Browse Source

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
for/master/ret
Philipp Maier 2 years ago
parent
commit
08623baa4a
  1. 18
      utils.py

18
utils.py

@ -24,12 +24,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# 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):

Loading…
Cancel
Save