Skip to content

Commit

Permalink
upload code
Browse files Browse the repository at this point in the history
  • Loading branch information
dtlnor committed Jan 10, 2023
1 parent ee683b9 commit 6f472ce
Show file tree
Hide file tree
Showing 6 changed files with 1,148 additions and 0 deletions.
28 changes: 28 additions & 0 deletions HexTool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import io
import struct


def seek_align_up(filestream: io.BufferedReader, align: int) -> int | None:
"""pad to align"""
padSize = filestream.tell() % align
padding, = struct.unpack(f"{padSize}s", filestream.read(padSize))
assert all([x == 0 for x in padding]), "padding value should be zero"
return padding


def printHexView(bytestream: bytearray | bytes, width = 32):
"""print hex bytes similar in hex editor, for debug usage"""
view = ""
digit = len(str(len(bytestream)))
for i, b in enumerate(bytestream):
sep = ' '
pref = ''
if i % width == 0:
pref = ("{0:0"+str(digit)+"d}").format(i) + ": "
elif i % width == width - 1:
sep = '\n'
elif i % 4 == 4 - 1:
sep = '|'
view = view + pref + f"{b:02X}" + sep
print(view)
return view
Loading

0 comments on commit 6f472ce

Please sign in to comment.