Skip to content

Instantly share code, notes, and snippets.

@invisiblethreat
Created September 25, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invisiblethreat/d5c281ed79ab7bad796f58109872e0d5 to your computer and use it in GitHub Desktop.
Save invisiblethreat/d5c281ed79ab7bad796f58109872e0d5 to your computer and use it in GitHub Desktop.
Wireshark hex stream to Go byte slice
#!/usr/bin/env python3
import sys
if not sys.stdin.isatty():
raw = sys.stdin.readline()
raw = raw.rstrip()
else:
raw = sys.argv[1]
if len(raw) % 2 != 0:
print("Invalid hex sequence")
sys.exit(1)
convert = ""
count = 0
for double in (raw[i:i+2] for i in range(0, len(raw), 2)):
convert += "0x{}, ".format(double)
count += 1
if count % 16 == 0:
convert += "\n"
print("var rawBytes = []byte{{\n{}}}".format(convert[:-2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment