|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.|
|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.
|And I guess links don't work.|
|And maybe it should save my name, at least for this session, instead of going back to "Anonymous".|
|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.
|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!
|Tom, you're not only using the bastard language C++, but you're writing self-modifying code? What happened to you ?!?!?!|
|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...
|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.
|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...|
|Then I wonder why self-modifying viruses aren't spreading through the penguin's flesh right now! :)|
- File permissions
- Differing versions
- Low market penetrations
Some day, they will, at least if they keep programming in C!