diff options
author | itsme <itsme@xs4all.nl> | 2021-07-09 02:08:22 +0200 |
---|---|---|
committer | itsme <itsme@xs4all.nl> | 2021-07-09 02:08:22 +0200 |
commit | 2a9e53566d873b226d1523adcb80f78c14b4d773 (patch) | |
tree | ee374fcf8b441e75bad32f3d659bb75c36f55d48 /hexdump.py | |
parent | 8bcb2e9f570d3ee4a84884e5907b03e37a0b8389 (diff) |
added support for compressed records. kodump now supports a --width option.
Diffstat (limited to 'hexdump.py')
-rw-r--r-- | hexdump.py | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -26,9 +26,17 @@ def aschr(b): | |||
26 | return "." | 26 | return "." |
27 | def asasc(line): | 27 | def asasc(line): |
28 | return "".join(aschr(_) for _ in line) | 28 | return "".join(aschr(_) for _ in line) |
29 | def hexdump(ofs, data): | 29 | def hexdump(ofs, data, args): |
30 | for o in range(0, len(data), 16): | 30 | w = args.width |
31 | print("%08x: %-47s %s" % (o+ofs, ashex(data[o:o+16]), asasc(data[o:o+16]))) | 31 | if args.ascdump: |
32 | fmt = "%08x: %s" | ||
33 | else: | ||
34 | fmt = "%%08x: %%-%ds %%s" % (3*w-1) | ||
35 | for o in range(0, len(data), w): | ||
36 | if args.ascdump: | ||
37 | print(fmt % (o+ofs, asasc(data[o:o+w]))) | ||
38 | else: | ||
39 | print(fmt % (o+ofs, ashex(data[o:o+w]), asasc(data[o:o+w]))) | ||
32 | 40 | ||
33 | def tohex(data): | 41 | def tohex(data): |
34 | return b2a_hex(data).decode('ascii') | 42 | return b2a_hex(data).decode('ascii') |