Merge two exe files into one programmatically

48,536

Solution 1

Theoretically this is possible, but it will take some effort from your side.

You can append data to an exe file, this is how self extracting archives work. However, you'll need your own data format, similar to a file system, because you've got just one flat .exe file.
See this Microsoft article (there's a lot more on google) http://support.microsoft.com/?scid=kb%3Ben-us%3B84062&x=12&y=13

The exe you're packing your two files in must then extract those files and can finally run them.

Good luck.

Solution 2

No, your best bet is to create a .bat file (Windows) that runs both executable files.

@echo off
c:\path\to\first\exe\file1.exe
c:\path\to\second\exe\file2.exe

You can also create a shell script in Linux to do the same thing

#!/bin/sh
/path/to/first/exe/file1
/path/to/second/exe/file2

Note, this will execute file1 before file2.

Solution 3

You can create your own EXE file that contains two other EXE files as embedded resources and extracts and executes each of them.

Beware that the EXE that you embed might not work if you extract it to a different directory.

Solution 4

Technically it is possible to embed some other exes files in your exe, some packers like upx do it. So you should be able to do the same with 2 exes.

In a unix like fashion your exe could fork, then the first process execute the first old executable, and the new process execute the second exe, maybe installing a pipe between them before.

But this is clearly not so easy to do and very probably a useless overkill for your needs. You probably just need a small .bat or .sh

Solution 5

I noticed your "programmatically" qualifier, but just in case an out-of-code solution is acceptable for whatever you're doing...

IExpress can build an EXE which executes two other EXEs. You can build an IExpress package from the commandline.

SED file:

[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=1
HideExtractAnimation=1
UseLongFileName=0
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[Strings]
InstallPrompt=
DisplayLicense=
FinishMessage=
TargetName=C:\combined.exe
FriendlyName=Example Title
AppLaunched=run.bat
PostInstallCmd=
AdminQuietInstCmd=
UserQuietInstCmd=
FILE0="FirstProgram.exe"
FILE1="SecondProgram.exe"
FILE2="run.bat"
[SourceFiles]
SourceFiles0=C:\programs\
[SourceFiles0]
%FILE0%=
%FILE1%=
%FILE2%=

run.bat file:

FIRSTP~1.EXE
SECOND~1.EXE

When you run combined.exe, firstProgram.exe will execute. When it's finished, secondProgram.exe will execute. If you wanted firstProgram.exe and secondProgram.exe to run concurrently, it could be done with a change to the BAT file.

Share:
48,536
Auxiliary
Author by

Auxiliary

Studied data visualization architectures, love programming in Python, C++, Javascript.

Updated on July 09, 2022

Comments

  • Auxiliary
    Auxiliary almost 2 years

    Is there a way to merge two exe files into one, programmatically, so that running it would execute both older exe files together. I found some things on google about injecting code or dll files but is it possible two merge two exe files or to inject exe into exe?

    Thanks in advance.

    [EDIT] Thanks everyone. Just for those who said that it's not possible, I have to say I almost did it in the end in the way some suggested. It almost goes like this (I can't remember all of it cos it was a long time ago):

    [BEWARE: This algorithm is very similar to those of some worms and viruses. I am not a hacker or a virus writer! and this is to be used only for experimental or unharmful reasons - Making mistakes in the code can ruin the executables in directories.]

    1- The Exe checks itself's size to detect whether anything has been appended to itself. if it hasn't then:

         1.1- The exe finds other executable files in its directory (lets call one of them as victim!)
         1.2- it makes a copy of itself (lets call it newMe)
         1.3- it copies the other executable found in the directory to the end of newMe.
         1.4- it deletes the other executable file found and renames newMe to its victim's name.
    

    2- If the exe detects that something has been added to it then:

         2.1- Then it copies data from itself (from ORIGINAL_FILE_SIZE to the end of file) to a new file (lets call it newBorn.exe)
         2.2- It runs itself's code and then executes the newBorn.
    

    I said I ALMOST did it cos in this way the exe appends another exe to itself. but this could be repeated for appending and executing 2 or even 3 or more executables into one. you just have to know the ORIGINAL_FILE_SIZE of the written program.

  • Jeffrey Aylesworth
    Jeffrey Aylesworth over 14 years
    On Windows, I'm pretty sure one.exe will execute completely before two.exe starts. Not sure if this is what is wanted.
  • Agnel Kurian
    Agnel Kurian over 14 years
    -1. Because redirecting the output of one exe to the input of the other is not the same as what the OP intended. Very different.
  • Dio
    Dio almost 11 years
    it's not a good suggestion and mostly won't work. all three files will need to be in the same dir. It is also possible to pack two binaries together into one, and have them both run.
  • Imad Abu Hayyah
    Imad Abu Hayyah over 5 years
    Could you please explain more how to do it, I'm facing the same need.
  • Medi
    Medi almost 4 years
    How? what is the tool for doing this?