Solved

Self extractor

Posted on 2001-08-05
41
181 Views
Last Modified: 2010-04-04
anyone knows how to bind 2 .exe together and then when being executed, it extracts the 2 files to 2 separate files.
0
Comment
Question by:creatorsss
  • 20
  • 17
  • 2
  • +2
41 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6353443
use pkzip2exe.exe

hope that helps
0
 
LVL 3

Expert Comment

by:andysalih
ID: 6353453
have a read of this thread,

http://www.naic.org/help/technote/zip.htm

cheers
Andy
0
 
LVL 17

Expert Comment

by:inthe
ID: 6353794
hi,
here is example to put another exe inside your exe:
(you can add more if you want more than one)

with notepad make a .rc file that looks like this:

TESTFILE  EXEFILE  C:\TEST.EXE

and save as myres.rc

compile myres.rc with brcc32 to get myres.res then make sure myres.res is in same dir as project.

then in unit do:

{$R *.DFM}
{$R MYRES.RES}

procedure ExtractRes(ResType, ResName, ResNewName : String);
    var
      Res : TResourceStream;
    begin
      Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
      Res.SavetoFile(ResNewName);
      Res.Free;
    end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ExtractRes('EXEFILE','TESTFILE','C:\TEST_EXE_FROM_RES.EXE');
ShellExecute(Form1.Handle,'open','c:\Test_exe_from_res.exe',nil,nil,SW_SHOWNORMAL);
end;


that will extract the exe to a file called C:\TEST_EXE_FROM_RES.EXE and execute it.

afterwards you can call DeleteFile('C:\TEST_EXE_FROM_RES.EXE') to delete it if you want to.

Regards Barry
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6354425
I guess you want to merge 2 exe's together and then when you run this composit program it should rebuild itself as 2 seperate exe's.... and neither of the 2 should have any remnants of the other?

This is easy.... look at the demos on my web page and you should be able to figure out how to do this.... If you have trouble maybe I can find the time to make you a demo that does exactly what you need :-)

http://delphi.does.it

look aspecially at the self modifying exe demo and the demo that extracts a file....

What you want to do is add the 2nd exe to the end of the first... then when the program runs it reads it's own image from disk and pulls off the 2nd exe and writes it to a new file...then the first exe rebuilds itself and dumps the excess data from it's end... you will wind up with 2 exe's... both containing nothing of the other :-)
0
 

Author Comment

by:creatorsss
ID: 6355365
gwena, I would appreciate it if you could make the demo for me thanks.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6356209
Hi creatorsss :-)

  Did I give a pretty good example of what you are trying to do? If not please give more exact details :-)
0
 

Author Comment

by:creatorsss
ID: 6358900
hey gwena, could you give me a working example of how to store the data at the end of the first file and then extract it all on 1 project. I have been to the website and downloaded all the projects but I'm not able to create the program I want. Please help thanks.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6359992
Hi creatorsss :-)

  OK.. to create a single exe that has another exe stuck onto it's end is not hard.. but to do it easily you need a simple utility that can add one file to another and insert a small string of demarcation data between them...otherwise you are left using dos commands to combine 3 files... File1.exe+demarcation.txt+File2.exe and that's such a pain :-)

  Then you need to modify the oncreate event for File1.exe so that it can modify itself when it is first run...it will need to pull off the File2.exe data and simply write it into the current dir... then re-write itself and wind up running in the current dir without file2.exe's data appended to it.... it needs to do all this without any need for the user to do anything... this is do-able but it may take a couple of days for me to find the time to make the demo :-) I am really busy with some less interesting chores this week :-(

So if you can hang on a bit I will get to it when I get a free hour or two :-)

Gwen...
0
 

Author Comment

by:creatorsss
ID: 6362673
I would really appreciate it thank you.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6370226
Hi creatorsss :-)
  I just did a little work on the code for you... hang in there a while longer... I have not forgotten about this :-)
0
 

Author Comment

by:creatorsss
ID: 6371232
ok thanks
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6378610
Hi again :-)
  I just wrote an oncreate routine that does what you want... you just paste it into your program and add ShellAPI to your uses clause and it will work...

I need to make a little utility to bundle the 2 exe's together though... you wouldn't want to do that by hand..it's a pain :-)

 The second file need not be an exe.. it can be any file type... here is a small demo exe I made so you can look at it... I will make the utility for you tomorrow I think...
Be sure and store a backup copy of this little exe because when you run it it will split in 2 and there's no going back... without a backup you would have to download it again to experiment further.... the first exe ends up still running and has no remnant of the 2nd exe left in it...

http://www.codearchive.com/~gac/demoexe1.exe

0
 

Author Comment

by:creatorsss
ID: 6380550
thank you.pls also send the link for the source code thanks
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6382984
Hi :-)

  I wrote a tiny (20kb) util for you so you can make those self-splitting files easily... it's on my site..here's the link
http://www.codearchive.com/~gac/File-Combiner.exe

Here's what you do to use it...

Choose the delphi exe that you want to add another file to...open it in delphi and make an OnCreate event handler for it's main form (Form1) ... now go and run my little file-combiner util and copy the source code from the window...then go paste it into your delphi code ..completely replacing the OnCreate event handler that was there....now add ShellAPI to the programs uses clause..you can now recompile this delphi app and save it... it will work as it did before you added the code...

Now to add the second file to the above modified deplhi exe just run the little util and select the modified file  as the first file...then select any other file as the 2nd file and click the combine files button.... that's it.. the newly created program that is saved as new.exe will split into the 2 original files when it is first run... you can rename new.exe to whatever name you like... this name will be used as the name of the original exe you modified above :-)

I only tied this twice so you better play with it awhile to be sure there are no bugs :-)

<G>wen


0
 

Author Comment

by:creatorsss
ID: 6396441
sorry but the site doesn't work......could resend? And also, could you please give me the source code for it
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6398625
Hi :-)
  Yes.. the server that had my web page on it crashed or something... they still have not been able to fix it.. if you give me your email address I will email the stuff to you... it's a tiny program that handles putting the files together... it has the source code for the oncreate event inside it... you just cut and paste it from a memo :-)

You can download the file-combiner from my temporary website if you like just go to http://delphi.does.it and look for the file-combiner link... here is the url of the file but it's on geocities so you need to be at the website...geo has disabled direct off-site downloading :-(

http://www.geocities.com/gacarpenter386/File-Combiner.zip

p.s. I can also get the source for the file-combiner.exe to you but you will not be able to compile it properly without installing a bunch of code and utils in your delphi compiler... well you can compile it and run it but it will end up over 300kb instead of the small 19kb ..
I'm a real nut for making small exe's and use a lot of tricks to get them tiny... just let me know if you want the source to the util... but you don't need it to make your extractor work... the tricks are all in the oncreate event code.. the util is just so you won't have to build the combined files packages by hand...

0
 

Author Comment

by:creatorsss
ID: 6400250
I have checked out your extractor test on your website and found it to be quite interesting...let me check it out and then get back to you ok.
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6401004
Hi :-)
  OK... I'm in no hurry :-)
0
 

Author Comment

by:creatorsss
ID: 6424809
OK....I have reviewed your code for the self extractor 2 demo. Correct me if I'm wrong but I think your code does this:
................
let your code be A and another file be B
A adds B to the end of file A and saves it as
C(a new file containing A and B).
C then checks whether it is different from A and then extracts
B to C:\extractor-test\
.................
ok, now what I want it to do is to:
...............
C extract B to C:\extractor-test\ and C also extracts A to C:\extractor-test\
..............
0
 

Author Comment

by:creatorsss
ID: 6424811
Also, this isn't very important but I was wondering how do u shrink the code size for C....
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:Gwena
ID: 6425063
Well first the best way to shrink any exe file is to use the free exe compressor called UPX
http://wildsau.idv.uni-linz.ac.at/mfx/upx.html

use it like this for best compression

upx --best MyExe.exe

=====

I guess what you want is something like what the file combiner does but you want to be able to choose the dir that the 2 files end up in instead of it just defaulting to the same dir that you run your combined exe from?
That should be doable... let me think on it a bit :-)
0
 

Author Comment

by:creatorsss
ID: 6425893
er...actually, what I was thinking is for the combiner to split into 2 files...A and B
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6425956
Hmm... but the file-combiner demo I wrote does combine 2 files and then splits them apart... the first file must be the delphi exe file and must have the OnCreate code that I wrote... the second file can be anything... when the resulting combined exe is first run it splits into the 2 original files.... and the combined file is removed...
like so...
file1 = mydelphi.exe
file2 = whatever.???

make sure file1 has the oncreate code
then run file-combiner and merge them together
you now have a file named new.exe

when new exe is first run it splits back into
mydelphi.exe and whatever.??? and new.exe is
removed.

that sounds like what you want :-)
0
 

Author Comment

by:creatorsss
ID: 6426360
that's what I want but I have been looking at your self extractor code and so I've been wondering whether you could add on to the self extractor demo(on your website) and add on to it?
0
 

Author Comment

by:creatorsss
ID: 6444348
I have checked out ur file combiner but it says runtime error
0
 

Author Comment

by:creatorsss
ID: 6444354
I found out  why it says runtime, ok now, I tried ur program but it doesn't extract into 2 files
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6445842
I just used it to make a self extracting file that splits in 2....hmmm you are doing something wrong....try doing these things


