简体   繁体   中英

edit exe file script in python

i am trying to build a config script in python to change another exe config.. lets say i have the following program:

#include<stdio.h>
#include "windows.h"

int times=5;
int sleep=1000;

main() {
    int i;
    for (i=times;i>0;i--) {
        printf("Hello i is %d \n",i);
        Sleep(sleep);
    }
}

and i have a compiled exe file called hello.exe, i want to make a python script that will work on the exe file and change the time and sleep variables... where can i read how to do it in python?? thanks

You will have to disassemble the binary of the compiled code, locate the values in the binary, and than using python to change the binary. But I am sure it is not what you want to do. A simpler approach would be to put the configurable values in a header file, include it into your c code, and then let python script just generate the header and invoke compiler to regenerate the exe.

You will have to write a program that is similar to a hex editor finds and changes the appropriate value. What exactly are you trying to do? If you are making the program just make a configuration file that the program reads from.

i found an easier way which may help others in the future... because the original program i want to change is in c code, i have created an header file with all the variables as char array of size 100 which made it very easy to find them after in hex editor and change them with mmap.mmap function. later in the source file i alter the char array for my program needs, for example in the header i do:

char timer[100]="10000";

and it will be easy to find later on with hexeditor...

and in the source file of the program i use the atoi function to make it as int for my use

I'm sorry, but it is not a good idea to change an exe after compiling just to change some parameters. Why don't you make your program to use a configuration file that contains the parameters that you want to change later? By doing this, you don't have to worry about changing your exes (and corrupting them), and changing behavior of your program will be much easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM