X-Git-Url: https://git.siccegge.de//index.cgi?p=frida%2Ffrida.git;a=blobdiff_plain;f=src%2Fdisassembler%2Fllvm%2FLLVMDisassembler.cxx;h=d2c68fdce4f4f48f803c90726a2707565007d8fc;hp=8dd548332bf4f1f01106cd2020db3b137e13b626;hb=d5084161ca261d7fc0bd284621569440b6503eac;hpb=879c174dd56331b6c7b3254edd115e46a0b5e78c diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index 8dd5483..d2c68fd 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -1,6 +1,7 @@ #include "disassembler/llvm/LLVMDisassembler.hxx" #include "disassembler/llvm/LLVMBasicBlock.hxx" #include "disassembler/llvm/LLVMFunction.hxx" +#include "core/InformationManager.hxx" #include #include @@ -156,18 +157,19 @@ void LLVMDisassembler::start() { readSymbols(); readSections(); disassemble(); + readDynamicSymbols(); } template LLVMDisassembler::~LLVMDisassembler() { - std::for_each(functions.begin(), functions.end(), - [](std::pair it) { - delete it.second; - }); - std::for_each(blocks.begin(), blocks.end(), - [](std::pair it) { - delete it.second; - }); + // std::for_each(functions.begin(), functions.end(), + // [](std::pair it) { + // delete it.second; + // }); + // std::for_each(blocks.begin(), blocks.end(), + // [](std::pair it) { + // delete it.second; + // }); } template @@ -320,16 +322,10 @@ void LLVMDisassembler::disassemble() { } if (binary->isELF()) { - bool is64bit = (binary->getData()[4] == 0x02); + const ELFO * elffile = o->getELFFile(); + const typename ELFO::Elf_Ehdr * header = elffile->getHeader(); - for (int i(0); i < (is64bit? 8 : 4); ++i) { - if (binary->isLittleEndian()) { - _entryAddress |= (unsigned int)((unsigned char)binary->getData()[0x18 + i]) << 8*i; - } else { - _entryAddress = _entryAddress << 8; - _entryAddress |= (unsigned char)binary->getData()[0x18 + i]; - } - } + _entryAddress = header->e_entry; LOG4CXX_DEBUG(logger, "Adding entryAddress at: " << std::hex << _entryAddress); std::stringstream s; s << "<_start 0x" << std::hex << _entryAddress << ">"; @@ -394,6 +390,25 @@ void LLVMDisassembler::splitBlocks(LLVMFunction* function) { } } +template +void LLVMDisassembler::readDynamicSymbols() { + const ELFO * elffile = o->getELFFile(); + for (typename ELFO::Elf_Sym_Iter + it = elffile->begin_dynamic_symbols(), + end = elffile->end_dynamic_symbols(); + it != end; + ++it) { + if (it->getType() == 2) { // Function + bool is_default; + // TODO: Error handling + std::string symbolname = *(elffile->getSymbolName(it)); + std::string symbolversion = *(elffile->getSymbolVersion(nullptr, &*it, is_default)); + manager->signal_new_dyn_symbol(symbolname + (is_default? "@@" : "@") + symbolversion); + LOG4CXX_DEBUG(logger, "Adding dynamic Symbol " << symbolname << (is_default? "@@" : "@") << symbolversion); + } + } +} + template void LLVMDisassembler::readSymbols() { error_code ec;