Creating self-extracting exes (coding)

Started by
11 comments, last by Hoser 20 years, 4 months ago
Does anyone know where I can find a tutorial on how to create self-extracting executables? I''m working on some encryption/decryption software and I would like to be able to create self-extracting (or self decrypting) executables. Googling only provided links to similar types of software... Any help would be appreciated.
Advertisement
Research PE headers.

You''ll need a small exe as a stub that handles the unpacking.
When I needed something like this, what I did was put every file that was to be extracted into the resource section of the exe.

I then wrote a function to find a specific file in the resource, lock it, get its size, and finally write the data to disk. You just compile a short program with the files in its resource and just call the extract function for every file in the resource .

If you wanted to do this automatically, you could use batch files to compile the res and exe, and then link them. You would also write a small scripting engine with LUA (not hard at all ) to script the extraction of the files.



I''m pretty sure the OP wants to make a program that will generate the self-extracting exe''s based on other files. This is significantly different than having a project that will produce one self-extracting exe based on the project settings.
Can still be done with scripting and a small compiler

quote:
I''m pretty sure the OP wants to make a program that will generate the self-extracting exe''s based on other files. This is significantly different than having a project that will produce one self-extracting exe based on the project settings.


This is exactly what I want to do.

downgraded - Thanks for the tip, I think this is what I''m after.
I''ve looked into the PE headers a little bit...and it doesn''t seem like an easy approach. How exactly would I go about creating a self extracting exe? I''m guessing that I would have to...
1) Create the small exe program which is capable of doing the extraction
2) Have a program which can modify the header of this small exe, and append the files (files to extract) to the exe.
3) Have the small exe read its own header to find the location of the extra data and extract?

Am I on the right track?

Is there a way to just add a resource to an exe after the fact? That would be an easier approach for me...

Any help is appreciated.
quote:Original post by Hoser
I''ve looked into the PE headers a little bit...and it doesn''t seem like an easy approach. How exactly would I go about creating a self extracting exe? I''m guessing that I would have to...
1) Create the small exe program which is capable of doing the extraction
2) Have a program which can modify the header of this small exe, and append the files (files to extract) to the exe.
3) Have the small exe read its own header to find the location of the extra data and extract?

Am I on the right track?

Is there a way to just add a resource to an exe after the fact? That would be an easier approach for me...

Any help is appreciated.


That sounds about right to me. Except you don''t have to modify the the header of the exe, you can just create a footer after you''d appended the extra data to your exe. Then it''s just matter of having the exe open it''s self as a binary input, seek the EOF minus the size of the footer then using the information contain in the footer to extract the extra data.
Something wrong with winzip here..?
quote:
Except you don''t have to modify the the header of the exe, you can just create a footer after you''d appended the extra data to your exe. Then it''s just matter of having the exe open it''s self as a binary input, seek the EOF minus the size of the footer then using the information contain in the footer to extract the extra data.


That''s the solution I had come up with. Anyone know off hand what windows function will give me the filename of the currently running exe?

quote:
Something wrong with winzip here..?


Yes. The application I''m working in is quite specialized...I need some custom software.

This topic is closed to new replies.

Advertisement