diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-07 20:11:57 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-07 20:11:57 +0200 |
| commit | 35be012af254617b72ecbe4bca718f3ce96c1fd2 (patch) | |
| tree | 34745f1537181d800e8da5ef19d6dccfe535d952 /disasm/dumpobject.cpp | |
| parent | a10cf47a9701a4d0be83940a23a8edf9a5ed7b5e (diff) | |
| download | openwar-35be012af254617b72ecbe4bca718f3ce96c1fd2.tar.gz openwar-35be012af254617b72ecbe4bca718f3ce96c1fd2.tar.bz2 openwar-35be012af254617b72ecbe4bca718f3ce96c1fd2.zip | |
cleaned up disasm, and prepared it to handle multiple commands.
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; + } +} |
