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;