python - How to run an executable file contained in a text file(hex of exe) -


i have txt file containing hex of exe. read file in python, failed run .exe file. kind of appriciated...

thanx

import binascii  def getexefile():     file1=input("enter exe file name(path):")     open(file1, 'rb') f:         content1 = f.read()         bucket1=open("f1.txt", 'w')         bucket1.write(str(binascii.hexlify(content1)))         print(binascii .hexlify(content1))         bucket1.close() def getnonexefile():     file2=input("enter non-exe file name(path):")     open(file2, 'rb') f:         content2 = f.read()         bucket2=open("f2.txt", 'w')         bucket2.write(str(binascii.hexlify(content2)))         print(binascii .hexlify(content2))         bucket2.close() getexefile() getnonexefile() print("end") 

dump temporary file; change it's permissions it's executable , run in subprocess

example:

from os import chown subprocess import check_call tempfile import namedtemporaryfile  namedtemporaryfile(delete=false) f:     f.write(get_hex_from_file("mydata.dat"))  chown(f.name, 0755) check_call(f.name) 

of course i'm making assumption here doing on kind of unix machine , "exe" in case means kind of elf/a.out/coff executable! -- nevertheless; same principles , code (with tweaking) work on other paltforms; e.g: windows.

see:


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -