#define INCLUDE__LLVMDisassembler_hxx
#include <memory>
+#include <map>
#include <log4cxx/logger.h>
#include "include_llvm.hxx"
#include "disassembler/Disassembler.hxx"
+class Function;
+class BasicBlock;
+class LLVMFunction;
+class LLVMBasicBlock;
+Disassembler * createLLVMDisassembler(const std::string& filename, InformationManager* manager);
+
+template <typename ELFT>
class LLVMDisassembler
- : public Disassembler {
+ : public Disassembler {
public:
- LLVMDisassembler(const std::string& filename);
- virtual ~LLVMDisassembler() {};
+ LLVMDisassembler(const std::string& filename, InformationManager* manager,
+ llvm::object::ELFObjectFile<ELFT>* file = NULL);
+ virtual ~LLVMDisassembler();
+
+ void start();
+ void getSymbols() {}
+ uint64_t entryAddress() {return _entryAddress;}
- void getSymbols();
- uint64_t entryAddress();
+ void forEachFunction(std::function<void (uint64_t, Function*)> callback);
+ void printEachInstruction(uint64_t start, uint64_t end,
+ std::function<void (uint8_t*, size_t, const std::string&,
+ const std::string&)> fun);
- void forEachInstruction(const std::string& name, std::function<void (long, std::string, std::string)> callback) {}
+ BasicBlock * getBasicBlock(uint64_t address) {
+ return blocks[address];
+ }
- BasicBlock * generateControlFlowGraph(const std::string& name);
- BasicBlock * generateControlFlowGraph(uint64_t address);
+ Function * disassembleFunctionAt(uint64_t address, const std::string& name = "");
protected:
- bool isFunctionCall(uint64_t address) {return false;}
- bool isJump(uint64_t address) {return false;}
+ bool isFunctionCall(uint64_t address) {return false;}
+ bool isJump(uint64_t address) {return false;}
private:
- log4cxx::LoggerPtr logger;
-
- llvm::Triple triple;
- std::shared_ptr<llvm::object::Binary> binary;
-
-
- const llvm::Target * target;
- llvm::object::ObjectFile * o;
-
- std::unique_ptr<const llvm::MCRegisterInfo> MRI;
- std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
- std::unique_ptr<llvm::MCModule> Mod;
- std::unique_ptr<llvm::MCInstPrinter> IP;
- std::unique_ptr<llvm::MCDisassembler> DisAsm;
- std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
- std::unique_ptr<llvm::MCContext> Ctx;
- std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
- std::unique_ptr<const llvm::MCSubtargetInfo> STI;
- std::unique_ptr<const llvm::MCInstrInfo> MII;
- llvm::OwningPtr<llvm::MCRelocationInfo> RelInfo;
- llvm::OwningPtr<llvm::MCSymbolizer> Symzer;
-
- std::map<std::string, llvm::object::SectionRef> sections;
- std::map<std::string, llvm::object::SymbolRef> symbols;
+ typedef llvm::object::ELFFile<ELFT> ELFO;
+
+ // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197
+ void disassembleFunction(LLVMFunction* function);
+ void splitBlocks(LLVMFunction* fun);
+ void disassemble();
+
+ void readSymbols();
+ void readSections();
+ void readDynamicSymbols();
+
+ log4cxx::LoggerPtr logger;
+ std::map<uint64_t, LLVMBasicBlock*> blocks;
+ std::map<uint64_t, LLVMFunction*> functions;
+
+ llvm::Triple triple;
+ std::shared_ptr<llvm::object::Binary> binary;
+
+ const llvm::Target * target;
+ llvm::object::ELFObjectFile<ELFT> * o;
+
+ std::unique_ptr<const llvm::MCRegisterInfo> MRI;
+ std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
+ std::unique_ptr<llvm::MCModule> Mod;
+ std::unique_ptr<llvm::MCInstPrinter> IP;
+ std::unique_ptr<llvm::MCDisassembler> DisAsm;
+ std::unique_ptr<const llvm::MCObjectFileInfo> MOFI;
+ std::unique_ptr<llvm::MCContext> Ctx;
+ std::unique_ptr<const llvm::MCInstrAnalysis> MIA;
+ std::unique_ptr<const llvm::MCSubtargetInfo> STI;
+ std::unique_ptr<const llvm::MCInstrInfo> MII;
+ std::unique_ptr<llvm::MCRelocationInfo> RelInfo;
+ std::unique_ptr<llvm::MCSymbolizer> Symzer;
+
+ std::map<std::string, llvm::object::SectionRef> sections;
+ std::map<std::string, llvm::object::SymbolRef> symbols;
+ InformationManager * manager;
+ uint64_t _entryAddress;
};
#endif