]>
git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.cxx
294dc2f53583b7e3a9c5ce6b8f33fd49427bf058
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"
8 #include <quazip/quazip.h>
9 #include <quazip/quazipfile.h>
11 InformationManager::~InformationManager() {
15 for (auto f
: functions
)
19 void InformationManager::reset(const std::string
& filename
) {
20 disassembler
.reset(createLLVMDisassembler(filename
, this));
21 if (disassembler
.get() != NULL
)
22 disassembler
.get()->start();
25 void InformationManager::save(const QString
& filename
) {
27 zip
.open(QuaZip::mdCreate
);
28 zip
.setComment("FRIDA 0.0");
29 QuaZipFile
outZipFile(&zip
);
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 stream
.writeStartElement("function");
41 stream
.writeAttribute("name", fun
->getName().c_str());
42 stream
.writeAttribute("entry", QString::number(fun
->getStartAddress(), 16));
44 for (auto& blockentry
: fun
->blocks()) {
45 stream
.writeStartElement("block");
46 stream
.writeAttribute("id", blockentry
.second
->getName().c_str());
47 stream
.writeTextElement("start", QString::number(blockentry
.second
->getStartAddress(), 16));
48 stream
.writeTextElement("end", QString::number(blockentry
.second
->getEndAddress(), 16));
49 if (0 != blockentry
.second
->getNextBlock(0))
50 stream
.writeTextElement("next", QString::number(blockentry
.second
->getNextBlock(0), 16));
51 if (0 != blockentry
.second
->getNextBlock(1))
52 stream
.writeTextElement("next", QString::number(blockentry
.second
->getNextBlock(1), 16));
53 stream
.writeEndElement(); // "block"
56 stream
.writeEndElement(); // "function"
57 stream
.writeEndDocument();
64 void InformationManager::signal_new_function(Function
* fun
) {
67 Function
* InformationManager::getFunction(uint64_t address
) {
68 auto it
= functions
.find(address
);
69 if (it
!= functions
.end())
75 BasicBlock
* InformationManager::getBasicBlock(uint64_t address
) {
76 auto it
= blocks
.find(address
);
77 if (it
!= blocks
.end())
83 Function
* InformationManager::newFunction(uint64_t address
) {
84 Function
* fun
= new Function(address
, this);
85 functions
.insert(std::make_pair(address
, fun
));
89 BasicBlock
* InformationManager::newBasicBlock(uint64_t address
) {
90 BasicBlock
* block
= new BasicBlock(address
, this);
91 blocks
.insert(std::make_pair(address
, block
));
95 Comment
* InformationManager::newGlobalComment(uint64_t address
) {
99 Comment
* InformationManager::newLocalComment(uint64_t address
, Function
* f
) {
103 void InformationManager::finishFunction(Function
* fun
) {
104 for (auto b
: fun
->blocks()) {
105 BasicBlock
* bl
= b
.second
;
106 blocks
.insert(std::make_pair(bl
->getStartAddress(), bl
));
108 new_function_signal(fun
);
111 void InformationManager::finishBasicBlock(BasicBlock
* b
) {
114 void InformationManager::finnishComment(Comment
* c
) {
117 void InformationManager::deleteFunction(Function
* f
) {
118 functions
.erase(f
->getStartAddress());
122 void InformationManager::deleteBasicBlock(BasicBlock
* b
) {
123 blocks
.erase(b
->getStartAddress());
127 void InformationManager::deleteComment(Comment
* c
) {