How can I write hex to a binary file? Ie the task is this: there is a hex string of a binary file, I need to write this hex string into an .exe file using a script.

Type this line:

4d5a90000300000004000000ffff0000b800000000000000000000000000000000000000000000000000000000000000000000000000000000100e1fba0e00b409cd21b8014ccd215468

Closed due to the fact that the essence of the question is not clear to the participants of freim , gil9red , LFC , aleksandr barakin , 0xdb on 29 March at 15:25 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    hex_str = '4d5a90000300000004000000ffff ... 0000100000e1fba0e00b409cd21b8014ccd215468' with open('some.exe', wb) as fh: fh.write(bytes.fromhex(hex_str))