Skip to main content
GameDev.net gamedev.net
🔒 Locked

.exe inside a .exe

Started by quant Jul 7, 2004 at 10:02 AM 1 replies 850+ views
Original Post
quant
quant
Is it possible to store a .exe withing a .exe, similar to how resource files work, but with executable code. How would i run the code?
-keyboard
ApochPiQ
ApochPiQ
It's possible, and just a little bit tricky. You can basically stick anything you want on the end of an EXE file if you do it right. I usually pad the first EXE with null characters (byte 0) until the file is an even multiple of 24KB. After the padding I add the second EXE. In the first EXE's code, I will know how many multiples of 24KB the padding is, so I can hardcode the starting position of the second EXE and extract the file with normal file I/O routines.

The easiest way to run the code would be to extract the second EXE into a temporary file, and run that will ShellExecute(). When it's done you can just delete the temp file.
Nemesis2k2
Nemesis2k2
Well, you could store an exe as a resource, which you could then extract and execute (you would have to actually write it back to a file). The exe would just be a standalone program though, not part of your program.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.