]> git.siccegge.de Git - frida/frida.git/blob - src/core/InformationManager.hxx
Move the interpreters to the core InformationManager
[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
21 class QString;
22 class QTemporaryFile;
23 class QPluginLoader;
24
25 class InformationManager {
26 public:
27 InformationManager();
28 ~InformationManager();
29
30 void reset(const std::string& filename);
31 void load(const std::string& filename);
32 void save(const std::string& filename);
33
34 void signal_new_function(Function* f);
35 void signal_new_dyn_symbol(const std::string& f)
36 { new_dyn_symbol_signal(f); }
37
38 boost::signals2::connection
39 connect_new_function_signal(std::function<void(Function*)> f)
40 { return new_function_signal.connect(f); }
41
42 boost::signals2::connection
43 connect_new_dyn_symbol_signal(std::function<void(const std::string& name)> f)
44 { return new_dyn_symbol_signal.connect(f); }
45
46 boost::signals2::connection
47 connect_reset_signal(std::function<void ()> f)
48 { return reset_signal.connect(f); }
49
50 boost::signals2::connection
51 connect_rename_function_signal(std::function<void (RenameFunctionEvent*)> f)
52 { return rename_function_signal.connect(f); }
53
54 Disassembler* getDisassembler()
55 { return disassembler.get(); }
56
57 void dispatch(RenameFunctionEvent* event)
58 { rename_function_signal(event); }
59
60
61 Function* getFunction(uint64_t address);
62 bool hasFunctions() const {return functions.size() != 0;}
63 std::map<uint64_t, Function*>::const_iterator beginFunctions();
64 std::map<uint64_t, Function*>::const_iterator endFunctions();
65
66 BasicBlock* getBasicBlock(uint64_t address);
67 bool hasBasicBlocks() const {return blocks.size() != 0;}
68 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
69 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
70
71
72 Interpreter* getInterpreter(const std::string& name);
73 bool hasInterpreters() const {return interpreters.size() != 0;}
74 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
75 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
76
77
78 /* Protocoll:
79 *
80 * Users may allocate new Data containers with the new*()
81 * functions. Once they have populated the information they hand
82 * over the object to the information manager using the finish*()
83 * functions.
84 *
85 * if new*() returns NULL there already exists a function at the
86 * specified address. Users may then get the old object if they
87 * wish or (more likely) skip creating it. Uniqueness of the
88 * object is only guaranteed as compared to the finish()ed
89 * objects.
90 *
91 * Users are responsible for destroying functions iff they do not
92 * finish them using the delete*() functions. Once the objects are
93 * finished, the information manager is responsible for cleaning
94 * up the memory. If delete*() is called on a finished object, bad
95 * thingsmay happen.
96 */
97 Function* newFunction(uint64_t address);
98 BasicBlock* newBasicBlock(uint64_t address);
99 Comment* newGlobalComment(uint64_t address);
100 Comment* newLocalComment(uint64_t address, Function* f);
101 void finishFunction(Function* f);
102 void finishBasicBlock(BasicBlock* b);
103 void finnishComment(Comment* c);
104 void deleteFunction(Function* f);
105 void deleteBasicBlock(BasicBlock* b);
106 void deleteComment(Comment* c);
107
108 private:
109 boost::signals2::signal<void ()> reset_signal;
110 boost::signals2::signal<void (Function*)> new_function_signal;
111 boost::signals2::signal<void (const std::string& name)> new_dyn_symbol_signal;
112 boost::signals2::signal<void (RenameFunctionEvent*)> rename_function_signal;
113 std::unique_ptr<Disassembler> disassembler;
114 std::map<std::string, Interpreter*> interpreters;
115 std::map<uint64_t, Function*> functions;
116 std::map<uint64_t, BasicBlock*> blocks;
117 std::string filename;
118 std::unique_ptr<QTemporaryFile> tmpfile;
119 std::vector<QPluginLoader*> plugins;
120
121 log4cxx::LoggerPtr logger;
122 };
123
124 #endif /* INCLUDE__InformationManager_hxx */