]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.cxx
Name functions in BasicBlock view
[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
6 #include "gui/qt.hxx"
7 #include <quazip/quazip.h>
8 #include <quazip/quazipfile.h>
9
10 InformationManager::~InformationManager() {
11 for (auto b : blocks)
12 delete b.second;
13
14 for (auto f : functions)
15 delete f.second;
16 }
17
18 void InformationManager::reset(const std::string& filename) {
19 disassembler.reset(createLLVMDisassembler(filename, this));
20 if (disassembler.get() != NULL)
21 disassembler.get()->start();
22 }
23
24 void InformationManager::save(const QString& filename) {
25 QuaZip zip(filename);
26 zip.open(QuaZip::mdCreate);
27 zip.setComment("FRIDA 0.0");
28 QuaZipFile outZipFile(&zip);
29
30 for (auto funpair : functions) {
31 Function* fun = funpair.second;
32 QuaZipNewInfo zipinfo(fun->getName().c_str());
33 zipinfo.setPermissions(static_cast<QFile::Permissions>(0x6444));
34 outZipFile.open(QIODevice::WriteOnly, zipinfo);
35 QXmlStreamWriter stream(&outZipFile);
36 stream.setAutoFormatting(true);
37 stream.setAutoFormattingIndent(-1);
38 stream.writeStartDocument();
39 stream.writeStartElement("function");
40 stream.writeAttribute("name", fun->getName().c_str());
41 stream.writeAttribute("entry", QString::number(fun->getStartAddress(), 16));
42
43 for (auto& blockentry : fun->blocks()) {
44 stream.writeStartElement("block");
45 stream.writeAttribute("id", blockentry.second->getName().c_str());
46 stream.writeTextElement("start", QString::number(blockentry.second->getStartAddress(), 16));
47 stream.writeTextElement("end", QString::number(blockentry.second->getEndAddress(), 16));
48 if (0 != blockentry.second->getNextBlock(0))
49 stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(0), 16));
50 if (0 != blockentry.second->getNextBlock(1))
51 stream.writeTextElement("next", QString::number(blockentry.second->getNextBlock(1), 16));
52 stream.writeEndElement(); // "block"
53 }
54
55 stream.writeEndElement(); // "function"
56 stream.writeEndDocument();
57 outZipFile.close();
58 }
59
60 zip.close();
61 }
62
63 void InformationManager::signal_new_function(Function* fun) {
64 functions.insert(std::make_pair(fun->getStartAddress(), fun));
65 for (auto b : fun->blocks()) {
66 BasicBlock* bl = b.second;
67 blocks.insert(std::make_pair(bl->getStartAddress(), bl));
68 }
69 new_function_signal(fun);
70 }