]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Add comments
[frida/frida.git] / src / core / InformationManager.hxx
1 #ifndef INCLUDE__InformationManager_hxx
2 #define INCLUDE__InformationManager_hxx
3
4 #include <log4cxx/logger.h>
5 #include <functional>
6 #include <string>
7 #include <map>
8 #include <vector>
9 #include <memory>
10
11 #include "qt.hxx"
12 #include "disassembler/Disassembler.hxx"
13
14 #include "core/events/NewFunctionEvent.hxx"
15
16 class Interpreter;
17
18 class Function;
19 class BasicBlock;
20 class Comment;
21
22 class RenameFunctionEvent;
23 class NewFunctionEvent;
24 class ChangeCommentEvent;
25
26 class QString;
27 class QTemporaryFile;
28 class QPluginLoader;
29
30 class InformationManager : public QObject {
31 #ifndef SWIG
32 Q_OBJECT
33 signals:
34 #else
35 public:
36 #endif
37 void renameFunctionEvent(RenameFunctionEvent* event);
38 void newFunctionEvent(NewFunctionEvent event);
39 void changeCommentEvent(ChangeCommentEvent* event);
40 void resetEvent();
41 public:
42 InformationManager();
43 ~InformationManager();
44
45 // Start working on a fresh binary
46 void reset(const std::string& filename);
47
48 // Load a saved binary
49 void load(const std::string& filename);
50
51 // Save current state to disk
52 void save(const std::string& filename);
53
54 Disassembler* getDisassembler()
55 { return disassembler.get(); }
56
57 // Accessors
58 /* Used by the disassembler to determine whether to use unsafe
59 * heuristics for finding an entry point
60 */
61 bool hasFunctions() const {return functions.size() != 0;}
62
63 Function* getFunction(uint64_t address);
64 std::map<uint64_t, Function*>::const_iterator beginFunctions();
65 std::map<uint64_t, Function*>::const_iterator endFunctions();
66
67 BasicBlock* getBasicBlock(uint64_t address);
68 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
69 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
70
71 std::pair<
72 std::multimap<uint64_t, Comment*>::const_iterator,
73 std::multimap<uint64_t, Comment*>::const_iterator>
74 getComments(uint64_t address);
75 std::multimap<uint64_t,Comment*>::const_iterator beginComments();
76 std::multimap<uint64_t,Comment*>::const_iterator endComments();
77
78 Interpreter* getInterpreter(const std::string& name);
79 bool hasInterpreters() const {return interpreters.size() != 0;}
80 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
81 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
82
83 /* Protocoll:
84 *
85 * Users may allocate new Data containers with the new*()
86 * functions. Once they have populated the information they hand
87 * over the object to the information manager using the finish*()
88 * functions.
89 *
90 * if new*() returns NULL there already exists a function at the
91 * specified address. Users may then get the old object if they
92 * wish or (more likely) skip creating it. Uniqueness of the
93 * object is only guaranteed as compared to the finish()ed
94 * objects.
95 *
96 * Users are responsible for destroying functions iff they do not
97 * finish them using the delete*() functions. Once the objects are
98 * finished, the information manager is responsible for cleaning
99 * up the memory. If delete*() is called on a finished object, bad
100 * thingsmay happen.
101 */
102 Function* newFunction(uint64_t address);
103 Function* newDynamicFunction(uint64_t address);
104 BasicBlock* newBasicBlock(uint64_t address);
105 Comment* newGlobalComment(uint64_t address);
106 Comment* newLocalComment(uint64_t address, Function* f);
107 void finishFunction(Function* f);
108 void finishBasicBlock(BasicBlock* b);
109 void finishComment(Comment* c);
110 void deleteFunction(Function* f);
111 void deleteBasicBlock(BasicBlock* b);
112 void deleteComment(Comment* c);
113
114 private:
115 std::unique_ptr<Disassembler> disassembler;
116
117 std::map<std::string, Interpreter*> interpreters;
118 std::map<uint64_t, Function*> functions;
119 std::map<uint64_t, BasicBlock*> blocks;
120 std::multimap<uint64_t, Comment*> comments;
121
122 std::string filename;
123 std::unique_ptr<QTemporaryFile> tmpfile;
124 std::vector<QPluginLoader*> plugins;
125
126 QThread disassemblerThread;
127 log4cxx::LoggerPtr logger;
128 };
129
130 #endif /* INCLUDE__InformationManager_hxx */