aboutsummaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-06-14 09:12:03 +0000
committerhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-06-14 09:12:03 +0000
commit46a4a119be08a93575fb94182f7f30bb371f3054 (patch)
treeb75804c533777381b60dabf56b16fe8ce718cb58 /utils.py
parent9c614ae526a937e90012febba52724f1a5be3f38 (diff)
variable length hexdumps
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@85 f711b948-2313-0410-aaa9-d29f33439f0b
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/utils.py b/utils.py
index 09fe00d..e9cc38b 100644
--- a/utils.py
+++ b/utils.py
@@ -37,7 +37,7 @@ def parse_binary(value, bytemasks, verbose = False, value_len = 8):
return result
_myprintable = " " + string.letters + string.digits + string.punctuation
-def hexdump(data, indent = 0, short = False):
+def hexdump(data, indent = 0, short = False, linelen = 16):
r"""Generates a nice hexdump of data and returns it. Consecutive lines will
be indented with indent spaces. When short is true, will instead generate
hexdump without adresses and on one line.
@@ -56,15 +56,16 @@ def hexdump(data, indent = 0, short = False):
if short:
return "%s (%s)" % (hexable(data), printable(data))
+ FORMATSTRING = "%04x: %-"+ str(linelen*3) +"s %-"+ str(linelen) +"s"
result = ""
- (head, tail) = (data[:16], data[16:])
+ (head, tail) = (data[:linelen], data[linelen:])
pos = 0
while len(head) > 0:
if pos > 0:
result = result + "\n%s" % (' ' * indent)
- result = result + "%04x: %-48s %-16s" % (pos, hexable(head), printable(head))
+ result = result + FORMATSTRING % (pos, hexable(head), printable(head))
pos = pos + len(head)
- (head, tail) = (tail[:16], tail[16:])
+ (head, tail) = (tail[:linelen], tail[linelen:])
return result
LIFE_CYCLES = {0x01: "Load file = loaded",