]> git.siccegge.de Git - frida/frida.git/commitdiff
implement basic deserialization of BasicBlock's
authorChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 16:36:10 +0000 (17:36 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Tue, 3 Mar 2015 17:29:48 +0000 (18:29 +0100)
src/core/BasicBlock.cxx
src/core/BasicBlock.hxx

index 0dec430fcf6bd00b6ba1f5af6bf06683d430552a..5e2efd7860662de04f8aba491185da3895fb0416 100644 (file)
@@ -1,5 +1,9 @@
 #include "BasicBlock.hxx"
 #include "gui/qt.hxx"
+#include "core/InformationManager.hxx"
+
+#include <cassert>
+#include <iostream>
 
 void BasicBlock::serialize(QXmlStreamWriter& stream) {
        stream.writeStartElement("block");
@@ -12,3 +16,76 @@ void BasicBlock::serialize(QXmlStreamWriter& stream) {
                stream.writeTextElement("next", QString::number(getNextBlock(1), 16));
        stream.writeEndElement(); // "block"
 }
+
+BasicBlock* BasicBlock::deserialize(QXmlStreamReader& stream, InformationManager* manager) {
+       Q_ASSERT(stream.name() == "block");
+
+       QString name = stream.attributes().value("id").toString();
+       uint64_t start_address(0), end_address(0), next_blocks[2] = {0, 0};
+       BasicBlock* block;
+
+
+       while (QXmlStreamReader::NoToken != stream.readNext()) {
+               while (QXmlStreamReader::Characters == stream.tokenType() &&
+                      stream.isWhitespace())
+                       stream.readNext();
+               if (QXmlStreamReader::EndElement == stream.tokenType())
+                       break;
+
+               if(QXmlStreamReader::StartElement != stream.tokenType())
+                       return NULL;
+
+               if (stream.name() == "start") {
+                       stream.readNext();
+                       if (QXmlStreamReader::Characters != stream.tokenType())
+                               return NULL;
+
+                       start_address = stream.text().toULongLong(NULL, 16);
+                       stream.readNext();
+
+                       if(QXmlStreamReader::EndElement != stream.tokenType())
+                               return NULL;
+               }
+               if (stream.name() == "end") {
+                       stream.readNext();
+                       if (QXmlStreamReader::Characters != stream.tokenType())
+                               return NULL;
+
+                       end_address = stream.text().toULongLong(NULL, 16);
+                       stream.readNext();
+
+                       if(QXmlStreamReader::EndElement != stream.tokenType())
+                               return NULL;
+               }
+               if (stream.name() == "next") {
+                       stream.readNext();
+                       if (QXmlStreamReader::Characters != stream.tokenType())
+                               return NULL;
+
+                       uint64_t newblock = stream.text().toULongLong(NULL, 16);
+                       stream.readNext();
+
+                       if (next_blocks[0] == 0) {
+                               next_blocks[0] = newblock;
+                       } else {
+                               if (0 != next_blocks[1])
+                                       return NULL;
+                               next_blocks[1] = newblock;
+                       }
+
+                       if(QXmlStreamReader::EndElement != stream.tokenType())
+                               return NULL;
+               }
+       }
+
+       block = manager->newBasicBlock(start_address);
+       block->end_address = end_address;
+       block->next_blocks[0] = next_blocks[0];
+       block->next_blocks[1] = next_blocks[1];
+
+       assert(stream.name() == "block");
+       assert(block->getName() == name.toStdString());
+
+       manager->finishBasicBlock(block);
+       return block;
+}
index c7ae26eb0a3c03d7650b47653a77a888f456239d..bec0da3a7d77752c78b031a429ea52a2f36908ee 100644 (file)
@@ -8,6 +8,7 @@
 class Disassembler;
 class InformationManager;
 class QXmlStreamWriter;
+class QXmlStreamReader;
 
 class BasicBlock {
 public:
@@ -48,6 +49,8 @@ public:
        }
 
        void serialize(QXmlStreamWriter& stream);
+       static BasicBlock* deserialize(QXmlStreamReader& stream, InformationManager* manager);
+
 private:
        BasicBlock(uint64_t start_address, InformationManager* manager)
                : start_address(start_address)