Last active
October 2, 2016 10:09
-
-
Save kostyll/6b9581413a804b5b228713298c771f23 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python | |
| import os | |
| def chunks(l, n): | |
| for i in xrange(0, len(l), n): | |
| yield l[i:i+n] | |
| try: | |
| file_to_open = os.sys.argv[1] | |
| except IndexError: | |
| print "Have to type file name for dumping to string" | |
| print 'echo "char data[] = $(python pack_file_to_char_array.py item.exe )"' | |
| print """ | |
| char data[] = { | |
| '\\x23', '\\x0a', '\\x23', '\\x0a', '\\x23', '\\x20', '\\x43', '\\x75' | |
| '\\x73', '\\x74', '\\x6f', '\\x6d', '\\x20', '\\x6d', '\\x65', '\\x74' | |
| '\\x61', '\\x73', '\\x70', '\\x6c', '\\x6f', '\\x69', '\\x74', '\\x20' | |
| '\\x65', '\\x78', '\\x70', '\\x6c', '\\x6f', '\\x69', '\\x74 | |
| .... | |
| """ | |
| os.sys.exit(1) | |
| if os.path.isfile(file_to_open): | |
| try: | |
| data = open(file_to_open, 'rb').read() | |
| except Exception, e: | |
| print "Exception!: %s " % str(e) | |
| os.sys.exit(1) | |
| alignment_index = 0 | |
| l = len(data) | |
| bytes_in_string = 8 | |
| for string_to_print_data in chunks(data, bytes_in_string): | |
| print " " + ", ".join(map(lambda x: "0x{0:0>2}".format(hex(ord(x))[2:]), string_to_print_data))+"," | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment