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