hi, say i've got this piece of code: .DATA cap db 65,66,67,0 .CODE start: invoke MessageBox,NULL,addr cap,addr cap,MB_OK inc byte ptr invoke ExitProcess,NULL END start ok, when i first start the prog it should output ABC after restart it should give me a DBC and so on but i've got no idea on how to realize this... how can i mark the data section as writable? (and how write i to it?) thank you in advise...
Posted on 2000-12-27 09:12:00 by drcmda
A couple of points... 1) Your program, as written, will produce a message box with "ABC" and then change the "A" to a "B". Not "D" as you indicated. - Big deal, you can fix that. 2) Your program modifies itself in memory. If you execute it a second time, the OS loads a new copy from a storage device(Hard drive, floppy drive,etc.) into memory. It doesn't re-use the one in memory. I am assuming, of course, that we aren't talking about re-entrant code. Your code snippet looks straight forward. You would need to open your .exe like a data file and re-write the entire file verbatum, changing only the byte at the right offset from the start of the file. You need to understand (or just remember) the difference between a program stored on media and one executing in memory. Change the one in memory and lose it as soon as the machine is turned off, or change the one on the HD and it is changed permanently (Until you change it again nyway). Good luck...
Posted on 2000-12-27 10:26:00 by David_
? ok my fault (B not D)... ? yeah, i know That this piece of code does not that what i want, thats why i opened a thread! ? i know that i can access my exe via open api's but i wanted to know if there are other ways to do that (mark data sec as writable in the linking process)...
Posted on 2000-12-27 10:54:00 by drcmda
"? i know that i can access my exe via open api's but i wanted to know if there are other ways to do that (mark data sec as writable in the linking process)..." Your .data section is already marked read/write, otherwise you couldn't use it to store dymanic values, all it would hold are constants. Here is what you are missing: When a program is compiled, it creates a file. When that program is run, the data in that file is COPPIED to memory. If you change something in .data at run time, you are changing the copy in memory, not the .exe itself. If you wish to save other data, I suggest you find some other place then your .exe to store it. Perhaps check out the WriteProfileString and GetProfileString API's would be more helpful to you. AND... if you are sitting there huffing that I didn't get your point, that you truly wish to change your own .exe, well, I'm not sure that is possible. The file may well be locked (a simple test I just performed confirms this) so you cannot change the open .exe file. You could make program2.exe be able to change program1.exe. This could be useful to you in this way: When program1.exe is terminating, it shells program2.exe. Then program2 checks that program1 is truly not running, then modifies the program1.exe file.
Posted on 2000-12-27 11:43:00 by Ernie
ok thank you... i thought i can write to my exe when i use some special linker options... i know that there are plenty other ways but i'm very lazy ;) best regards
Posted on 2000-12-27 11:54:00 by drcmda