From 2a9e53566d873b226d1523adcb80f78c14b4d773 Mon Sep 17 00:00:00 2001 From: itsme Date: Fri, 9 Jul 2021 02:08:22 +0200 Subject: added support for compressed records. kodump now supports a --width option. --- hexdump.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'hexdump.py') diff --git a/hexdump.py b/hexdump.py index cbba3c9..984a19f 100644 --- a/hexdump.py +++ b/hexdump.py @@ -26,9 +26,17 @@ def aschr(b): return "." def asasc(line): return "".join(aschr(_) for _ in line) -def hexdump(ofs, data): - for o in range(0, len(data), 16): - print("%08x: %-47s %s" % (o+ofs, ashex(data[o:o+16]), asasc(data[o:o+16]))) +def hexdump(ofs, data, args): + w = args.width + if args.ascdump: + fmt = "%08x: %s" + else: + fmt = "%%08x: %%-%ds %%s" % (3*w-1) + for o in range(0, len(data), w): + if args.ascdump: + print(fmt % (o+ofs, asasc(data[o:o+w]))) + else: + print(fmt % (o+ofs, ashex(data[o:o+w]), asasc(data[o:o+w]))) def tohex(data): return b2a_hex(data).decode('ascii') -- cgit v1.2.3