]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Some 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 <boost/signals2.hpp>
6 #include <functional>
7 #include <string>
8 #include <map>
9 #include <vector>
10
11 #include "disassembler/Disassembler.hxx"
12
13 class Interpreter;
14
15 class Function;
16 class BasicBlock;
17 class Comment;
18
19 class RenameFunctionEvent;
20 class NewFunctionEvent;
21 class ChangeCommentEvent;
22
23 class QString;
24 class QTemporaryFile;
25 class QPluginLoader;
26
27 using boost::signals2::connection;
28
29 class InformationManager {
30 public:
31 InformationManager();
32 ~InformationManager();
33
34 void reset(const std::string& filename);
35 void load(const std::string& filename);
36 void save(const std::string& filename);
37
38 Disassembler* getDisassembler()
39 { return disassembler.get(); }
40
41 // Rename Function
42 typedef std::function<void (RenameFunctionEvent*)> RenameFunctionHandler;
43 connection registerRenameFunctionEvent(RenameFunctionHandler h)
44 { return renameFunctionSignal.connect(h); }
45 void dispatch(RenameFunctionEvent* event)
46 { renameFunctionSignal(event); }
47
48 // New Function
49 typedef std::function<void (NewFunctionEvent*)> NewFunctionHandler;
50 connection registerNewFunctionEvent(NewFunctionHandler h)
51 { return newFunctionSignal.connect(h); }
52 void dispatch(NewFunctionEvent* event)
53 { newFunctionSignal(event); }
54
55 // Change Comment
56 typedef std::function<void (ChangeCommentEvent*)> ChangeCommentHandler;
57 connection registerChangeCommentEvent(ChangeCommentHandler h)
58 { return changeCommentSignal.connect(h); }
59 void dispatch(ChangeCommentEvent* event)
60 { changeCommentSignal(event); }
61
62 // Reset frida
63 connection connect_reset_signal(std::function<void ()> f)
64 { return reset_signal.connect(f); }
65
66 // Accessors
67 Function* getFunction(uint64_t address);
68 bool hasFunctions() const {return functions.size() != 0;}
69 std::map<uint64_t, Function*>::const_iterator beginFunctions();
70 std::map<uint64_t, Function*>::const_iterator endFunctions();
71
72 BasicBlock* getBasicBlock(uint64_t address);
73 bool hasBasicBlocks() const {return blocks.size() != 0;}
74 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
75 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
76
77 std::pair<
78 std::multimap<uint64_t, Comment*>::const_iterator,
79 std::multimap<uint64_t, Comment*>::const_iterator>
80 getComments(uint64_t address);
81 bool hasComments() const {return ! comments.empty();}
82 std::multimap<uint64_t,Comment*>::const_iterator beginComments();
83 std::multimap<uint64_t,Comment*>::const_iterator endComments();
84
85 Interpreter* getInterpreter(const std::string& name);
86 bool hasInterpreters() const {return interpreters.size() != 0;}
87 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
88 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
89
90 /* Protocoll:
91 *
92 * Users may allocate new Data containers with the new*()
93 * functions. Once they have populated the information they hand
94 * over the object to the information manager using the finish*()
95 * functions.
96 *
97 * if new*() returns NULL there already exists a function at the
98 * specified address. Users may then get the old object if they
99 * wish or (more likely) skip creating it. Uniqueness of the
100 * object is only guaranteed as compared to the finish()ed
101 * objects.
102 *
103 * Users are responsible for destroying functions iff they do not
104 * finish them using the delete*() functions. Once the objects are
105 * finished, the information manager is responsible for cleaning
106 * up the memory. If delete*() is called on a finished object, bad
107 * thingsmay happen.
108 */
109 Function* newFunction(uint64_t address);
110 Function* newDynamicFunction(uint64_t address);
111 BasicBlock* newBasicBlock(uint64_t address);
112 Comment* newGlobalComment(uint64_t address);
113 Comment* newLocalComment(uint64_t address, Function* f);
114 void finishFunction(Function* f);
115 void finishBasicBlock(BasicBlock* b);
116 void finishComment(Comment* c);
117 void deleteFunction(Function* f);
118 void deleteBasicBlock(BasicBlock* b);
119 void deleteComment(Comment* c);
120
121 private:
122 boost::signals2::signal<void (RenameFunctionEvent*)> renameFunctionSignal;
123 boost::signals2::signal<void (NewFunctionEvent*)> newFunctionSignal;
124 boost::signals2::signal<void (ChangeCommentEvent*)> changeCommentSignal;
125
126 boost::signals2::signal<void ()> reset_signal;
127
128 std::unique_ptr<Disassembler> disassembler;
129
130 std::map<std::string, Interpreter*> interpreters;
131 std::map<uint64_t, Function*> functions;
132 std::map<uint64_t, BasicBlock*> blocks;
133 std::multimap<uint64_t, Comment*> comments;
134
135 std::string filename;
136 std::unique_ptr<QTemporaryFile> tmpfile;
137 std::vector<QPluginLoader*> plugins;
138
139 log4cxx::LoggerPtr logger;
140 };
141
142 #endif /* INCLUDE__InformationManager_hxx */