Created
September 25, 2020 20:35
-
-
Save invisiblethreat/d5c281ed79ab7bad796f58109872e0d5 to your computer and use it in GitHub Desktop.
Wireshark hex stream to Go byte slice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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