summaryrefslogtreecommitdiff
path: root/hexdump.py
diff options
context:
space:
mode:
Diffstat (limited to 'hexdump.py')
-rw-r--r--hexdump.py14
1 files changed, 11 insertions, 3 deletions
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):
26 return "." 26 return "."
27def asasc(line): 27def asasc(line):
28 return "".join(aschr(_) for _ in line) 28 return "".join(aschr(_) for _ in line)
29def hexdump(ofs, data): 29def 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
33def tohex(data): 41def tohex(data):
34 return b2a_hex(data).decode('ascii') 42 return b2a_hex(data).decode('ascii')