]>
git.siccegge.de Git - frida/frida.git/blob - 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"
8 #include <quazip/quazip.h>
9 #include <quazip/quazipfile.h>
11 #include <QTemporaryFile>
13 InformationManager::InformationManager()
14 : logger(log4cxx::Logger::getLogger("InformationManager"))
17 InformationManager::~InformationManager() {
21 for (auto f
: functions
)
25 void InformationManager::reset(const std::string
& filename
) {
26 this->filename
= filename
;
27 disassembler
.reset(createLLVMDisassembler(filename
, this));
28 if (disassembler
.get() != NULL
)
29 disassembler
.get()->start();
32 void InformationManager::load(const std::string
& filename
) {
33 QuaZip
zip(filename
.c_str());
34 QuaZipFile
file(&zip
);
37 zip
.open(QuaZip::mdUnzip
);
38 tmpfile
.reset(new QTemporaryFile());
41 LOG4CXX_INFO(logger
, "Loading binary from archive");
42 zip
.setCurrentFile("binary");
44 file
.open(QIODevice::ReadOnly
);
46 while (!file
.atEnd()) {
47 buffer
= file
.read(4096);
48 tmpfile
->write(buffer
);
52 disassembler
.reset(createLLVMDisassembler(tmpfile
->fileName().toStdString(), this));
55 for (bool more
= zip
.goToFirstFile(); more
; more
= zip
.goToNextFile()) {
56 zip
.getCurrentFileInfo(&info
);
57 file
.open(QIODevice::ReadOnly
);
59 if(info
.name
!= "binary") {
60 QXmlStreamReader
reader(&file
);
61 assert(QXmlStreamReader::StartDocument
== reader
.readNext());
62 assert(QXmlStreamReader::StartElement
== reader
.readNext());
63 Function
* fun
= Function::deserialize(reader
, this);
69 void InformationManager::save(const std::string
& filename
) {
70 QuaZip
zip(filename
.c_str());
71 zip
.open(QuaZip::mdCreate
);
72 zip
.setComment("FRIDA 0.0");
73 QuaZipFile
outZipFile(&zip
);
76 QFile
binary(this->filename
.c_str());
77 binary
.open(QIODevice::ReadOnly
);
78 QuaZipNewInfo
zipinfo("binary");
79 zipinfo
.setPermissions(static_cast<QFile::Permissions
>(0x6444));
80 outZipFile
.open(QIODevice::WriteOnly
, zipinfo
);
82 while (!binary
.atEnd()) {
83 buffer
= binary
.read(4096);
84 outZipFile
.write(buffer
);
89 for (auto funpair
: functions
) {
90 Function
* fun
= funpair
.second
;
91 QuaZipNewInfo
zipinfo(fun
->getName().c_str());
92 zipinfo
.setPermissions(static_cast<QFile::Permissions
>(0x6444));
93 outZipFile
.open(QIODevice::WriteOnly
, zipinfo
);
94 QXmlStreamWriter
stream(&outZipFile
);
95 stream
.setAutoFormatting(true);
96 stream
.setAutoFormattingIndent(-1);
97 stream
.writeStartDocument();
99 fun
->serialize(stream
);
101 stream
.writeEndDocument();
108 void InformationManager::signal_new_function(Function
* fun
) {
111 Function
* InformationManager::getFunction(uint64_t address
) {
112 auto it
= functions
.find(address
);
113 if (it
!= functions
.end())
119 BasicBlock
* InformationManager::getBasicBlock(uint64_t address
) {
120 auto it
= blocks
.find(address
);
121 if (it
!= blocks
.end())
127 Function
* InformationManager::newFunction(uint64_t address
) {
128 Function
* fun
= new Function(address
, this);
129 functions
.insert(std::make_pair(address
, fun
));
133 BasicBlock
* InformationManager::newBasicBlock(uint64_t address
) {
134 BasicBlock
* block
= new BasicBlock(address
, this);
135 blocks
.insert(std::make_pair(address
, block
));
139 Comment
* InformationManager::newGlobalComment(uint64_t address
) {
143 Comment
* InformationManager::newLocalComment(uint64_t address
, Function
* f
) {
147 void InformationManager::finishFunction(Function
* fun
) {
148 LOG4CXX_DEBUG(logger
, "Finishing function " << fun
->getName());
149 for (auto b
: fun
->blocks()) {
150 BasicBlock
* bl
= b
.second
;
151 blocks
.insert(std::make_pair(bl
->getStartAddress(), bl
));
153 new_function_signal(fun
);
156 void InformationManager::finishBasicBlock(BasicBlock
* b
) {
159 void InformationManager::finnishComment(Comment
* c
) {
162 void InformationManager::deleteFunction(Function
* f
) {
163 functions
.erase(f
->getStartAddress());
167 void InformationManager::deleteBasicBlock(BasicBlock
* b
) {
168 blocks
.erase(b
->getStartAddress());
172 void InformationManager::deleteComment(Comment
* c
) {