-Make a new delphi program and make an oncreate event handler for form1
-add shellAPI to the uses clause
-copy the oncreate event handler from the file-combiner text box and paste it into your delphi app replacing the one that was there
-now compile the delphi app and close delphi
-now run file-combiner and choose the delphi app you just made as file1
-choose any other file as file2
-combine both files into 1 file... a file called new.exe will be created... when you run this exe it splits in 2 :-)

If you still have problems let me know and I will send you the source of a simple app that has the oncreate code pasted in..and the resulting exe that splits in 2 ... that way you can look them over to see how it was done :-)
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6445861
Oh..maybe it is confusing you that the new.exe is remaining and is extracting the second file...

New.exe becomes the original delphi app
the extracted file is the one that was added to it

If your original file is called MyDelphiProg.exe and the 2nd file that you add to it is somefile.exe then you can simply rename the new.exe that is created when you combine them back to MyDelphiProg.exe  .. now when it first runs you will end up with 2 files
MyDelphiProg.exe and somefile.exe... these are the 2 0riginal files... the combined file has dissapeared :-)
0
 

Author Comment

by:creatorsss
ID: 6447379
ok....so I checked out ur code...it works except that u need to use 2 .exe to make this work. Is there a way in which I can just use 1 .exe such that
1. When A is executed, it checks whether there is any code at the end of the file
2. If not, it then open.dialog and allows user to choose file to be attached.
3. After choosing, it attaches file to the end.
4. When it is executed again, the file checks whether there is any code at the end of the file
5. It find that there is code and then it takes the code at the end and the code in the front and it saves them in 2 separate files : A and B
6. The process carries on
Hope you can help.Thanks
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6447806
Yes that can be done.... I am finishing up my ExeMod.pas
delphi unit and it will make creating a program like that easy... I will get a copy to you as soon as it's finished :-)
0
 

Author Comment

by:creatorsss
ID: 6448475
Yeah thanx.........
0
 

Author Comment

by:creatorsss
ID: 6452821
Hey, another problem that have just realised is that the size of my application. all in all, my app is 100 over k after compression and if I have the combiner, the whole file could be more than 300 k which is alot. Is there some component out there to solve this?
0
 

Author Comment

by:creatorsss
ID: 6452826
So far, I know of 3 ways which is
1.Use compressions like upx
2. Remove ur uses clause like sysutils etc(but the prob is, u need these!)
3.Program in api way whereby .dpr files are not included(troublesome!)
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6453069
The only way I know of to make really small delphi programs is to use the KOL library... I make small utility exe's that are 15kb to about 35kb using KOL. But the documentation on KOL is poor and I'm not sure I could recode my ExeMod.pas unit to work with KOL... Your best bet is to use regular delphi and 'UPX --best your.exe' the programs :-)

Oh... I'm nearly finished with ExeMod.pas so send me your email and I will send you a working early version... you can do all the stuff you want with this unit.... I still have to add routines for adding sections to the PE and for pulling data from ram but you don't need those to do what you want to do :-)


You can finf KOL here
http://xcl.cjb.net/
0
 

Author Comment

by:creatorsss
ID: 6459513
ok....can just send me a simplified version without the ram bit. Thanks. My email is marinedestroyer2@hotmail.com
0
 
LVL 5

Accepted Solution

by:
Gwena earned 250 total points
ID: 6464900
Hi creatorsss :-)
  I just put a new version of SplitDemp.zip up on my site...it does what you want... I included the source code.. and the latest version of ExeMod.pas is in the zip :-)

It still has one small glitch though... It somehow ejects a copy of the embedded file during the first run... but that does not affect how the new exe performs...the newly created exe only ejects the file one time... after that it's just a simple program. The embedded file is removed from the final exe so that it's size goes back to normal :-)

I just can't seem to find the code that is ejecting a copy of the embedded file on first run.....hmmm maybe someone else can see it :-)
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6464907
Hey!  wasn't this just a 50 point Q at first?  
Don't worry about adding points I don't care about them at all anyway... I just comment on questions that interest me
:-)
0
 

Author Comment

by:creatorsss
ID: 6478580
ok
0
 

Author Comment

by:creatorsss
ID: 6501689
hey........I have a problem again....when the program binds a huge file, it hangs since there is so much code to bind....is there a way through this? is the {sleep} function useful?
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6501808
Hmmm... I have never noticed that problem... but I only have added stuff up to about 5mb in size...so if your adding more than that...hmmm   I'm not sure how to solve this.. maybe placing an application.processmessages somewhere would help.... it might need to go in the source code for some of the delphi string handling routines though and I don't have the source... I just have the standard versions of delphi.  I will think about this and if I get an idea I will post it here... if you think of something let me know :-)

sleep ??
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8735466
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

To accept Gwena's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now