]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Implement InformationManager / Comment and ChangeCommentEvent
[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 connection connect_reset_signal(std::function<void ()> f)
63 { return reset_signal.connect(f); }
64
65 Function* getFunction(uint64_t address);
66 bool hasFunctions() const {return functions.size() != 0;}
67 std::map<uint64_t, Function*>::const_iterator beginFunctions();
68 std::map<uint64_t, Function*>::const_iterator endFunctions();
69
70 BasicBlock* getBasicBlock(uint64_t address);
71 bool hasBasicBlocks() const {return blocks.size() != 0;}
72 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
73 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
74
75 std::pair<
76 std::multimap<uint64_t, Comment*>::const_iterator,
77 std::multimap<uint64_t, Comment*>::const_iterator>
78 getComments(uint64_t address);
79 bool hasComments() const {return ! comments.empty();}
80 std::multimap<uint64_t,Comment*>::const_iterator beginComments();
81 std::multimap<uint64_t,Comment*>::const_iterator endComments();
82
83 Interpreter* getInterpreter(const std::string& name);
84 bool hasInterpreters() const {return interpreters.size() != 0;}
85 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
86 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
87
88 /* Protocoll:
89 *
90 * Users may allocate new Data containers with the new*()
91 * functions. Once they have populated the information they hand
92 * over the object to the information manager using the finish*()
93 * functions.
94 *
95 * if new*() returns NULL there already exists a function at the
96 * specified address. Users may then get the old object if they
97 * wish or (more likely) skip creating it. Uniqueness of the
98 * object is only guaranteed as compared to the finish()ed
99 * objects.
100 *
101 * Users are responsible for destroying functions iff they do not
102 * finish them using the delete*() functions. Once the objects are
103 * finished, the information manager is responsible for cleaning
104 * up the memory. If delete*() is called on a finished object, bad
105 * thingsmay happen.
106 */
107 Function* newFunction(uint64_t address);
108 Function* newDynamicFunction(uint64_t address);
109 BasicBlock* newBasicBlock(uint64_t address);
110 Comment* newGlobalComment(uint64_t address);
111 Comment* newLocalComment(uint64_t address, Function* f);
112 void finishFunction(Function* f);
113 void finishBasicBlock(BasicBlock* b);
114 void finishComment(Comment* c);
115 void deleteFunction(Function* f);
116 void deleteBasicBlock(BasicBlock* b);
117 void deleteComment(Comment* c);
118
119 private:
120 boost::signals2::signal<void (RenameFunctionEvent*)> renameFunctionSignal;
121 boost::signals2::signal<void (NewFunctionEvent*)> newFunctionSignal;
122 boost::signals2::signal<void (ChangeCommentEvent*)> changeCommentSignal;
123
124 boost::signals2::signal<void ()> reset_signal;
125
126 std::unique_ptr<Disassembler> disassembler;
127
128 std::map<std::string, Interpreter*> interpreters;
129 std::map<uint64_t, Function*> functions;
130 std::map<uint64_t, BasicBlock*> blocks;
131 std::multimap<uint64_t, Comment*> comments;
132
133 std::string filename;
134 std::unique_ptr<QTemporaryFile> tmpfile;
135 std::vector<QPluginLoader*> plugins;
136
137 log4cxx::LoggerPtr logger;
138 };
139
140 #endif /* INCLUDE__InformationManager_hxx */