1 #ifndef INCLUDE__InformationManager_hxx
2 #define INCLUDE__InformationManager_hxx
4 #include <log4cxx/logger.h>
5 #include <boost/signals2.hpp>
11 #include "disassembler/Disassembler.hxx"
19 class RenameFunctionEvent;
20 class NewFunctionEvent;
21 class ChangeCommentEvent;
27 using boost::signals2::connection;
29 class InformationManager {
32 ~InformationManager();
34 void reset(const std::string& filename);
35 void load(const std::string& filename);
36 void save(const std::string& filename);
38 Disassembler* getDisassembler()
39 { return disassembler.get(); }
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); }
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); }
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); }
62 connection connect_reset_signal(std::function<void ()> f)
63 { return reset_signal.connect(f); }
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();
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();
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();
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();
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*()
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
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
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);
120 boost::signals2::signal<void (RenameFunctionEvent*)> renameFunctionSignal;
121 boost::signals2::signal<void (NewFunctionEvent*)> newFunctionSignal;
122 boost::signals2::signal<void (ChangeCommentEvent*)> changeCommentSignal;
124 boost::signals2::signal<void ()> reset_signal;
126 std::unique_ptr<Disassembler> disassembler;
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;
133 std::string filename;
134 std::unique_ptr<QTemporaryFile> tmpfile;
135 std::vector<QPluginLoader*> plugins;
137 log4cxx::LoggerPtr logger;
140 #endif /* INCLUDE__InformationManager_hxx */