Recent

Author Topic: Include an Executable in your Project  (Read 1276 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 3135
Include an Executable in your Project
« on: September 23, 2022, 03:25:53 pm »
Hi Folks,

maybe a stupid question:
Is it possible (resp. who to?) to include a separate EXE into your own Exe?

Background: Currently, i'm writinga small tool for the company i work for.
And this tool will use a command-line EXE called via TProcess.

Now to avoid moving multiple files around i was thinking to include everything in my own Exe, kinda like:
1) Start up my Exe
2) it notices it's a first start (the "other" exe is missing)
3) My Exe spits out ("vomits" *gg*) the "other" exe
4) Go ahead and be happy

consecutive starts of my exe would always first check if the other exe is there.

So, back to my question: Possible? How?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

lainz

  • Hero Member
  • *****
  • Posts: 4737
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Include an Executable in your Project
« Reply #1 on: September 23, 2022, 03:36:01 pm »
And antivirus will trigger. Best use an installer with Inno Setup or something else.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Include an Executable in your Project
« Reply #2 on: September 23, 2022, 03:37:57 pm »
If you are talking about windows, simple include whatever file into the resource section via Project -> Project Options -> Resource
Add there your exe, give it a qualified identifier, later extract that resource back to disk and run it however you like.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

loaded

  • Hero Member
  • *****
  • Posts: 876
Re: Include an Executable in your Project
« Reply #3 on: September 23, 2022, 03:40:58 pm »
If the size of the exe is not very large;
It can be added to resources and created once, in a specific folder at first run time.
In other runtimes, you can just use the extracted exe.
The more memory computers have, the less memory people seem to use. 😅

bobby100

  • Sr. Member
  • ****
  • Posts: 300
    • Malzilla
Re: Include an Executable in your Project
« Reply #4 on: September 23, 2022, 03:41:12 pm »
There is a name for such apps - droppers.
Every Antivirus will (or should) react on dropping an EXE.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6189
  • Compiler Developer
Re: Include an Executable in your Project
« Reply #5 on: September 23, 2022, 03:48:50 pm »
Is it possible (resp. who to?) to include a separate EXE into your own Exe?

Background: Currently, i'm writinga small tool for the company i work for.
And this tool will use a command-line EXE called via TProcess.

Now to avoid moving multiple files around i was thinking to include everything in my own Exe, kinda like:
1) Start up my Exe
2) it notices it's a first start (the "other" exe is missing)
3) My Exe spits out ("vomits" *gg*) the "other" exe
4) Go ahead and be happy

consecutive starts of my exe would always first check if the other exe is there.

So, back to my question: Possible? How?

Yes, just add your executable as a resource and write that to a file if it does not yet exist (or its checksum does not match with what you have stored inside your executable).

And antivirus will trigger. Best use an installer with Inno Setup or something else.

There is a name for such apps - droppers.
Every Antivirus will (or should) react on dropping an EXE.

SysInternals Process Explorer uses this for the x86_64 (and nowadays also ARM64) executable which are all contained inside the i386 executable. Also our own application at work does that for an utility application to access VSS on a 64-bit system from a 32-bit application. And so far I have seen no anti virus react to that.

Zvoni

  • Hero Member
  • *****
  • Posts: 3135
Re: Include an Executable in your Project
« Reply #6 on: September 23, 2022, 03:54:13 pm »
Whoa.
Didn’t expect so many answers in such little time.
Thx guys. Appreciate it.
Now i have a starting point
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Include an Executable in your Project
« Reply #7 on: September 23, 2022, 03:55:49 pm »
Antivirus will to 100% react if you
a) have exe-packed the file (main and/or included)
b) extract exe-packed file to disk
c) try to run included exe from/within RAM without saving prior to disk

official way, like i described up there works wonderful on windows.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: Include an Executable in your Project
« Reply #8 on: September 23, 2022, 06:28:46 pm »
Is it possible (resp. who to?) to include a separate EXE into your own Exe?
Yes, just add your executable as a resource
[/quote]

In Delphi there was maybe a more "mouse-friendly" approach, JediVCL (partially ported to Laz, but not this component) hasTJvFormData
In design-time you click the component and load files into it via usual OS-standard file open dialogs. Then they were stored in DFM/LFM, with an optional name.

At runtime it is just a component in the form that gives you TStream by its name or index. In the end it is similar to including resources, but more novice-friendly. Though, i'd not use it for really big files, since this approach most probably disable lazy read via memory mapping.

I used it to provide empty databases, like "new document template". The server DLL were provided traditional way though, not because of antivirus concern (the signed binaries probably would had calmed antiviri down), just because there was a need to save several files and subfolders.

There is more concerns than antivirus though. On Windows %TEMP% is executable, and many installers rely on it, so it probably would remain. On Linux i would not be sure i am guaranteed to have a filesytstem both writeable and executable in some fixed predefined path...

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: Include an Executable in your Project
« Reply #9 on: September 23, 2022, 06:30:57 pm »
SysInternals Process Explorer uses this

Microsoft antivirus would whitelist Microsoft EXEs signed by Microsoft crypto-signature.

To which extend this can be extrapolated to non-MS AV and non-signed own binaries is anyone's guess.

 

TinyPortal © 2005-2018