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