added over.misc.raw_to_hex and over.misc.hex_to_raw
This commit is contained in:
parent
73132dad6f
commit
0d1794d4b6
1 changed files with 28 additions and 0 deletions
28
over/misc.py
28
over/misc.py
|
@ -191,3 +191,31 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show
|
||||||
if not output:
|
if not output:
|
||||||
output_io.seek(0)
|
output_io.seek(0)
|
||||||
return output_io.read()
|
return output_io.read()
|
||||||
|
|
||||||
|
# --------------------------------------------------
|
||||||
|
|
||||||
|
def raw_to_hex(raw, spaces=True):
|
||||||
|
"""
|
||||||
|
Converts a bytearray (or bytes) into its textual hexadecimal representation.
|
||||||
|
"""
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
|
for o in raw:
|
||||||
|
output.append(hex(o)[2:].zfill(2))
|
||||||
|
|
||||||
|
return (" " if spaces else "").join(output)
|
||||||
|
|
||||||
|
def hex_to_raw(text):
|
||||||
|
"""
|
||||||
|
Converts a hexadecimal representation of a byte array into a bytearray.
|
||||||
|
"""
|
||||||
|
|
||||||
|
output = []
|
||||||
|
|
||||||
|
text = text.replace(" ", "")
|
||||||
|
|
||||||
|
for i in range(len(text)//2):
|
||||||
|
output.append(int(text[2*i:2*i+2], 16))
|
||||||
|
|
||||||
|
return bytearray(output)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue