From 3493bceb6690f53900d2a4524401990c601b1464 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Tue, 3 Mar 2015 14:26:10 +0100 Subject: [PATCH] Make pieces of information serialize themselves Moving responsibility of serialization to the individual pieces of Information. --- CMakeLists.txt | 1 + src/core/BasicBlock.cxx | 14 ++++++++++++++ src/core/BasicBlock.hxx | 3 +++ src/core/Function.cxx | 14 ++++++++++++-- src/core/Function.hxx | 4 +++- src/core/InformationManager.cxx | 20 +++----------------- 6 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 src/core/BasicBlock.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fe40fb..e9ff46b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ separate_arguments(LLVM_LIBS) SET(frida_SOURCES src/main.cxx src/core/InformationManager.cxx + src/core/BasicBlock.cxx src/core/Function.cxx src/gui/Mainwindow.cxx src/gui/widgets/BasicBlockWidget.cxx diff --git a/src/core/BasicBlock.cxx b/src/core/BasicBlock.cxx new file mode 100644 index 0000000..0dec430 --- /dev/null +++ b/src/core/BasicBlock.cxx @@ -0,0 +1,14 @@ +#include "BasicBlock.hxx" +#include "gui/qt.hxx" + +void BasicBlock::serialize(QXmlStreamWriter& stream) { + stream.writeStartElement("block"); + stream.writeAttribute("id", getName().c_str()); + stream.writeTextElement("start", QString::number(getStartAddress(), 16)); + stream.writeTextElement("end", QString::number(getEndAddress(), 16)); + if (0 != getNextBlock(0)) + stream.writeTextElement("next", QString::number(getNextBlock(0), 16)); + if (0 != getNextBlock(1)) + stream.writeTextElement("next", QString::number(getNextBlock(1), 16)); + stream.writeEndElement(); // "block" +} diff --git a/src/core/BasicBlock.hxx b/src/core/BasicBlock.hxx index 69d4f37..c7ae26e 100644 --- a/src/core/BasicBlock.hxx +++ b/src/core/BasicBlock.hxx @@ -7,6 +7,7 @@ class Disassembler; class InformationManager; +class QXmlStreamWriter; class BasicBlock { public: @@ -45,6 +46,8 @@ public: InformationManager* getManager() const { return manager; } + + void serialize(QXmlStreamWriter& stream); private: BasicBlock(uint64_t start_address, InformationManager* manager) : start_address(start_address) diff --git a/src/core/Function.cxx b/src/core/Function.cxx index 539192c..1df4d1d 100644 --- a/src/core/Function.cxx +++ b/src/core/Function.cxx @@ -1,8 +1,7 @@ #include "Function.hxx" #include "core/events/RenameFunctionEvent.hxx" #include "InformationManager.hxx" - -#include +#include "gui/qt.hxx" Function::Function(uint64_t start_address, InformationManager* manager) : start_address(start_address) @@ -15,3 +14,14 @@ void Function::setName(const std::string& new_name) { manager->dispatch(&event); } +void Function::serialize(QXmlStreamWriter& stream) { + stream.writeStartElement("function"); + stream.writeAttribute("name", getName().c_str()); + stream.writeAttribute("entry", QString::number(getStartAddress(), 16)); + + for (auto& blockentry : blocks()) { + blockentry.second->serialize(stream); + } + + stream.writeEndElement(); // "function" +} diff --git a/src/core/Function.hxx b/src/core/Function.hxx index 5497800..d567c28 100644 --- a/src/core/Function.hxx +++ b/src/core/Function.hxx @@ -5,10 +5,10 @@ #include "BasicBlock.hxx" class InformationManager; +class QXmlStreamWriter; class Function { public: - uint64_t getStartAddress() const { return start_address; } @@ -28,6 +28,8 @@ public: const std::map& blocks() { return _blocks; } + + void serialize(QXmlStreamWriter& stream); private: Function(uint64_t start_address, InformationManager* manager); diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index 294dc2f..3eebc34 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -37,23 +37,9 @@ void InformationManager::save(const QString& filename) { stream.setAutoFormatting(true); stream.setAutoFormattingIndent(-1); stream.writeStartDocument(); - stream.writeStartElement("function"); - stream.writeAttribute("name", fun->getName().c_str()); - stream.writeAttribute("entry", QString::number(fun->getStartAddress(), 16)); - - for (auto& blockentry : fun->blocks()) { - stream.writeStartElement("block"); - stream.writeAttribute("id", blockentry.second->getName().c_str()); - stream.writeTextElement("start", QString::number(blockentry.second->getStartAddress(), 16)); - stream.writeTextElement("end", QString::number(blockentry.second->getEndAddress(), 16)); - if (0 != blockentry.second->getNextBlock(0)) - stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(0), 16)); - if (0 != blockentry.second->getNextBlock(1)) - stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(1), 16)); - stream.writeEndElement(); // "block" - } - - stream.writeEndElement(); // "function" + + fun->serialize(stream); + stream.writeEndDocument(); outZipFile.close(); } -- 2.39.5