Skip to content

Instantly share code, notes, and snippets.

@whudson
Last active March 28, 2022 13:50
Show Gist options
  • Save whudson/ff3834514a8c5804d13d68a197897910 to your computer and use it in GitHub Desktop.
Save whudson/ff3834514a8c5804d13d68a197897910 to your computer and use it in GitHub Desktop.
Python3 - printing a bytestring as escaped bytes
payload = b'bytes'
pretty_payload = '\\x' + '\\x'.join("{0:0{1}x}".format(b, 2) for b in payload)
# the first 0 is the index of the bytes field
# the 0 after : is the fill character
# the {1} is our align width, from field 1 (align=2)
# x specifies lowercase hex format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment