Click here to Skip to main content
15,867,756 members
Articles / Desktop Programming / MFC
Article

Self-Extracting File Framework

Rate me:
Please Sign up or sign in to vote.
4.55/5 (5 votes)
7 May 2001 111.3K   1.6K   37   15
An article about creating Self-Extracting files with integrated compression

Introduction

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:

sfxLoader.exe

LOADERHEADER

StartModule

User Data

As you can see, there is an executable (sfxLoader.exe) with some appended data.

sfxLoader

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 LoaderPriv.h.

Compression: The compression has left in charge with the well-known zlib.

StartModule

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.

User Data

Here you can put any data that makes sense to the StartModule, since the StartModule will process this data.

LOADERHEADER

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

The framework for creating sfx consists mostly in the class CSFXFileCreator.

The steps for creating a sfx are:

  1. Create your own class derived from CSFXFileCreator and override the AppendStartModule and AppendUserData.
  2. Call CSFXFileCreator::Create.
  3. Call CSFXFileCreator::Close.

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

  1. Download and extract the code from this article to 'c:\sfx'
  2. Download and extract the ZLib to the directory 'c:\sfx\ZLib'
  3. Open and Build the following projects from the Loader workspace ('c:\sfx\Loader\Loader.dsw'):
    • Loader
    • StartModule
    • Compress
    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.
  4. Run the 'c:\sfx\bin\Compress.exe' and you will get a sample sfx file called MySFXFile.exe in the directory 'c:\sfx\bin'

License

  1. You must mention my name in your application documentation/help box, something like, Portions © 2000 by Rui Godinho Lopes <ruiglopes@yahoo.com>.
  2. I would appreciate an email letting me know that you are using this code.
  3. 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.
  4. You cannot sell this code. This is free software.
  5. 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 Godinho Lopes

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Praisethank you Pin
steppeman10-Feb-16 7:18
steppeman10-Feb-16 7:18 
GeneralAppending files Pin
kementeus26-Nov-06 18:24
kementeus26-Nov-06 18:24 
So, let me try to understand, I can append files at the end of the sfx but in the "runtime" the sfx file would only execute the loader part? (I guess it would "extract" the loader and execute it.
So if I append another set of files at the end, I would need to create a loader that would extract those files?
GeneralVC++ 2005 and zlib-1.2.3 problems Pin
Prof. Nimnul20-Jul-06 3:57
Prof. Nimnul20-Jul-06 3:57 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems Pin
kementeus24-Nov-06 14:05
kementeus24-Nov-06 14:05 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems Pin
Prof. Nimnul25-Nov-06 3:24
Prof. Nimnul25-Nov-06 3:24 
GeneralZLib source Pin
BobDonjacour4-Mar-05 4:58
BobDonjacour4-Mar-05 4:58 
GeneralRe: ZLib source Pin
BobDonjacour4-Mar-05 5:14
BobDonjacour4-Mar-05 5:14 
GeneralRe: ZLib source Pin
Prof. Nimnul20-Jul-06 4:02
Prof. Nimnul20-Jul-06 4:02 
Questionextract to memory? Pin
Rogerio Silva20-Apr-04 17:14
Rogerio Silva20-Apr-04 17:14 
Generalself extracting exe Pin
Member 43933716-Jun-03 0:02
Member 43933716-Jun-03 0:02 
GeneralRe: self extracting exe Pin
Rui Lopes16-Jun-03 2:54
Rui Lopes16-Jun-03 2:54 
Questionappend user data....? Pin
13-Jan-02 6:41
suss13-Jan-02 6:41 
QuestionDLLs ? Pin
8-May-01 1:55
suss8-May-01 1:55 
AnswerRe: DLLs ? Pin
Rui Lopes17-Jun-01 11:10
Rui Lopes17-Jun-01 11:10 
GeneralCool Pin
olliman11-Jul-00 5:55
olliman11-Jul-00 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.