From 6375df7c896a8a0e4be6959392848f28b021073c Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Wed, 21 Jan 2015 17:19:47 +0100 Subject: [PATCH] Add dynamically linked symbols --- src/core/InformationManager.hxx | 11 +++++++++++ src/disassembler/llvm/LLVMDisassembler.cxx | 21 ++++++++++++++++++++- src/disassembler/llvm/LLVMDisassembler.hxx | 3 +++ src/gui/Mainwindow.cxx | 4 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index 5d2ef64..9285d5f 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -3,6 +3,7 @@ #include #include +#include class Disassembler; class Function; @@ -18,6 +19,15 @@ public: new_function_signal(f); } + boost::signals2::connection + connect_new_dyn_symbol_signal(std::function f) { + return new_dyn_symbol_signal.connect(f); + } + + void signal_new_dyn_symbol(const std::string& f) { + new_dyn_symbol_signal(f); + } + boost::signals2::connection connect_reset_signal(std::function f) { return reset_signal.connect(f); @@ -37,6 +47,7 @@ public: private: boost::signals2::signal reset_signal; boost::signals2::signal new_function_signal; + boost::signals2::signal new_dyn_symbol_signal; std::unique_ptr disassembler; }; diff --git a/src/disassembler/llvm/LLVMDisassembler.cxx b/src/disassembler/llvm/LLVMDisassembler.cxx index 18cfe80..5652cfb 100644 --- a/src/disassembler/llvm/LLVMDisassembler.cxx +++ b/src/disassembler/llvm/LLVMDisassembler.cxx @@ -156,6 +156,7 @@ void LLVMDisassembler::start() { readSymbols(); readSections(); disassemble(); + readDynamicSymbols(); } template @@ -320,7 +321,6 @@ void LLVMDisassembler::disassemble() { } if (binary->isELF()) { - typedef ELFFile ELFO; const ELFO * elffile = o->getELFFile(); const typename ELFO::Elf_Ehdr * header = elffile->getHeader(); @@ -389,6 +389,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; diff --git a/src/disassembler/llvm/LLVMDisassembler.hxx b/src/disassembler/llvm/LLVMDisassembler.hxx index 6c8767a..95e961f 100644 --- a/src/disassembler/llvm/LLVMDisassembler.hxx +++ b/src/disassembler/llvm/LLVMDisassembler.hxx @@ -44,6 +44,8 @@ protected: bool isJump(uint64_t address) {return false;} private: + typedef llvm::object::ELFFile ELFO; + // http://llvm.org/docs/doxygen/html/MCObjectDisassembler_8cpp_source.html +197 void disassembleFunction(LLVMFunction* function); void splitBlocks(LLVMFunction* fun); @@ -51,6 +53,7 @@ private: void readSymbols(); void readSections(); + void readDynamicSymbols(); log4cxx::LoggerPtr logger; std::map blocks; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 5931a83..46ce2e9 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -55,6 +55,10 @@ Mainwindow::Mainwindow(InformationManager* mgr) setWindowTitle(tr("FRIDA")); mgr->connect_new_function_signal([&] (Function* fun) {addFunction(fun);}); + mgr->connect_new_dyn_symbol_signal([&] (const std::string& name) { + auto item = new QListWidgetItem(name.c_str(), listWidget); + item->setBackground(QBrush(QColor(0xff, 0xdd, 0xdd))); + }); } void Mainwindow::quit() -- 2.39.5