]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.cxx
Add testcase for serializing / deserializing BasicBlocks
[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 #include "core/Comment.hxx"
6
7 #include "gui/qt.hxx"
8 #include <quazip/quazip.h>
9 #include <quazip/quazipfile.h>
10
11 InformationManager::~InformationManager() {
12 for (auto b : blocks)
13 delete b.second;
14
15 for (auto f : functions)
16 delete f.second;
17 }
18
19 void InformationManager::reset(const std::string& filename) {
20 disassembler.reset(createLLVMDisassembler(filename, this));
21 if (disassembler.get() != NULL)
22 disassembler.get()->start();
23 }
24
25 void InformationManager::save(const QString& filename) {
26 QuaZip zip(filename);
27 zip.open(QuaZip::mdCreate);
28 zip.setComment("FRIDA 0.0");
29 QuaZipFile outZipFile(&zip);
30
31 for (auto funpair : functions) {
32 Function* fun = funpair.second;
33 QuaZipNewInfo zipinfo(fun->getName().c_str());
34 zipinfo.setPermissions(static_cast<QFile::Permissions>(0x6444));
35 outZipFile.open(QIODevice::WriteOnly, zipinfo);
36 QXmlStreamWriter stream(&outZipFile);
37 stream.setAutoFormatting(true);
38 stream.setAutoFormattingIndent(-1);
39 stream.writeStartDocument();
40
41 fun->serialize(stream);
42
43 stream.writeEndDocument();
44 outZipFile.close();
45 }
46
47 zip.close();
48 }
49
50 void InformationManager::signal_new_function(Function* fun) {
51 }
52
53 Function* InformationManager::getFunction(uint64_t address) {
54 auto it = functions.find(address);
55 if (it != functions.end())
56 return it->second;
57 else
58 return NULL;
59 }
60
61 BasicBlock* InformationManager::getBasicBlock(uint64_t address) {
62 auto it = blocks.find(address);
63 if (it != blocks.end())
64 return it->second;
65 else
66 return NULL;
67 }
68
69 Function* InformationManager::newFunction(uint64_t address) {
70 Function* fun = new Function(address, this);
71 functions.insert(std::make_pair(address, fun));
72 return fun;
73 }
74
75 BasicBlock* InformationManager::newBasicBlock(uint64_t address) {
76 BasicBlock* block = new BasicBlock(address, this);
77 blocks.insert(std::make_pair(address, block));
78 return block;
79 }
80
81 Comment* InformationManager::newGlobalComment(uint64_t address) {
82 return NULL;
83 }
84
85 Comment* InformationManager::newLocalComment(uint64_t address, Function* f) {
86 return NULL;
87 }
88
89 void InformationManager::finishFunction(Function* fun) {
90 for (auto b : fun->blocks()) {
91 BasicBlock* bl = b.second;
92 blocks.insert(std::make_pair(bl->getStartAddress(), bl));
93 }
94 new_function_signal(fun);
95 }
96
97 void InformationManager::finishBasicBlock(BasicBlock* b) {
98 }
99
100 void InformationManager::finnishComment(Comment* c) {
101 }
102
103 void InformationManager::deleteFunction(Function* f) {
104 functions.erase(f->getStartAddress());
105 delete f;
106 }
107
108 void InformationManager::deleteBasicBlock(BasicBlock* b) {
109 blocks.erase(b->getStartAddress());
110 delete b;
111 }
112
113 void InformationManager::deleteComment(Comment* c) {
114 delete c;
115 }