]> git.siccegge.de Git - frida/frida.git/commitdiff
Handle case with no known functions properl
authorChristoph Egger <christoph@christoph-egger.org>
Sun, 8 Dec 2013 20:57:00 +0000 (21:57 +0100)
committerChristoph Egger <christoph@christoph-egger.org>
Sun, 8 Dec 2013 20:57:00 +0000 (21:57 +0100)
src/Binary.cxx

index 83909a0915a1767f8da82b6c91dd5d2b57f98646..1fcd908543ea767bd20affe2cc337d85ade4a72b 100644 (file)
@@ -187,22 +187,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());
+
+            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;
+
+        }
+        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;
+        }
 
-        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;
 
-        // outs() << "Middle for_each_instruction " << function << " Size: " << ssize << "\n";
+        // 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;