This article is about making self-extracting files (lets call them "sfx"), or more precisely, making
the framework for creating sfx.
For a start, let's look at the physical anatomy of a sfx:
As you can see, there is an executable (sfxLoader.exe) with some appended data.
This is the soul of a sfx, a regular Win32 portable executable file that has the responsibility of managing
a compressed start module.
For making this I established some goals:
Small footprint: The goal was to make the small possible sfxLoader, and the end the result was a sfxLoader
of about 20 KB. This is in part because of some techniques demonstrated in other articles, namely:
I have also made a stub. If you want more information on this, start your reading with the file
Compression: The compression has left in charge with the well-known zlib.
A StartModule is a piece of software that can be either an executable (EXE) or a dynamic link library (DLL).
The StartModule has the responsibility of managing the User Data, for example this can be a setup program.
Here you can put any data that makes sense to the StartModule, since the StartModule will process this data.
This structure contains, among other things, the size and offset of the start module. You should look at the
source code for more details.
The framework for creating sfx consists mostly in the class
The steps for creating a sfx are:
- Create your own class derived from
CSFXFileCreator and override the
You can find the interface of this in the header
sfx.h. Also, there are some helper functions and
classes in the header
sfx_helpers.h. For a real example, take a look at the sample project Compress.
Installing and Building
- Download and extract the code from this article to 'c:\sfx'
- Download and extract the ZLib to the directory 'c:\sfx\ZLib'
- Open and Build the following projects from the Loader workspace ('c:\sfx\Loader\Loader.dsw'):
At the end, you will get in the bin directory ('c:\sfx\bin') the files, sfxLoader.e32, StartModule.dll and Compress.exe
NOTE1: You will get some 'LINK : warning LNK4078: multiple ".data" ....', just ignore them.
NOTE2: If you want to build a EXE start module you have to define '_STARTMODULE_IS_EXE' in the Loader.h file, and
rebuild all projects in workspace.
- Run the 'c:\sfx\bin\Compress.exe' and you will get a sample sfx file called MySFXFile.exe in the directory
- You must mention my name in your application documentation/help box, something like, Portions © 2000
by Rui Godinho Lopes <firstname.lastname@example.org>.
- I would appreciate an email letting me know that you are using this code.
- I cannot be held responsible of any kind of data lost caused directly or indirectly by the use of this code.
Use it at your own risk.
- You cannot sell this code. This is free software.
- If you use this code in a commercial application, you have to give me a copy of your product.
Don't forget, if you have constructive thoughts just email me! Rui