]> git.siccegge.de Git - frida/frida.git/commitdiff
Add dynamically linked symbols
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 21 Jan 2015 16:19:47 +0000 (17:19 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 21 Jan 2015 16:19:47 +0000 (17:19 +0100)
src/core/InformationManager.hxx
src/disassembler/llvm/LLVMDisassembler.cxx
src/disassembler/llvm/LLVMDisassembler.hxx
src/gui/Mainwindow.cxx

index 5d2ef64c67342f98cfddd2805d36335c0cfc22b0..9285d5fdd92658e3196ec7b340110b40d7bf4e5b 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <boost/signals2.hpp>
 #include <functional>
+#include <string>
 
 class Disassembler;
 class Function;
@@ -18,6 +19,15 @@ public:
                new_function_signal(f);
        }
 
+       boost::signals2::connection
+       connect_new_dyn_symbol_signal(std::function<void(const std::string& name)> 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<void ()> f) {
                return reset_signal.connect(f);
@@ -37,6 +47,7 @@ public:
 private:
        boost::signals2::signal<void ()> reset_signal;
        boost::signals2::signal<void (Function*)> new_function_signal;
+       boost::signals2::signal<void (const std::string& name)> new_dyn_symbol_signal;
        std::unique_ptr<Disassembler> disassembler;
 };
 
index 18cfe8065eefc0fb5e409d7978408e50dd47a1b2..5652cfb8bb2e62f6bb04813606aa82397861f65d 100644 (file)
@@ -156,6 +156,7 @@ void LLVMDisassembler<ELFT>::start() {
        readSymbols();
        readSections();
        disassemble();
+       readDynamicSymbols();
 }
 
 template <typename ELFT>
@@ -320,7 +321,6 @@ void LLVMDisassembler<ELFT>::disassemble() {
        }
 
        if (binary->isELF()) {
-               typedef ELFFile<ELFT> ELFO;
                const ELFO * elffile = o->getELFFile();
                const typename ELFO::Elf_Ehdr * header = elffile->getHeader();
 
@@ -389,6 +389,25 @@ void LLVMDisassembler<ELFT>::splitBlocks(LLVMFunction* function) {
        }
 }
 
+template <typename ELFT>
+void LLVMDisassembler<ELFT>::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 <typename ELFT>
 void LLVMDisassembler<ELFT>::readSymbols() {
        error_code ec;
index 6c8767aa1a2bc7b55cb116408446504c109ef513..95e961fb5656804ef745e4dc073ed496a41fe7ff 100644 (file)
@@ -44,6 +44,8 @@ protected:
        bool isJump(uint64_t address) {return false;}
 
 private:
+       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);
@@ -51,6 +53,7 @@ private:
 
        void readSymbols();
        void readSections();
+       void readDynamicSymbols();
 
        log4cxx::LoggerPtr logger;
        std::map<uint64_t, LLVMBasicBlock*> blocks;
index 5931a834f47bf69f8ce3764d438e46510098b386..46ce2e98562a24cca3b63c460a935529a979de48 100644 (file)
@@ -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()