Jump to content

include exe within exe


larynx

Recommended Posts

I'm using Visual C# (within Visual Studio 2005) to code something and I'm looking for way a to include an existing exe file within the project so I can run it within the program I'm creating, the idea is that I end up (after the build) with one exe file that does something and also executes the other exe file.

Is there anyway to do this?

If not, is there a good alternative?

Thanks in advance...

Link to comment
Share on other sites

Use an exe wrapper? Or embed a file in the program using OLE and then extract and execute against the file.

Link to comment
Share on other sites

What i have seen done, i have not done this myself, but what you can do is take the .exe binary > a oct array and when it runs write it back out in binary. 

Link to comment
Share on other sites

  • 1 month later...
If you mean run both programs from one EXE, you can use iexpress with come with windows.

Yeah, if you want to install multiple exe's at a time and script the install process into one package.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 2 weeks later...
  • 2 weeks later...

I am quite sure he is not trying to package the file. I think he wants to run a .exe from within a .exe.. You can't "Include" a .exe binary in a source file. The reason? Because it is not the original source it has been compiled, boiled down. You would need the source. Correct me if I am wrong but you would either have to decompile it or use its original source in compilation..

If you want to run a .exe from within a .exe with C++ :

system("my.exe");

Link to comment
Share on other sites

I am quite sure he is not trying to package the file. I think he wants to run a .exe from within a .exe.. You can't "Include" a .exe binary in a source file. The reason? Because it is not the original source it has been compiled, boiled down. You would need the source. Correct me if I am wrong but you would either have to decompile it or use its original source in compilation..

If you want to run a .exe from within a .exe with C++ :

system("my.exe");

You could open the program in notepad, then copy the program into c#, and put it in an array. Then write the array back out using a file stream.

I shall prove with a program...

Link to comment
Share on other sites

  • 3 weeks later...

I'm not much of a coder (other than the odd bit of php) so I don't know for sure but... Could you fork one exe into an alternate data stream of the other?

Who knows?! :-P

I might do a bit of experimenting later on when I've finished doing more important stuff like drinking my coffee.

Drinking coffee is very important.

Link to comment
Share on other sites

  • 3 weeks later...
You could open the program in notepad, then copy the program into c#, and put it in an array. Then write the array back out using a file stream.

I shall prove with a program...

Yes nicatronTg is exactly right! you don't need source code to run a binary executable... lolz

dejay or whatever your name is, you are 100% wrong!!! why on earth would you need source code to embed binary data in an executable program of your own?

nicatronTg I thought you were going to post an example program? I guess you forgot! well I'll do it...

okay I whipped up this program in 5 minutes! its really simple, I use this method all the time when making my directx games, I like to embed the textures and sounds and all that good stuff within the executable file it self that way I dont leave things in a folder somewhere for someone to mess with... its all hidden inside the games executable where noobs wont even mess with...

I use Hex Workshop to take a file's bytes and format it in an unsigned char array that is ready to copy and paste right into your source code(I like to make a header file to store the binary data as it is a huge array even with a small file, so instead of making the main source code a difficult to scroll through file I just put it in a header file and keep my source code file clean) in hex workshop goto Edit->select all, then Edit->Copy As-> C Source

In this example I will be using calc.exe just to demonstrate exactly how easy this is...

Im using Microsoft Visual C++ 2008 by the way(you might have to modify it slightly to work for other compilers)

Ok I have created a blank console project(I hate the precompiled header)

then added a .cpp called "ExeInExe.cpp"

then I wrote this code:

yeah I just had to post because DJ said it was not possible without source code LOL !! :P

#include <windows.h> // all required headers
#include <stdio.h>
#include <fstream>
#include <iostream>
#include "CalcData.h" // where the binary data for "calc.exe" is stored

using namespace std;

char EXEfile[256]; // will hold the path to the executable to run once extracted from this console executable

int main()
{
    SetConsoleTitleA("Steves Embed File Into Executable Example");
    system("color 0A");
    GetSystemDirectoryA(EXEfile, 256); // get system dir to hide exe file ex. C:\WINDOWS\system32
    strcat_s(EXEfile, "\\secret"); // append our secret dir

    CreateDirectoryA(EXEfile, 0); // create the folder
    strcat_s(EXEfile, "\\EmbeddedCalc.exe"); // concatenate file name to it so we save the exe into this new folder

    ofstream EXE(EXEfile, ios::binary); // create the file at the specified secret path ios::binary for binary data
    EXE.write((char*)&Calc, sizeof(Calc)); // write the calc binary data to the file
    EXE.close(); // save and close the file

    cout << "Saved EXE file to: " << EXEfile << "\n"; // print out where it was saved to console
    cout << "Running exported exe file in\n\n";

    for(int x = 3; x > 0; x--) // count down 3 2 1 RUN!!! // count down to execution
    {
        cout << x << "...\n";
        Sleep(1000);
    }

        // finally use shellexecute to execute the file, better than system()

    ShellExecuteA(0, "open", EXEfile, 0, 0, SW_SHOWNORMAL); // or you could use SW_HIDE to create the window hidden hehe! :)

    cout << "\n\n\n\n";
    system("pause");

    return 0;
}

CalcData.h is way to big to post here so ive gone ahead and uploaded the whole project to this link:

http://rapidshare.com/files/122239169/ExeInExe.rar.html

or you can just use hex workshop and make it yourself from calc, and change the name of the unsigned char array to "Calc"

Thats how its done :)

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...