0

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

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you but i am trying to access and change the exe directly without recompile
0

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.

1 Comment

i guess i am trying to write a program in python that will change the exe file in an addresses that i will give him in order to change the original exe parameters
0

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.