Skip to content

Commit

Permalink
Cleanup of hexdump function.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jan 26, 2018
1 parent fd27c95 commit fe81fdc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ def as_hexdump(self):
"""

non_dot_characters = set(string.printable)
non_dot_characters -= set(string.whitespace)
non_dot_characters |= set(' ')

def format_line(address, data):
"""`data` is a list of integers and None for unused elements.
Expand All @@ -885,10 +889,6 @@ def format_line(address, data):
ascii = ''

for byte in data:
non_dot_characters = set(string.printable)
non_dot_characters -= set(string.whitespace)
non_dot_characters |= set(' ')

if byte is None:
ascii += ' '
elif chr(byte) in non_dot_characters:
Expand All @@ -911,8 +911,10 @@ def format_line(address, data):
elif address > line_address + 16:
line_data += [None] * (16 - len(line_data))
lines.append(format_line(line_address, line_data))

if address > line_address + 32:
lines.append('...')

line_address = address - (address % 16)
line_data = []

Expand All @@ -922,7 +924,7 @@ def format_line(address, data):
if len(data) > line_left:
line_data += [byte for byte in data[0:line_left]]
lines.append(format_line(line_address, line_data))
line_address = line_address + 16
line_address += 16
line_data = [byte for byte in data[line_left:]]
elif len(data) == line_left:
line_data += [byte for byte in data]
Expand Down

0 comments on commit fe81fdc

Please sign in to comment.