diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-08 21:49:49 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-08 21:49:49 +0200 |
| commit | cec56db9d4c84de13796ce7cd7dcd2631c443cec (patch) | |
| tree | d21847b479ee5bf4f263abd124a8dc7a3293e1cd /disasm/extractfunction.cpp | |
| parent | 35be012af254617b72ecbe4bca718f3ce96c1fd2 (diff) | |
| download | openwar-cec56db9d4c84de13796ce7cd7dcd2631c443cec.tar.gz openwar-cec56db9d4c84de13796ce7cd7dcd2631c443cec.tar.bz2 openwar-cec56db9d4c84de13796ce7cd7dcd2631c443cec.zip | |
Refactored argument parsing, and added stub for extractfunction.
Diffstat (limited to 'disasm/extractfunction.cpp')
| -rw-r--r-- | disasm/extractfunction.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/disasm/extractfunction.cpp b/disasm/extractfunction.cpp new file mode 100644 index 0000000..6d6f7bc --- /dev/null +++ b/disasm/extractfunction.cpp @@ -0,0 +1,39 @@ +#include "extractfunction.hpp" + +#include "parsefileandrewind.hpp" + +#include <distorm.h> + +#include <iomanip> + +void extract_function(std::istream& is, binparse::Value32 object_id, binparse::Offset32 function_offset) { + + auto file = parse_file_and_rewind(is); + + is.ignore(file.le_header.data_page_offset); + + _DInst decodedInstructions[1]; + _DecodeType dt = Decode32Bits; + unsigned int decodedInstructionsCount = 0; + + auto object = file.object_table.entries[object_id]; + unsigned int object_size = object.nr_page_table_entries * file.le_header.page_size; + + std::vector<uint8_t> code_buf; + code_buf.reserve(object_size); + std::copy_n(std::istream_iterator<uint8_t>(is), object_size, std::back_inserter(code_buf)); + + _CodeInfo ci; + ci.code = code_buf.data() + function_offset; + ci.codeLen = code_buf.size() - function_offset; + ci.codeOffset = object.reloc_base_address + function_offset; + ci.dt = dt; + ci.features = DF_NONE; + + distorm_decompose64(&ci, decodedInstructions, 1, &decodedInstructionsCount); + + _DecodedInst inst; + distorm_format64(&ci, &decodedInstructions[0], &inst); + + std::cout << std::hex << std::setw(8) << std::setfill('0') << inst.offset << ":\t" << inst.mnemonic.p << " " << inst.operands.p << std::endl; +} |
