]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler/llvm/LLVMDisassembler.hxx
2713ac6f32f561df00e252a53b0678c4fe6cc4d9
[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
12 class Function;
13 class BasicBlock;
14 class LLVMBasicBlock;
15
16 Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
17
18 template <typename ELFT>
19 class LLVMDisassembler
20 : public Disassembler {
21 public:
22 LLVMDisassembler(const std::string& filename, InformationManager* manager,
23 llvm::object::ELFObjectFile<ELFT>* file = NULL);
24 virtual ~LLVMDisassembler();
25
26 void start();
27 void getSymbols() {}
28 uint64_t entryAddress() {return _entryAddress;}
29
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);
34
35 BasicBlock * getBasicBlock(uint64_t address) {
36 return blocks[address];
37 }
38
39 Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
40
41 protected:
42 bool isFunctionCall(uint64_t address) {return false;}
43 bool isJump(uint64_t address) {return false;}
44
45 private:
46 typedef llvm::object::ELFFile<ELFT> ELFO;
47
48 // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
49 void disassembleFunction(Function* function);
50 void splitBlocks(Function* fun);
51 void disassemble();
52
53 void readSymbols();
54 void readSections();
55 void readDynamicSymbols();
56
57 log4cxx::LoggerPtr logger;
58 std::map<uint64_t, LLVMBasicBlock*> blocks;
59 std::map<uint64_t, Function*> functions;
60
61 llvm::Triple triple;
62 std::shared_ptr<llvm::object::Binary> binary;
63
64 const llvm::Target * target;
65 llvm::object::ELFObjectFile<ELFT> * o;
66
67 std::unique_ptr<const llvm::MCRegisterInfo> MRI;
68 std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
69 std::unique_ptr<llvm::MCModule> Mod;
70 std::unique_ptr<llvm::MCInstPrinter> IP;
71 std::unique_ptr<llvm::MCDisassembler> DisAsm;
72 std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
73 std::unique_ptr<llvm::MCContext> Ctx;
74 std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
75 std::unique_ptr<const llvm::MCSubtargetInfo> STI;
76 std::unique_ptr<const llvm::MCInstrInfo> MII;
77 std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
78 std::unique_ptr<llvm::MCSymbolizer> Symzer;
79
80 std::map<std::string, llvm::object::SectionRef> sections;
81 std::map<std::string, llvm::object::SymbolRef> symbols;
82 InformationManager * manager;
83 uint64_t _entryAddress;
84 };
85
86 #endif