]> git.siccegge.de Git - frida/frida.git/blobdiff - src/core/InformationManager.cxx
Add doc repo as submodule
[frida/frida.git] / src / core / InformationManager.cxx
index 6179f5f1ff2d83c5287ed07f629674907da15139..604425e617499fa5155e3db8d84f40af49448824 100644 (file)
@@ -4,10 +4,9 @@
 #include "core/Function.hxx"
 #include "core/BasicBlock.hxx"
 #include "core/Comment.hxx"
-#include "core/events/NewFunctionEvent.hxx"
 #include "core/events/ChangeCommentEvent.hxx"
 
-#include "gui/qt.hxx"
+#include "qt.hxx"
 #include <quazip/quazip.h>
 #include <quazip/quazipfile.h>
 
@@ -19,6 +18,7 @@ InformationManager::InformationManager()
        : logger(log4cxx::Logger::getLogger("core.InformationManager"))
 {
        current_information_manager = this;
+       qRegisterMetaType<NewFunctionEvent>("NewFunctionEvent");
 
        QPluginLoader* loader = new QPluginLoader("libguilePlugin", NULL);
        if (!loader->load())
@@ -28,6 +28,7 @@ InformationManager::InformationManager()
 }
 
 InformationManager::~InformationManager() {
+       disassemblerThread.quit();
        for (auto b : blocks)
                delete b.second;
 
@@ -36,13 +37,23 @@ InformationManager::~InformationManager() {
 
        for (auto i : plugins)
                delete i;
+       disassemblerThread.wait();
 }
 
 void InformationManager::reset(const std::string& filename) {
        this->filename = filename;
        disassembler.reset(createLLVMDisassembler(filename, this));
-       if (disassembler.get() != NULL)
+       if (disassembler.get() != NULL) {
+               emit resetEvent();
+#ifndef CONFIG_TEST
+               disassembler.get()->moveToThread(&disassemblerThread);
+               connect(&disassemblerThread, &QThread::started,
+                       disassembler.get(), &Disassembler::start);
+               disassemblerThread.start();
+#else
                disassembler.get()->start();
+#endif
+       }
 }
 
 void InformationManager::load(const std::string& filename) {
@@ -50,7 +61,10 @@ void InformationManager::load(const std::string& filename) {
        QuaZipFile file(&zip);
        QuaZipFileInfo info;
 
-       zip.open(QuaZip::mdUnzip);
+       if (!zip.open(QuaZip::mdUnzip)) {
+               LOG4CXX_ERROR(logger, "Failed to open archive " << filename);
+               return;
+       }
        tmpfile.reset(new QTemporaryFile());
 
        {
@@ -73,10 +87,21 @@ void InformationManager::load(const std::string& filename) {
                file.open(QIODevice::ReadOnly);
 
                if(info.name != "binary") {
-                       QXmlStreamReader reader(&file);
-                       assert(QXmlStreamReader::StartDocument == reader.readNext());
-                       assert(QXmlStreamReader::StartElement == reader.readNext());
-                       Function::deserialize(reader, this);
+                       if (info.name.startsWith("comment:")) {
+                               QXmlStreamReader reader(&file);
+                               auto starttoken = reader.readNext();
+                               auto elementtoken = reader.readNext();
+                               assert(QXmlStreamReader::StartDocument == starttoken);
+                               assert(QXmlStreamReader::StartElement == elementtoken);
+                               Comment::deserialize(reader, this);
+                       } else {
+                               QXmlStreamReader reader(&file);
+                               auto starttoken = reader.readNext();
+                               auto elementtoken = reader.readNext();
+                               assert(QXmlStreamReader::StartDocument == starttoken);
+                               assert(QXmlStreamReader::StartElement == elementtoken);
+                               Function::deserialize(reader, this);
+                       }
                }
                file.close();
        }
@@ -117,6 +142,23 @@ void InformationManager::save(const std::string& filename) {
                stream.writeEndDocument();
                outZipFile.close();
        }
+       for (auto commentpair : comments) {
+               Comment* comment = commentpair.second;
+               if (!comment->isLocal()) {
+                       QuaZipNewInfo zipinfo(QString("comment:%1").arg(comment->getAddress(), 0, 16));
+                       zipinfo.setPermissions(static_cast<QFile::Permissions>(0x6444));
+                       outZipFile.open(QIODevice::WriteOnly, zipinfo);
+                       QXmlStreamWriter stream(&outZipFile);
+                       stream.setAutoFormatting(true);
+                       stream.setAutoFormattingIndent(-1);
+                       stream.writeStartDocument();
+
+                       comment->serialize(stream);
+
+                       stream.writeEndDocument();
+                       outZipFile.close();
+               }
+       }
 
        zip.close();
 }
@@ -239,7 +281,7 @@ void InformationManager::finishFunction(Function* fun) {
                blocks.insert(std::make_pair(bl->getStartAddress(), bl));
        }
        NewFunctionEvent event(fun->getStartAddress(), fun);
-       dispatch(&event);
+       emit newFunctionEvent(event);
 }
 
 void InformationManager::finishBasicBlock(BasicBlock*) {
@@ -248,7 +290,7 @@ void InformationManager::finishBasicBlock(BasicBlock*) {
 void InformationManager::finishComment(Comment* c) {
        LOG4CXX_DEBUG(logger, "Finishing comment " << c->getAddress());
        ChangeCommentEvent event(c->getAddress(), c->getLocation(), c);
-       dispatch(&event);
+       emit changeCommentEvent(&event);
 }
 
 void InformationManager::deleteFunction(Function* f) {