From 721087eeeb933d4a46873870644e0762a158dbfd Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Sat, 31 Oct 2009 19:46:55 +0000 Subject: [PATCH] Added -flipped option to unidasm to output with disassembly first and address/data bytes afterwards in comment form. --- src/tools/unidasm.c | 100 +++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/src/tools/unidasm.c b/src/tools/unidasm.c index 49cdee36253..92f9844904b 100644 --- a/src/tools/unidasm.c +++ b/src/tools/unidasm.c @@ -81,6 +81,7 @@ struct _options UINT8 norawbytes; UINT8 lower; UINT8 upper; + UINT8 flipped; int mode; const dasm_table_entry *dasm; }; @@ -379,6 +380,8 @@ static int parse_options(int argc, char *argv[], options *opts) pending_arch = TRUE; else if (tolower((UINT8)curarg[1]) == 'b') pending_base = TRUE; + else if (tolower((UINT8)curarg[1]) == 'f') + opts->flipped = TRUE; else if (tolower((UINT8)curarg[1]) == 'l') opts->lower = TRUE; else if (tolower((UINT8)curarg[1]) == 'm') @@ -445,7 +448,8 @@ static int parse_options(int argc, char *argv[], options *opts) return 0; usage: - printf("Usage: %s -arch [-basepc ] [-mode ] [-norawbytes] [-upper] [-lower]\n", argv[0]); + printf("Usage: %s -arch [-basepc ] \n", argv[0]); + printf(" [-mode ] [-norawbytes] [-flipped] [-upper] [-lower]\n"); printf("\n"); printf("Supported architectures:"); numrows = (ARRAY_LENGTH(dasm_table) + 6) / 7; @@ -515,33 +519,7 @@ int main(int argc, char *argv[]) else numbytes = pcdelta >> opts.dasm->pcshift; - // round to the nearest display chunk - numbytes = ((numbytes + displaychunk - 1) / displaychunk) * displaychunk; - if (numbytes == 0) - numbytes = displaychunk; - numchunks = numbytes / displaychunk; - - // output the address - printf("%08X: ", curpc); - - // output the raw bytes - if (!opts.norawbytes) - { - int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks; - int chunknum, bytenum; - for (chunknum = 0; chunknum < firstchunks; chunknum++) - { - for (bytenum = 0; bytenum < displaychunk; bytenum++) - printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]); - printf(" "); - oprom += displaychunk; - } - for ( ; chunknum < maxchunks; chunknum++) - printf("%*s ", displaychunk * 2, ""); - printf(" "); - } - - // output the disassembly + // force upper or lower if (opts.lower) { for (p = buffer; *p != 0; p++) @@ -552,16 +530,24 @@ int main(int argc, char *argv[]) for (p = buffer; *p != 0; p++) *p = toupper((UINT8)*p); } - printf("%s\n", buffer); - // output additional raw bytes - if (!opts.norawbytes && numchunks > maxchunks) + // round to the nearest display chunk + numbytes = ((numbytes + displaychunk - 1) / displaychunk) * displaychunk; + if (numbytes == 0) + numbytes = displaychunk; + numchunks = numbytes / displaychunk; + + // non-flipped case + if (!opts.flipped) { - for (numchunks -= maxchunks; numchunks > 0; numchunks -= maxchunks) + // output the address + printf("%08X: ", curpc); + + // output the raw bytes + if (!opts.norawbytes) { int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks; int chunknum, bytenum; - printf(" "); for (chunknum = 0; chunknum < firstchunks; chunknum++) { for (bytenum = 0; bytenum < displaychunk; bytenum++) @@ -569,8 +555,54 @@ int main(int argc, char *argv[]) printf(" "); oprom += displaychunk; } - printf("\n"); + for ( ; chunknum < maxchunks; chunknum++) + printf("%*s ", displaychunk * 2, ""); + printf(" "); } + + // output the disassembly + printf("%s\n", buffer); + + // output additional raw bytes + if (!opts.norawbytes && numchunks > maxchunks) + { + for (numchunks -= maxchunks; numchunks > 0; numchunks -= maxchunks) + { + int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks; + int chunknum, bytenum; + printf(" "); + for (chunknum = 0; chunknum < firstchunks; chunknum++) + { + for (bytenum = 0; bytenum < displaychunk; bytenum++) + printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]); + printf(" "); + oprom += displaychunk; + } + printf("\n"); + } + } + } + + // flipped case + else + { + // output the disassembly and address + printf("\t%-40s ; %08X", buffer, curpc); + + // output the raw bytes + if (!opts.norawbytes) + { + int chunknum, bytenum; + printf(": "); + for (chunknum = 0; chunknum < numchunks; chunknum++) + { + for (bytenum = 0; bytenum < displaychunk; bytenum++) + printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]); + printf(" "); + oprom += displaychunk; + } + } + printf("\n"); } // advance