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