[ back to Tom 7 Radar ]

p
e
r
s
o
n
a
l
Does anybody know... (04 Oct 2003 at 17:13)
Does anybody know how to get an executable to overwrite itself in Windows 98? I can't unlink (works in linux) the exe, or rename it (works in Windows 2000/XP), or fopen it for writing. I need this so that Escape can upgrade itself from the internet.
c
o
m
m
e
n
t
Adam (lynx.auton.cs.cmu.edu) – 10.04.03 18:39:39
You have to hack it. If your executable is "e.exe", then:

1. Download with a different name. (say "e-prime.exe")

2. Run e-prime.exe.

3. Quit the original, thus unlocking the file, all the while having e-prime.exe wait patiently for this to happen.

4. Have e-prime.exe change around e.exe.

5. Load e.exe, and (optionally) wait for eprime.exe to quit to delete it from e.exe.



For Windows 2000/XP, you have the handy <a href="http://msdn.microsoft.com/library/en-us/fileio/base/replacefile.asp?frame=true">ReplaceFile</a> function there for you.
c
o
m
m
e
n
t
Adam (lynx.auton.cs.cmu.edu) – 10.04.03 18:39:58
And I guess links don't work.
c
o
m
m
e
n
t
Anonymous (lynx.auton.cs.cmu.edu) – 10.04.03 18:40:27
And maybe it should save my name, at least for this session, instead of going back to "Anonymous".
c
o
m
m
e
n
t
Tom 7 (h-66-167-9-120.phlapafg.dynamic.covad.net) – 10.05.03 12:00:38
Yeah, I was hoping I wouldn't have to do something like that ... ;)

Adding cookies for the names should be pretty easy, I'll put that in the queue.
c
o
m
m
e
n
t
Tom 7 (h-66-167-9-120.phlapafg.dynamic.covad.net) – 10.05.03 22:48:41
OK, well, I did it, and it was a super pain in the ass, but it works on 2000 and 98 now.

By the way, if you want for some really confusing debugging, just pass a std::string in the ... part of a call to spawnl or execl on windoes!
c
o
m
m
e
n
t
Hock (res211.mesls.org) – 10.05.03 23:01:21
Tom, you're not only using the bastard language C++, but you're writing self-modifying code? What happened to you ?!?!?!
c
o
m
m
e
n
t
Tom 7 (h-66-167-9-120.phlapafg.dynamic.covad.net) – 10.06.03 10:21:32
Ha ha, it's not self-modifying code. It's just an "auto-update" feature for Escape, where it downloads a new version of itself and starts that. I guess that's self-modifying, in a sense, but not in a serious sense.

Yeah, C++ does suck a lot. But right now there's no good way to make standalone SDL applications on windows other than to use C++. (The ML port is old, although that guy is working on a new version that may be reasonable!)

Also, I realized that I also need to do this for all of the in-use DLLs. That's going to be even trickier...
c
o
m
m
e
n
t
FARINA00 (213.255.104.225) – 10.07.03 13:59:05
Uhm, I would just attach at the end of the main executable, another little executable whose task is to delete the first one.

Once you run the first, it detaches the second one, runs it with it's own full filename as parameter, and closes. This second executable gets the parameter, and deletes the specified file (this being the first executable).

This, if I understood your problem.


c
o
m
m
e
n
t
Tom 7 (h-66-167-9-120.phlapafg.dynamic.covad.net) – 10.07.03 21:13:32
That's basically what I'm doing, but I just have a standard command line argument for replacing and deleting files. I was hoping that there'd be a cleaner way, because it's a total non-issue in linux...
c
o
m
m
e
n
t
FARINA00 (213.255.104.225) – 10.08.03 03:54:26
Then I wonder why self-modifying viruses aren't spreading through the penguin's flesh right now! :)
c
o
m
m
e
n
t
Tom 7 (h-66-167-9-120.phlapafg.dynamic.covad.net) – 10.08.03 09:49:48

- File permissions
- Differing versions
- Low market penetrations

Some day, they will, at least if they keep programming in C!
p
o
s
t

a

c
o
m
m
e
n
t
Please enter the code, unless you are spammer!!
[ Tom 7 Radar  •  Tom 7 on Google+  •  on Twitter  •  on Facebook ]