?
Solved

Loading an EXE inside a TMemoryStream and executing it from there.

Posted on 2003-02-19
10
Medium Priority
?
723 Views
Last Modified: 2010-04-04
Hello,

my question is very simple, I need to load an EXE file inside a TMemoryStream. Once the full image of the executable has been loaded in memory I need to execute it from there.

Reason? I need to bundle an EXE image inside my program and esecute it in-memory. It NEVER have to be written to disk.

I'm starting with 300 points but if the answer will show being harder than expected I will increase the points.

THANKS IN ADVANCE!!
0
Comment
Question by:BackDream
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7982878
not possible :-(
0
 
LVL 22

Expert Comment

by:grg99
ID: 7983059
Not easily doable in-memory.  Running an EXE involves more than just loading it into memory, there's various kinds of relocation that have to go on, plus setting up a PSP, and more.

If you can make your executable very small, less than 64K and simple, it may compile into a .COM file, which is easier to load and run, but still not totally trivial.

Another way would be to write a special block-device driver, which looks to the system as a device, but actually transfers data from your internal .EXE.
NOT a trivial thing, and is going to be heavily system dependent (meaning you'll need separate drivers for DOS, Windows31, Windows 95/98/Me, Windows NT/2000/XP.)


Does this help?


0
 
LVL 34

Expert Comment

by:Slick812
ID: 7983678
hello BackDream, the windows system seems to be set up so that executables are only allowed to run from a disk file, there seems to be some good reasons for this. I guess anything is possible (I.E. creating your own driver to bypass the disk read, although delphi don't do drivers), so I'd have to agree with kretzschmar -> sort of Not posible, except maybe with very  advanced coding methods. But it seems that since you allready have an executable running, just do the code for your results and not launch another executable.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:SteveWaite
ID: 7984635
How about starting a console with command.com but in silent unseen mode using ShellExecute and SW_HIDE, send keys to it to start a memory disk, then copy the exe to it from stream, run it, and so on.

function ExecuteFile(const FileName, Params, DefaultDir: String; const ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array [0..250] of Char;
begin
  Result := ShellExecute(Application.Handle,
    nil,
    StrPCopy(zFileName, FileName),
    StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir),
    ShowCmd   // use SW_HIDE
    );
end;

Regards
Steve
0
 
LVL 5

Accepted Solution

by:
Gwena earned 1200 total points
ID: 7986131
Hi :-)

Is this other exe you want to run without extracting it to disk a delphi exe you have written?

If so then I suggest combining the 2 exe programs into one single exe.


It is easy to store another exe inside your main exe and then extract and run it... you could send it to windows/temp  or perhaps you could create a ram disk and place it there.


If you just want to keep people from being able to grab the extracted exe from the disk and run it themselves then you could protect the exe by using one of those utils that can make any exe a password protected exe... some of them may accept the password as a command line parameter... and so your main exe could send the pw but a user would not easily discover it.


If it is possible to store an exe in yours and somehow run it without putting it on disk first then I think the clues to how to do it might be found by examining the source code of an exe compressor like UPX. These compressors create a single file that has the de-compressor code at the start and the decompressor creates and writes the original exe into ram and runs it... this is close to what you need ... the decompressor code places an exe into ram and never writes it to disk... and yet the exe runs just fine :-)
0
 

Author Comment

by:BackDream
ID: 7991967
Thanks to all of you for your comments and... Gwena, I've downloaded the source code to UPX (C and assembler!) and the extractor, so the little program that extracts and RUNS the extracted program is all written in assembler.

Not understandable to me, unfortunately.

But id does exactly what I want to be able to do: bundle 2 exes, extract one directly into memory and run it from there...

I already know how to write all the compress, bundle, extract code. The only part I'm missing is how to run it once I have extracted it to memory.

Any more help would be so much appreciated!! :-)))

BackDream
0
 
LVL 5

Expert Comment

by:Gwena
ID: 7995930
Hi BackDream :-)

I thought that that code was doing about what you wanted to do... I hoped maybe you could figure it out and tell me how to do it too :-)

Figuring out how UPX does that is too hard for my small brain :-)
0
 

Expert Comment

by:kake26
ID: 9210960
Hi Gwena,
I've seen delphi exe binders that do just what your trying to do. Search for Multibinder on torry.net thats pretty much what you are looking for. Its freeware and comes with source!! I hope it sheds light on this.
0
 
LVL 10

Expert Comment

by:kacor
ID: 9928045
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 for this question:
       to accept Gwena's answer
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Some days and here is the Christmas Time. I wish good luck and good health for you all and for your loved ones

kacor
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 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