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