diff options
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') |