From e5e574df7edc326b258533e18e20cd7b2a5c9072 Mon Sep 17 00:00:00 2001 From: AJR Date: Fri, 12 Jul 2019 22:47:43 -0400 Subject: unidasm: Add -xchbytes option to swap bytes --- src/tools/unidasm.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/tools/unidasm.cpp b/src/tools/unidasm.cpp index 135a540da05..b2361ff7ffd 100644 --- a/src/tools/unidasm.cpp +++ b/src/tools/unidasm.cpp @@ -296,6 +296,7 @@ struct options const char * filename; offs_t basepc; uint8_t norawbytes; + uint8_t xchbytes; uint8_t lower; uint8_t upper; uint8_t flipped; @@ -951,6 +952,8 @@ static int parse_options(int argc, char *argv[], options *opts) opts->norawbytes = true; else if(tolower((uint8_t)curarg[1]) == 'u') opts->upper = true; + else if(tolower((uint8_t)curarg[1]) == 'x') + opts->xchbytes = true; else goto usage; } @@ -1029,7 +1032,7 @@ static int parse_options(int argc, char *argv[], options *opts) usage: printf("Usage: %s -arch [-basepc ] \n", argv[0]); - printf(" [-mode ] [-norawbytes] [-flipped] [-upper] [-lower]\n"); + printf(" [-mode ] [-norawbytes] [-xchbytes] [-flipped] [-upper] [-lower]\n"); printf(" [-skip ] [-count ]\n"); printf("\n"); printf("Supported architectures:"); @@ -1080,7 +1083,14 @@ int main(int argc, char *argv[]) base_buffer.data.resize(rounded_size + 8, 0x00); base_buffer.size = length; base_buffer.base_pc = opts.basepc; - memcpy(&base_buffer.data[0], (const u8 *)data + opts.skip, length - opts.skip); + if(opts.xchbytes) { + for(uint32_t offset = opts.skip; offset < length - 1; offset += 2) { + base_buffer.data[offset - opts.skip] = ((const u8 *)data)[offset + 1]; + base_buffer.data[offset - opts.skip + 1] = ((const u8 *)data)[offset]; + } + } + else + memcpy(&base_buffer.data[0], (const u8 *)data + opts.skip, length - opts.skip); // Build the decryption buffers if needed unidasm_data_buffer opcodes_buffer(disasm.get(), opts.dasm), params_buffer(disasm.get(), opts.dasm); -- cgit v1.2.3