From 08623baa4a1885ddffdcf5520b43349b1f2ce20b Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 8 Nov 2019 12:54:47 +0100 Subject: [PATCH] utils.py: generate multiline hexdumps At the moment we can only print single line hexdumps. This works fine for short data. However, if data becomes longer we should be able to display it over multiple lines. Related: SYS#4466 Change-Id: Id553df7c579bd648cb724fb1bbf906d9b50a357e --- utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/utils.py b/utils.py index 15db411..2562f6c 100644 --- a/utils.py +++ b/utils.py @@ -24,12 +24,22 @@ along with this program. If not, see . """ # Convert list to an printable ascii hex string -def hexdump(array): - if array: - return ''.join('{:02x}'.format(x) for x in array) - else: +def hexdump(array, multilne = False, width = 30, prefix = " "): + + if array == None: return "(no data)" + if multilne: + result = "" + for i in range(0, len(array), width): + buf = array[i:i + width] + result += prefix + result += ''.join('{:02x}'.format(x) for x in buf) + result += "\n" + return result + else: + return ''.join('{:02x}'.format(x) for x in array) + # Convert ascii string with decimal numbers to numeric ascii-code list def ascii_to_list(string):