Recursive disassembler
[frida/frida.git] / src / disassembler / llvm / LLVMDisassembler.hxx
1 #ifndef INCLUDE__LLVMDisassembler_hxx
2 #define INCLUDE__LLVMDisassembler_hxx
3
4 #include <memory>
5 #include <map>
6 #include <log4cxx/logger.h>
7
8 #include "include_llvm.hxx"
9
10 #include "disassembler/Disassembler.hxx"
11 #include "disassembler/llvm/LLVMBasicBlock.hxx"
12
13
14 class LLVMDisassembler
15 : public Disassembler {
16 public:
17 LLVMDisassembler(const std::string& filename);
18 virtual ~LLVMDisassembler() {};
19
20 void getSymbols();
21 uint64_t entryAddress();
22
23 void forEachInstruction(const std::string& name,
24 std::function<void (long, std::string, std::string)> callback)
25 {}
26
27 BasicBlock * generateControlFlowGraph(const std::string& name);
28 BasicBlock * generateControlFlowGraph(uint64_t address);
29
30 protected:
31 bool isFunctionCall(uint64_t address) {return false;}
32 bool isJump(uint64_t address) {return false;}
33
34 private:
35 void disassemble();
36
37 void readSymbols();
38 void readSections();
39
40 log4cxx::LoggerPtr logger;
41 std::map<uint8_t, LLVMBasicBlock*> blocks;
42
43 llvm::Triple triple;
44 std::shared_ptr<llvm::object::Binary> binary;
45
46
47 const llvm::Target * target;
48 llvm::object::ObjectFile * o;
49
50 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
51 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
52 std::unique_ptr<llvm::MCModule> Mod;
53 std::unique_ptr<llvm::MCInstPrinter> IP;
54 std::unique_ptr<llvm::MCDisassembler> DisAsm;
55 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
56 std::unique_ptr<llvm::MCContext> Ctx;
57 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
58 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
59 std::unique_ptr<const llvm::MCInstrInfo> MII;
60 llvm::OwningPtr<llvm::MCRelocationInfo> RelInfo;
61 llvm::OwningPtr<llvm::MCSymbolizer> Symzer;
62
63 std::map<std::string, llvm::object::SectionRef> sections;
64 std::map<std::string, llvm::object::SymbolRef> symbols;
65 };
66
67 #endif