I need an idea how to make application which will be able to patch itself, to change a few variables in data or code section,
and to save those changes.

Thank you
Posted on 2002-02-08 17:18:37 by dJed_mRaz
If somebody think that i want to write virii or something like this that is not a case. I just want to save a few status flags without creating an external data file.
Posted on 2002-02-08 17:25:16 by dJed_mRaz
Never fear,

there are legitimate uses for self modifying code. There is an example in the MASM32 examples that does this by one technique. The basics of SMC is building the EXE with the .CODE section writable which is a build option.

Once this is done, you can write changes to the code section but be careful, the offsets are hard coded in by the assembler and you will have to know what you are doing with jumps and variable reference.


Posted on 2002-02-08 17:49:51 by hutch--
I check SMC code, but how can i save those changes to my HD. This example just show how to modify code section in run time, but real question is how to write those changes permanent.
Posted on 2002-02-08 18:07:14 by dJed_mRaz
Normally an application cannot change its own disk image as it only has read access to the disk file while it is running. I cannot think of an easy way to do what you are after, its the same problem as a file that needs to delete itself, the OS will not allow the access.


Posted on 2002-02-08 18:16:41 by hutch--
The Only way i can think of doing this would involve creating 2 temporary external files. After your file has modified itself it could save the changed copy and then create a batch file that will delete the origonal and replace it with the changed one then the batch file would delete itself. The problem with this is that saved file would be a copy of the file after it has been loaded into memory...
Posted on 2002-02-08 21:28:55 by Quantum
That seems like a lot of trouble just to save some values.... why don't you use the registry instead?
Posted on 2002-02-09 04:22:45 by sluggy

in elicz.cjb.net, there's a dll that allow the process delete itself (and probably self-modify).

Posted on 2002-02-09 10:45:02 by ancev

That seems like a lot of trouble just to save some values.... why don't you use the registry instead?
because you can't easily transfer the values you saved in the registry to another computer. for example, if i have a cool little app and i wanna give it to my friend, it's so much easier to just copy one exe file than exporting the registry key, copy the .reg along with the .exe, then ask him to import it into his registry...
Posted on 2002-02-10 20:15:52 by cynix

My own approach to this problem of not wanting to write to the registry and keeping a program portable across windows versions without having a seperate INI file is a seperate setings editor that writes directly to the EXE file. You have to set up where you write the data but the rest is simple.

All you have to work out is the offset to read it from when the app is running. Value of hInstance + the offset you wrote the data to if its in the DOS header.


Posted on 2002-02-11 00:35:27 by hutch--
I would like to thank you all for your help.
This forum is great place.
Posted on 2002-02-11 10:46:21 by dJed_mRaz