]> git.siccegge.de Git - frida/frida.git/blobdiff - src/core/InformationManager.cxx
Move to Qt Signal/Slots
[frida/frida.git] / src / core / InformationManager.cxx
index e1571892349336ab5d0cc94f1d64104d64428d68..b7229d376854639dfc8cc16fbece136f2ef9bed2 100644 (file)
@@ -5,8 +5,9 @@
 #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>
 
@@ -49,7 +50,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());
 
        {
@@ -72,10 +76,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 * fun = 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();
        }
@@ -116,6 +131,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();
 }
@@ -160,6 +192,22 @@ std::map<uint64_t, BasicBlock*>::const_iterator InformationManager::endBasicBloc
        return blocks.end();
 }
 
+/* *********************************
+ * Accessors for the Comments map
+ */
+std::pair<
+       std::multimap<uint64_t, Comment*>::const_iterator,
+       std::multimap<uint64_t, Comment*>::const_iterator>
+InformationManager::getComments(uint64_t address) {
+       return comments.equal_range(address);
+}
+
+std::multimap<uint64_t, Comment*>::const_iterator InformationManager::beginComments() {
+       return comments.begin();
+}
+std::multimap<uint64_t, Comment*>::const_iterator InformationManager::endComments() {
+       return comments.end();
+}
 
 /* *********************************
  * Accessors for the Interpreter map
@@ -210,7 +258,7 @@ Comment* InformationManager::newGlobalComment(uint64_t address) {
 }
 
 Comment* InformationManager::newLocalComment(uint64_t address, Function* f) {
-       Comment* comment = new Comment(address, this);
+       Comment* comment = new Comment(address, f, this);
        comments.insert(std::make_pair(address, comment));
        return comment;
 }
@@ -222,13 +270,16 @@ void InformationManager::finishFunction(Function* fun) {
                blocks.insert(std::make_pair(bl->getStartAddress(), bl));
        }
        NewFunctionEvent event(fun->getStartAddress(), fun);
-       dispatch(&event);
+       Q_EMIT newFunctionEvent(&event);
 }
 
 void InformationManager::finishBasicBlock(BasicBlock*) {
 }
 
-void InformationManager::finnishComment(Comment* c) {
+void InformationManager::finishComment(Comment* c) {
+       LOG4CXX_DEBUG(logger, "Finishing comment " << c->getAddress());
+       ChangeCommentEvent event(c->getAddress(), c->getLocation(), c);
+       Q_EMIT changeCommentEvent(&event);
 }
 
 void InformationManager::deleteFunction(Function* f) {