1 #ifndef INCLUDE__LLVMDisassembler_hxx
2 #define INCLUDE__LLVMDisassembler_hxx
6 #include <log4cxx/logger.h>
8 #include "include_llvm.hxx"
10 #include "disassembler/Disassembler.hxx"
11 #include "disassembler/BasicBlock.hxx"
12 #include "disassembler/Function.hxx"
13 #include "disassembler/llvm/LLVMBasicBlock.hxx"
14 #include "disassembler/llvm/LLVMFunction.hxx"
17 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
19 template <typename ELFT>
20 class LLVMDisassembler
21 : public Disassembler {
23 LLVMDisassembler(const std::string& filename, InformationManager* manager);
24 virtual ~LLVMDisassembler();
28 uint64_t entryAddress() {return _entryAddress;}
30 void forEachFunction(std::function<void (uint64_t, Function*)> callback);
31 void printEachInstruction(uint64_t start, uint64_t end,
32 std::function<void (uint8_t*, size_t, const std::string&,
33 const std::string&)> fun);
35 BasicBlock * getBasicBlock(uint64_t address) {
36 return blocks[address];
39 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
42 bool isFunctionCall(uint64_t address) {return false;}
43 bool isJump(uint64_t address) {return false;}
46 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
47 void disassembleFunction(LLVMFunction* function);
48 void splitBlocks(LLVMFunction* fun);
54 log4cxx::LoggerPtr logger;
55 std::map<uint64_t, LLVMBasicBlock*> blocks;
56 std::map<uint64_t, LLVMFunction*> functions;
59 std::shared_ptr<llvm::object::Binary> binary;
61 const llvm::Target * target;
62 llvm::object::ObjectFile * o;
64 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
65 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
66 std::unique_ptr<llvm::MCModule> Mod;
67 std::unique_ptr<llvm::MCInstPrinter> IP;
68 std::unique_ptr<llvm::MCDisassembler> DisAsm;
69 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
70 std::unique_ptr<llvm::MCContext> Ctx;
71 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
72 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
73 std::unique_ptr<const llvm::MCInstrInfo> MII;
74 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
75 std::unique_ptr<llvm::MCSymbolizer> Symzer;
77 std::map<std::string, llvm::object::SectionRef> sections;
78 std::map<std::string, llvm::object::SymbolRef> symbols;
79 InformationManager * manager;
80 uint64_t _entryAddress;