Is it possible to embed and run exe file in a Delphi executable app?
Asked Answered
R

4

8

Resource files (.RES) accept any kind of binary files but if it is an exe file how can I run it?

Rose answered 22/5, 2011 at 19:45 Comment(3)
A lot of malware does it. What is your reason to work that way insted of using the polite way of an installer/uninstaller? When your software runs on someone's else machine, it should be well-behaved.Freehanded
Interesting observation... what happened to the OP?Torrietorrin
I would use it to extract a app updater to update my application from a remote server, then the new application would delete it the next execution.Beaudoin
C
12

You would have to extract it as a file to disk and execute it.

Although you don't have to extract it to disk, as Cosmin Prund says in a comment, if you don't it requires a lot of hard work.

Catkin answered 22/5, 2011 at 19:47 Comment(4)
+1 At least this is by far the simplest and most obvious solution.Tisbe
One must remember, however, not to extract the file to the same directory as the current application, because the latter most likely resides in the read-only Program Files folder. Instead, one should use the current user's temporary directory.Tisbe
You don't have to extract it to disk. It's just that not extracting it to disk requires lots of hard work and the use of undocumented Windows functionality.Senegal
One must remember if you extract it to the user's temp directory that another session could be sharing the same temp directory (Terminal Services) - be use to use a unique name.Revenue
H
6

http://sites.google.com/site/delphibasics/home/delphibasicssnippets/memoryexecutionunit-winxpwinvistawin7

Take a look at this memory execution unit.It allows you to execute an exe from memory without dumping it on disk.

Hardheaded answered 23/5, 2011 at 6:12 Comment(3)
The link is just a great solution and it can be easily changed to work with resources. Take a look at TResourceStream (delphidabbler.com/articles?article=3) and you will only need to change the FileToBytes function (probably rename it too so the name suggests its purpose, maybe ResourceToBytes?).Granese
Can I execute 32 bit exe file in memory by using an 64 bit application? Is it possible with the routine above?Crustacean
Tried uExecFromMem and works excellent AFTER switch off virus warning "Virtool:Win32/DelfInject.gen!BI" for the compiled version of this code. I'm afraid this can't be used in genuine programs, that's sad :-(Transcendentalistic
F
1

Yes it is possible. There is a Delphi library to do this somewhere on the web, but I cannot for the life of me remember what it's called. It allows you to execute a normal exe file no-matter where it is in memory. So you can load it into a stream, or just embed it in a resource.

I realize that my reply is a bit depressing since i dont remember the name of the library, but at least you now know that it can be done. If you google around for "execute PE exe from memory" and "Delphi" then I'm sure you will find it.

Fleabag answered 22/5, 2011 at 22:57 Comment(0)
H
0

You might want to take a look at Orean's XBundler: http://www.oreans.com/xbundler.php

I use their licensing product (WinLicense) and have been very happy with the product, their support, responsiveness and updates.

In fact, I'm about to buy XBundler so I can ship a dll securely embedded in my exe.

Tom

Hoarse answered 22/5, 2011 at 22:20 Comment(3)
Whenever a post a link to a commercial product that I use and that is directly relevant to the OP, I get down-voted with no explanation. Perhaps some SO readers are allergic to commercial software? (If I were king of SO, I'd prohibit downvotes without an explanation... but that's a topic for another day...)Hoarse
I definitely agree with the sentiment about -1 votes without explanation; your post (and other posts) don't really look like the work of our usual spam-artists :) but this specific post could definitely use some copy-and-paste examples on how to call the exe once bundled, or some other indication that you've successfully used their product for just this reason. (Or, perhaps, some reason why it is a difficult enough problem to justify a commercial program.) I'm just saying that the bar for links to commercial software is much higher than most other posts...Clupeoid
+1 Good suggestion, sarnold. I hadn't thought of that. I'll include examples in future posts of this kind of thing. Thank you.Hoarse

© 2022 - 2024 — McMap. All rights reserved.