Skip to content

Instantly share code, notes, and snippets.

@MrSuicideParrot
Last active July 9, 2019 11:40
Show Gist options
  • Save MrSuicideParrot/b9dfdb97afd2f8105693b2622b25cfd9 to your computer and use it in GitHub Desktop.
Save MrSuicideParrot/b9dfdb97afd2f8105693b2622b25cfd9 to your computer and use it in GitHub Desktop.
Convert a packed byte string to an int array in python2
import struct
def pack_hex_to_int_arr(hex_str):
arr = []
for i in hex_str:
arr.append(struct.unpack("B", i)[0])
return arr
if __name__ == "__main__":
test = "\xfcg\xb2I\x00\x00\x00\x00s\x0e@\x00\x00\x00\x00\x00\x18 `\x00\x00\x00\x00\x00\x8c\x06@\x00\x00\x00\x00\x00w\x0c@\x00\x00\x00\x00\x00"
result = [252, 103, 178, 73, 0, 0, 0, 0, 115, 14, 64, 0, 0, 0, 0, 0, 24, 32, 96, 0, 0, 0, 0, 0, 140, 6, 64, 0, 0, 0, 0, 0, 119, 12, 64, 0, 0, 0, 0, 0]
print(pack_hex_to_int_arr(test) == result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment