Last active
March 28, 2022 13:50
-
-
Save whudson/ff3834514a8c5804d13d68a197897910 to your computer and use it in GitHub Desktop.
Python3 - printing a bytestring as escaped bytes
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
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