From 46a4a119be08a93575fb94182f7f30bb371f3054 Mon Sep 17 00:00:00 2001 From: hploetz Date: Wed, 14 Jun 2006 09:12:03 +0000 Subject: variable length hexdumps git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@85 f711b948-2313-0410-aaa9-d29f33439f0b --- utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'utils.py') 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", -- cgit v1.2.3