Click here to Skip to main content
Click here to Skip to main content
Go to top

Self-Extracting File Framework

, 7 May 2001
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Rui Lopes
Web Developer
Portugal Portugal
No Biography provided

Comments and Discussions

 
GeneralAppending files Pinmemberkementeus26-Nov-06 18:24 
GeneralVC++ 2005 and zlib-1.2.3 problems PinmemberProf. Nimnul20-Jul-06 3:57 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems Pinmemberkementeus24-Nov-06 14:05 
GeneralRe: VC++ 2005 and zlib-1.2.3 problems PinmemberProf. Nimnul25-Nov-06 3:24 
GeneralZLib source PinmemberBobDonjacour4-Mar-05 4:58 
GeneralRe: ZLib source PinmemberBobDonjacour4-Mar-05 5:14 
GeneralRe: ZLib source PinmemberProf. Nimnul20-Jul-06 4:02 
Questionextract to memory? PinmemberRogerio Silva20-Apr-04 17:14 
Is there a way to extract to memory and run directly?
Generalself extracting exe PinmemberMandan Misra16-Jun-03 0:02 
GeneralRe: self extracting exe PinmemberRui Godinho Lopes16-Jun-03 2:54 
Questionappend user data....? Pinmemberprgmaker13-Jan-02 6:41 
QuestionDLLs ? PinmemberAnonymous8-May-01 1:55 
AnswerRe: DLLs ? PinmemberRui Lopes17-Jun-01 11:10 
GeneralCool Pinsuss[ MoD ]11-Jul-00 5:55 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 8 May 2001
Article Copyright 2000 by Rui Lopes
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid