X-Git-Url: https://git.siccegge.de//index.cgi?p=frida%2Ffrida.git;a=blobdiff_plain;f=src%2FBinary.cxx;h=a659d5c450a58905effaf526d94f676360ac4935;hp=83909a0915a1767f8da82b6c91dd5d2b57f98646;hb=541e815a0f27feb84ad4bbb24d79c24b867a3a4e;hpb=37e3e9570967efad39ba74213f51bd12aebe4c8c diff --git a/src/Binary.cxx b/src/Binary.cxx index 83909a0..a659d5c 100644 --- a/src/Binary.cxx +++ b/src/Binary.cxx @@ -1,5 +1,7 @@ #include "Binary.hxx" +#include "disassembler/Disassembler.hxx" + #include #include #include @@ -54,8 +56,8 @@ namespace { std::map readSections(const ObjectFile& o) { error_code ec; std::map result; - section_iterator i(o.begin_sections()), e(o.end_sections()); - for (; i != e; i.increment(ec)) { + section_iterator i(o.section_begin()), e(o.section_end()); + for (; i != e; ++i) { StringRef name; if (error(i->getName(name))) break; @@ -67,8 +69,8 @@ namespace { std::map readSymbols(const ObjectFile& o) { error_code ec; std::map result; - symbol_iterator si(o.begin_symbols()), se(o.end_symbols()); - for (; si != se; si.increment(ec)) { + symbol_iterator si(o.symbol_begin()), se(o.symbol_end()); + for (; si != se; ++si) { StringRef name; if (error(si->getName(name))) break; @@ -83,15 +85,16 @@ namespace qtlldb { Binary::Binary(const std::string& filename) : triple("unkown-unknown-unknown") { + ::Disassembler d(filename); std::string error; - createBinary(filename, binary); - if (Archive *a = dyn_cast(binary.get())) { + binary = createBinary(filename).get(); + if (Archive *a = dyn_cast(binary)) { std::cerr << "Got an archive!" << std::endl; return; } - o = dyn_cast(binary.get()); + o = dyn_cast(binary); triple.setArch(Triple::ArchType(o->getArch())); std::string tripleName(triple.getTriple()); @@ -178,8 +181,12 @@ namespace qtlldb { std::vector result; for_each(symbols.begin(), symbols.end(), [&](const std::pair& i) { bool contains; - if (!error(r.containsSymbol(i.second, contains)) && contains) - result.push_back(i.first); + SymbolRef::Type t; + if (!error(r.containsSymbol(i.second, contains)) && contains) { + i.second.getType(t); + if (SymbolRef::ST_Function == t) + result.push_back(i.first); + } }); return result; } @@ -187,22 +194,36 @@ namespace qtlldb { void Binary::for_each_instruction(const std::string& function, std::function 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->section_begin()); - 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; @@ -251,9 +272,9 @@ namespace qtlldb { void Binary::disassemble_functions() { error_code ec; - for (section_iterator i = o->begin_sections(), - e = o->end_sections(); - i != e; i.increment(ec)) { + for (section_iterator i = o->section_begin(), + e = o->section_end(); + i != e; ++i) { if (error(ec)) break; bool text; if (error(i->isText(text))) break; @@ -264,9 +285,9 @@ namespace qtlldb { // Make a list of all the symbols in this section. std::vector > Symbols; - for (symbol_iterator si = o->begin_symbols(), - se = o->end_symbols(); - si != se; si.increment(ec)) { + for (symbol_iterator si = o->symbol_begin(), + se = o->symbol_end(); + si != se; ++si) { bool contains; if (!error(i->containsSymbol(*si, contains)) && contains) { uint64_t Address; @@ -347,7 +368,7 @@ namespace qtlldb { outs() << '\n' << Symbols[si].second << ":\n"; #ifndef NDEBUG - raw_ostream &DebugOut = DebugFlag ? dbgs() : nulls(); + raw_ostream &DebugOut = nulls(); //DebugFlag ? dbgs() : nulls(); #else raw_ostream &DebugOut = nulls(); #endif