Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Created January 24, 2020 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgeeky/6a820023789cdd87e16d789def6892af to your computer and use it in GitHub Desktop.
Save mgeeky/6a820023789cdd87e16d789def6892af to your computer and use it in GitHub Desktop.
Straightforward python's binary file into C hexstring conversion utility
#!/usr/bin/python3
import sys
def main(argv):
if len(argv) != 2:
print('Usag: ./bin2c.py <shellcodeFile>')
return False
with open(argv[1], 'rb') as f:
b = f.read()
i = 0
out = 'unsigned char buf[] =\n'
for foo in b:
if i > 0 and i % 16 == 0:
out += '\n'
i += 1
out += '\\x{:02x}'.format(foo)
i = 0
for line in out.split('\n'):
if i == 0:
print(line)
else:
print('"{}"'.format(line))
i += 1
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment