Steve Kobes
2003-10-14 09:04:25 UTC
I want my program to modify its own EXE file. I do not want to start
a separate EXE that waits for the first one to quit, then modifies it.
CreateFile fails with a sharing violation when I try to open the EXE
with FILE_WRITE_DATA access. So, we might reasonably conclude that my
task is impossible. BUT...
I wrote a Hello World program, and while the message box was on the
screen, I opened its EXE as a binary file in Visual C++ 6 (no
workspace open), and I was able to edit it! After I hit Save, a file
called ~VC90.tmp appeared in the same folder. Its contents match
those of the EXE before the change, and I'm unable to delete it until
I close the message box, suggesting that the VC++ editor somehow made
the system think my Hello World process had come from this .tmp file.
But the EXE itself is changed!
How'd they do that?
a separate EXE that waits for the first one to quit, then modifies it.
CreateFile fails with a sharing violation when I try to open the EXE
with FILE_WRITE_DATA access. So, we might reasonably conclude that my
task is impossible. BUT...
I wrote a Hello World program, and while the message box was on the
screen, I opened its EXE as a binary file in Visual C++ 6 (no
workspace open), and I was able to edit it! After I hit Save, a file
called ~VC90.tmp appeared in the same folder. Its contents match
those of the EXE before the change, and I'm unable to delete it until
I close the message box, suggesting that the VC++ editor somehow made
the system think my Hello World process had come from this .tmp file.
But the EXE itself is changed!
How'd they do that?