7

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

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
isa
  • 1,055
  • 16
  • 26
  • 4
    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. –  May 23 '11 at 07:24
  • Interesting observation... what happened to the OP? – Vector May 24 '11 at 02:10
  • 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. – NaN Aug 22 '13 at 20:19

4 Answers4

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.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • +1 At least this is by far the simplest and most obvious solution. – Andreas Rejbrand May 22 '11 at 19:53
  • 5
    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. – Andreas Rejbrand May 22 '11 at 21:49
  • 2
    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. – Cosmin Prund May 23 '11 at 07:30
  • 1
    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. – Ian Boyd Jun 18 '11 at 13:13
5

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.

opc0de
  • 11,557
  • 14
  • 94
  • 187
  • The link is just a great solution and it can be easily changed to work with resources. Take a look at `TResourceStream` (http://www.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`?). – Pateman May 23 '11 at 08:55
  • Can I execute 32 bit exe file in memory by using an 64 bit application? Is it possible with the routine above? – Mehmet Fide Apr 22 '13 at 09:02
  • 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 :-( – Codebeat Feb 21 '15 at 06:02
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.

Jon Lennart Aasenden
  • 3,920
  • 2
  • 29
  • 44
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

RobertFrank
  • 7,332
  • 11
  • 53
  • 99
  • 2
    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...) – RobertFrank May 23 '11 at 11:15
  • 1
    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... – sarnold May 24 '11 at 00:51
  • +1 Good suggestion, sarnold. I hadn't thought of that. I'll include examples in future posts of this kind of thing. Thank you. – RobertFrank May 24 '11 at 18:44