]> git.siccegge.de Git - frida/frida.git/blobdiff - src/Binary.cxx
Separate out several parts of llvm-using code ; Add logger
[frida/frida.git] / src / Binary.cxx
index 83909a0915a1767f8da82b6c91dd5d2b57f98646..1d64b8445a0ef80bfcdfd3d87d1aa90302d8c6c5 100644 (file)
@@ -1,5 +1,7 @@
 #include "Binary.hxx"
 
+#include "disassembler/Disassembler.hxx"
+
 #include <iostream>
 #include <string>
 #include <algorithm>
@@ -83,6 +85,7 @@ namespace qtlldb {
     Binary::Binary(const std::string& filename)
         : triple("unkown-unknown-unknown")
     {
+        ::Disassembler d(filename);
         std::string error;
 
         createBinary(filename, binary);
@@ -187,22 +190,36 @@ namespace qtlldb {
     void Binary::for_each_instruction(const std::string& function,
                                       std::function<void (long, std::string, std::string)> callback) {
         StringRef bytes;
-        SymbolRef ref = symbols[function];
-        section_iterator sec(o->begin_sections());
         uint64_t base_address, address, ssize, size(0), index, end;
+        StringRefMemoryObject memoryObject("");
 
-        // outs() << "Start for_each_instruction " << function << "\n";
+        if (symbols.end() != symbols.find(function)) {
+            SymbolRef ref;
+            section_iterator sec(o->begin_sections());
 
-        if (error(ref.getSection(sec))) return;
-        if (error(ref.getAddress(address))) return;
-        if (address == UnknownAddressOrSize) return;
-        if (error(ref.getSize(ssize))) return;
-        if (error(sec->getAddress(base_address))) return;
-        if (error(sec->getContents(bytes))) return;
+            ref = symbols.at(function);
+            if (error(ref.getSection(sec))) return;
+            if (error(ref.getAddress(address))) return;
+            if (address == UnknownAddressOrSize) return;
+            if (error(ref.getSize(ssize))) return;
+            if (error(sec->getAddress(base_address))) return;
+            if (error(sec->getContents(bytes))) return;
+            memoryObject = bytes;
 
-        // outs() << "Middle for_each_instruction " << function << " Size: " << ssize << "\n";
+        }
+        else if (sections.end() != sections.find(function)) {
+            SectionRef sref = sections.at(function);
+            if (error(sref.getAddress(address))) return;
+            if (address == UnknownAddressOrSize) return;
+            if (error(sref.getSize(ssize))) return;
+            if (error(sref.getContents(bytes))) return;
+            base_address = address;
+            memoryObject = bytes;
+        }
+
+
+        // outs() << "Start for_each_instruction " << function << "\n";
 
-        StringRefMemoryObject memoryObject(bytes);
         
         for (end = address + ssize - base_address, index = address - base_address; index < end; index += size) {
             MCInst Inst;