views:

101

answers:

5

There are many programs out there that will allow you to pack a few files together and generate an executable that has the necessary code to extract them. Somehow, those files are residing inside the executable. I am interested in doing the same thing; how is this done?

FYI, I'm interested primarily in Windows .exe files, if it makes a difference.

+1  A: 

You could probably save a file/files in a resource, compile it into the exe then use some code in the exe to extract it out to a file.

ie:

http://www.codeproject.com/KB/winsdk/binaryresources.aspx

John Boker
+2  A: 

Look at this: Article

tr4656
Worth highlighting in the article is the UpdateResource() function in the Windows API.
Phil
A: 

There are also products like pkzip and winzip which do it for you. If your time is worth anything, those would be more efficient.

wallyk
+1  A: 

Self extracting .exe files are usually archive files (zip, rar, tar, etc) concatenated together with a small program that does the extraction then executes the program that was extracted from the archive.

A really sophisticated one could extract the archive into memory and then jump to the extracted code and run it, but back in the old days, that sort of thing was easier to do.

If you wanted to write your own in Windows, you would create a small console application that did the extraction, and you would include the 'real' program in the console programs' resources.

John Knoeller
Are these archive files just appended to the 'real' program that does the extraction?
Phil
In the olden days yes, now I think you get into trouble with virus scanners if your archive isn't accounted for in the exe header.
John Knoeller
A: 

UPX is a well known packer for Windows .EXE which can be found here on WikiPedia. And here is the main site on sourceforge for UPX.

Hope this helps, Best regards, Tom.

tommieb75