]>
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 InformationManager::InformationManager()
12 : logger(log4cxx::Logger::getLogger("InformationManager"))
15 InformationManager::~InformationManager() {
19 for (auto f
: functions
)
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();
30 void InformationManager::save(const QString
& filename
) {
32 zip
.open(QuaZip::mdCreate
);
33 zip
.setComment("FRIDA 0.0");
34 QuaZipFile
outZipFile(&zip
);
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
);
43 while (!binary
.atEnd()) {
44 buffer
= binary
.read(4096);
45 outZipFile
.write(buffer
);
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();
60 fun
->serialize(stream
);
62 stream
.writeEndDocument();
69 void InformationManager::signal_new_function(Function
* fun
) {
72 Function
* InformationManager::getFunction(uint64_t address
) {
73 auto it
= functions
.find(address
);
74 if (it
!= functions
.end())
80 BasicBlock
* InformationManager::getBasicBlock(uint64_t address
) {
81 auto it
= blocks
.find(address
);
82 if (it
!= blocks
.end())
88 Function
* InformationManager::newFunction(uint64_t address
) {
89 Function
* fun
= new Function(address
, this);
90 functions
.insert(std::make_pair(address
, fun
));
94 BasicBlock
* InformationManager::newBasicBlock(uint64_t address
) {
95 BasicBlock
* block
= new BasicBlock(address
, this);
96 blocks
.insert(std::make_pair(address
, block
));
100 Comment
* InformationManager::newGlobalComment(uint64_t address
) {
104 Comment
* InformationManager::newLocalComment(uint64_t address
, Function
* f
) {
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
));
114 new_function_signal(fun
);
117 void InformationManager::finishBasicBlock(BasicBlock
* b
) {
120 void InformationManager::finnishComment(Comment
* c
) {
123 void InformationManager::deleteFunction(Function
* f
) {
124 functions
.erase(f
->getStartAddress());
128 void InformationManager::deleteBasicBlock(BasicBlock
* b
) {
129 blocks
.erase(b
->getStartAddress());
133 void InformationManager::deleteComment(Comment
* c
) {