+void LLVMDisassembler::printEachInstruction(uint64_t start, uint64_t end,
+ std::function<void (uint8_t*, size_t, const std::string&)> fun) {
+ SectionRef text_section = sections[".text"];
+ uint64_t base_address;
+ text_section.getAddress(base_address);
+ uint64_t current_address = start - base_address;
+
+ StringRef bytes;
+ text_section.getContents(bytes);
+ StringRefMemoryObject ref(bytes);
+
+ while (current_address < end - base_address) {
+ uint64_t inst_size;
+ MCInst inst;
+ std::string buf;
+ llvm::raw_string_ostream s(buf);
+
+ if(llvm::MCDisassembler::Success ==
+ DisAsm->getInstruction(inst, inst_size, ref, current_address, nulls(), nulls())) {
+
+ uint8_t bytes[inst_size+2];
+ ref.readBytes(current_address, inst_size, bytes);
+
+ uint64_t jmptarget;
+ if (MIA->evaluateBranch(inst, current_address, inst_size, jmptarget)) {
+ std::stringstream stream;
+ stream << std::hex << (base_address + jmptarget);
+ IP->printInst(&inst, s, stream.str());
+ } else
+ IP->printInst(&inst, s, "");
+
+ fun(bytes, inst_size, s.str());
+ } else {
+ LOG4CXX_WARN(logger, "Invalid byte at" << std::hex << current_address + base_address);
+ fun(NULL, 0, "Invalid Byte");
+ inst_size = 1;
+ }
+
+ current_address += inst_size;
+ }