Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import string
- import binascii
- from textwrap import TextWrapper
- filename ="temp.zip"
- outFile = "test.zip"
- sampleDataHeader = 'SampleDATA = ("'
- sampleDataEnd = '")'
- binaryData = open(filename, "rb").read()
- hexData = binascii.hexlify(binaryData)
- hexStrFile=""
- sampleData = ""
- tw = TextWrapper()
- tw.width = 60
- def insertNewlines(text, lineLength):
- if len(text) <= lineLength:
- return text
- else:
- return text[:lineLength] + '\n' + insertNewlines(text[lineLength:], lineLength)
- for x in range(0, len(hexData), 2):
- hexStr = hexData[x:x+2]
- hexStr = "\\x"+hexStr
- hexStrFile+=hexStr
- sampleData = '"\n'.join(tw.wrap(hexStrFile))
- print sampleData
- out = open(outFile,'wb')
- out.write(sampleDataHeader+sampleData+sampleDataEnd)
- out.close()
- #hexStr=hexStr+( hex( int (hexData[x:x+2], 16 ) ) )
- #hexStr = format(int(hexStr, 16), 'x')
- #hexStr=hexStr.replace("0x", "\\x")
- #hexStrFile+=hexStr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement