Created
January 24, 2020 14:22
-
-
Save mgeeky/6a820023789cdd87e16d789def6892af to your computer and use it in GitHub Desktop.
Straightforward python's binary file into C hexstring conversion utility
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/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