Thursday, 27 November 2014

python - print hex string into binary file

#!/usr/local/bin/python3
import binascii

file = open("xxx.exe", "wb")

with open("xxx.txt", "r") as f:
    i = 0
    byte = f.read(2)
    while byte != "" and len(byte) == 2:
        try:
            file.write(binascii.unhexlify(byte))
        except:
            print(byte)
            print(i)
            print(len(byte))
        byte = f.read(2)
        byte = byte.rstrip()
        i = i + 2
f.close()

file.close()

No comments:

Post a Comment