]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.cxx
Make InformationManager responsible for cleaning Blocks / Functions
[frida/frida.git] / src / core / InformationManager.cxx
1 #include "InformationManager.hxx"
2 #include "disassembler/llvm/LLVMDisassembler.hxx"
3 #include "core/Function.hxx"
4 #include "core/BasicBlock.hxx"
5
6 #include "gui/qt.hxx"
7 #include <quazip/quazip.h>
8 #include <quazip/quazipfile.h>
9
10 InformationManager::~InformationManager() {
11 for (BasicBlock * b : blocks)
12 delete b;
13
14 for (Function * f : functions)
15 delete f;
16 }
17
18 void InformationManager::reset(const std::string& filename) {
19 disassembler.reset(createLLVMDisassembler(filename, this));
20 if (disassembler.get() != NULL)
21 disassembler.get()->start();
22 }
23
24 void InformationManager::save(const QString& filename) {
25 QuaZip zip(filename);
26 zip.open(QuaZip::mdCreate);
27 zip.setComment("FRIDA 0.0");
28 QuaZipFile outZipFile(&zip);
29
30 for (Function* fun : functions) {
31 QuaZipNewInfo zipinfo(fun->getName().c_str());
32 zipinfo.setPermissions(static_cast<QFile::Permissions>(0x6444));
33 outZipFile.open(QIODevice::WriteOnly, zipinfo);
34 QXmlStreamWriter stream(&outZipFile);
35 stream.setAutoFormatting(true);
36 stream.setAutoFormattingIndent(-1);
37 stream.writeStartDocument();
38 stream.writeStartElement("function");
39 stream.writeAttribute("name", fun->getName().c_str());
40 stream.writeAttribute("entry", QString::number(fun->getStartAddress(), 16));
41
42 for (auto& blockentry : fun->blocks()) {
43 stream.writeStartElement("block");
44 stream.writeAttribute("id", blockentry.second->getName().c_str());
45 stream.writeTextElement("start", QString::number(blockentry.second->getStartAddress(), 16));
46 stream.writeTextElement("end", QString::number(blockentry.second->getEndAddress(), 16));
47 if (0 != blockentry.second->getNextBlock(0))
48 stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(0), 16));
49 if (0 != blockentry.second->getNextBlock(1))
50 stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(1), 16));
51 stream.writeEndElement(); // "block"
52 }
53
54 stream.writeEndElement(); // "function"
55 stream.writeEndDocument();
56 outZipFile.close();
57 }
58
59 zip.close();
60 }
61
62 void InformationManager::signal_new_function(Function* fun) {
63 functions.insert(fun);
64 for (auto b : fun->blocks())
65 blocks.insert(b.second);
66 new_function_signal(fun);
67 }