Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openin exe binary files and editing

I'm working on a project to automatize a process. My task is to open an .exe file and edit the binary. I was researching for a possible solution to this task without any success. Does anyone know if there is a Python library or java class that can help? Or any other solution to edit an exe file.

like image 738
user2130898 Avatar asked Jan 13 '23 04:01

user2130898


2 Answers

If you just need to edit the binary data contained in the file, then it is just a matter of opening the file as binary and seeking/reading/writing as you would any other binary file.

See the Python docs about reading and writing files: Reading and Writing Files

You'll do something like:

f = open('filename.exe', 'r+b') //'r+b' means read and write binary

Then proceed to seek through the file, read and write where needed.

like image 118
bojangler Avatar answered Jan 16 '23 18:01

bojangler


Depending on your needs, you could treat the .exe file as an "ordinary" binary file as suggested in an other answer.

In other hand, if you need to "decode" Windows portable executable files (accessing header, copying sections), there are some dedicated Python module specialized in that task. I don't know which work the best or has the most features, but you should take a look for example to:

  • pefile
  • PELP
like image 34
Sylvain Leroux Avatar answered Jan 16 '23 18:01

Sylvain Leroux