diff options
Diffstat (limited to 'disasm/dumpobject.cpp')
| -rw-r--r-- | disasm/dumpobject.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/disasm/dumpobject.cpp b/disasm/dumpobject.cpp new file mode 100644 index 0000000..85fbf43 --- /dev/null +++ b/disasm/dumpobject.cpp @@ -0,0 +1,47 @@ +#include "dumpobject.hpp" + +#include "le_file.hpp" + +#include <distorm.h> + +#include <iomanip> + +void dump_object(std::ifstream& ifs, uint32_t object_id) +{ + auto x = le::parse_file(ifs); + + ifs.clear(); + ifs.seekg(0, std::ios::beg); + + std::vector<uint8_t> code(std::istreambuf_iterator<char>(ifs), {}); + + std::vector<_DecodedInst> instructions; + instructions.resize(100000); + unsigned int read_inst; + + auto object = x.object_table.entries[object_id]; + auto index = object.page_table_index; + + binparse::Offset32 offset = x.le_header.data_page_offset; + + auto result = distorm_decode64( + object.reloc_base_address, + code.data() + offset + (index - 1) * x.le_header.page_size, + x.object_table.entries[1].nr_page_table_entries * x.le_header.page_size, + Decode32Bits, + instructions.data(), + instructions.size(), + &read_inst + ); + + instructions.resize(read_inst); + instructions.shrink_to_fit(); + + if(result) { + + } + + for(auto&& inst : instructions) { + std::cout << std::hex << std::setw(8) << std::setfill('0') << inst.offset << ":\t" << inst.mnemonic.p << " " << inst.operands.p << std::endl; + } +} |
