1 #ifndef INCLUDE__InformationManager_hxx
2 #define INCLUDE__InformationManager_hxx
4 #include <log4cxx/logger.h>
12 #include "disassembler/Disassembler.hxx"
14 #include "core/events/NewFunctionEvent.hxx"
22 class RenameFunctionEvent;
23 class NewFunctionEvent;
24 class ChangeCommentEvent;
30 class InformationManager : public QObject {
37 void renameFunctionEvent(RenameFunctionEvent* event);
38 void newFunctionEvent(NewFunctionEvent event);
39 void changeCommentEvent(ChangeCommentEvent* event);
43 ~InformationManager();
45 // Start working on a fresh binary
46 void reset(const std::string& filename);
48 // Load a saved binary
49 void load(const std::string& filename);
51 // Save current state to disk
52 void save(const std::string& filename);
54 Disassembler* getDisassembler()
55 { return disassembler.get(); }
58 /* Used by the disassembler to determine whether to use unsafe
59 * heuristics for finding an entry point
61 bool hasFunctions() const {return functions.size() != 0;}
63 uint64_t getEntryAddress() {return disassembler->entryAddress();}
65 Function* getFunction(uint64_t address);
66 std::map<uint64_t, Function*>::const_iterator beginFunctions();
67 std::map<uint64_t, Function*>::const_iterator endFunctions();
69 BasicBlock* getBasicBlock(uint64_t address);
70 std::map<uint64_t, BasicBlock*>::const_iterator beginBasicBlocks();
71 std::map<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
74 std::multimap<uint64_t, Comment*>::const_iterator,
75 std::multimap<uint64_t, Comment*>::const_iterator>
76 getComments(uint64_t address);
77 std::multimap<uint64_t,Comment*>::const_iterator beginComments();
78 std::multimap<uint64_t,Comment*>::const_iterator endComments();
80 Interpreter* getInterpreter(const std::string& name);
81 bool hasInterpreters() const {return interpreters.size() != 0;}
82 std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
83 std::map<std::string, Interpreter*>::const_iterator endInterpreters();
87 * Users may allocate new Data containers with the new*()
88 * functions. Once they have populated the information they hand
89 * over the object to the information manager using the finish*()
92 * if new*() returns NULL there already exists a function at the
93 * specified address. Users may then get the old object if they
94 * wish or (more likely) skip creating it. Uniqueness of the
95 * object is only guaranteed as compared to the finish()ed
98 * Users are responsible for destroying functions iff they do not
99 * finish them using the delete*() functions. Once the objects are
100 * finished, the information manager is responsible for cleaning
101 * up the memory. If delete*() is called on a finished object, bad
104 Function* newFunction(uint64_t address);
105 Function* newDynamicFunction(uint64_t address);
106 BasicBlock* newBasicBlock(uint64_t address);
107 Comment* newGlobalComment(uint64_t address);
108 Comment* newLocalComment(uint64_t address, Function* f);
109 void finishFunction(Function* f);
110 void finishBasicBlock(BasicBlock* b);
111 void finishComment(Comment* c);
112 void deleteFunction(Function* f);
113 void deleteBasicBlock(BasicBlock* b);
114 void deleteComment(Comment* c);
117 std::unique_ptr<Disassembler> disassembler;
119 std::map<std::string, Interpreter*> interpreters;
120 std::map<uint64_t, Function*> functions;
121 std::map<uint64_t, BasicBlock*> blocks;
122 std::multimap<uint64_t, Comment*> comments;
124 std::string filename;
125 std::unique_ptr<QTemporaryFile> tmpfile;
126 std::vector<QPluginLoader*> plugins;
128 QThread disassemblerThread;
129 log4cxx::LoggerPtr logger;
132 #endif /* INCLUDE__InformationManager_hxx */