Thread: insert another exe into exe

  1. #1
    Registered User lliero's Avatar
    Join Date
    Oct 2001

    Unhappy insert another exe into exe

    can anyone tell me how do i insert into existing exe file another exe so that it executes with it?

    i need it very bad because we will be having our computer lab this coming week. i have no idea how to perform it

  2. #2
    Registered User
    Join Date
    Mar 2002


    Look at this thread.

  3. #3
    Registered User lliero's Avatar
    Join Date
    Oct 2001

    Talking what i mean is this

    i mean,

    for example, i have this program turbo.exe <c compiler>
    then i what to insert some bytes into turbo.exe
    so that it calls my application say lliero.exe.

    is there a way? i am not trying to make a virus, its just that
    i want to know the theory behind this..

    i am using turbo c
    " programming is 1% syntax and 99% logic "

  4. #4
    Registered User
    Join Date
    Mar 2002

    I'm lost?

    Are you trying to just rename turbo.exe (possible, but it won't be ususable) or are you trying to do that with any exe? Sounds like you just want to make an execuatable to rename a file. Is that right?

    Well, if so, this code is Borland compliant:

    # include <stdio.h>

    int rename (const char *old_name, const char *new_name);

    But I'm probably guessing wrong on what you are asking.

  5. #5
    Join Date
    Aug 2001
    Groningen (NL)
    >for example, i have this program turbo.exe <c compiler>
    >then i what to insert some bytes into turbo.exe
    >so that it calls my application say lliero.exe.

    And when should turbo.exe call your lliero.exe? A possibility is to call your program when turbo.exe is finishing. You could make a jump to new code in turbo.exe and this new code calls lliero.exe.

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    There are several ways to do what you want. However, most of them are prob beyond where you are at in your coding.

    The easiest ways to execute child programs are with the spawn() family of functions.

    If you wish to go through DOS instead, then you can load and run or load and not run an EXE file via int 21h. The load and run or EXEC will only return to your program after the child process has completed. If you choose to just LOAD then you will have to read the EXE header yourself as well as the relocation items to find out where you need to jump into the EXE.

    If you want to copy one exe into another, the only way that I know of is to append it to the end of an exe. However, this will make the file size very large if your EXEs are of considerable size and the only way to execute the second EXE, is by loading in the second EXE and jumping to it. DOS will not do this for you since it does not support bundling exes together this way. You can load your second EXE as an overlay, but again most of this is beyond the scope of this board.

    Another way to do it, is to compile your second C file as a straight binary and append that to the end of your EXE file. This way you would only have to load in the bytes as they appeared after the first EXE. However, this will eliminate any relocation items and will essentially produce a flat binary in memory. You can also include raw data in EXEs using this method. Be very vareful not to overwrite any of the bytes from the first EXE and make sure that your first EXE does not run headlong into your second binary or your second EXE as this would certainly crash the computer.

    For more information consult the RBIL, DOS tech refs, OS dev sites, FAT specs, Art of Assembly book, and other sources related to file systems,EXE specs, COM specs, flat binaries, and assembly language.

  7. #7
    Super Moderator
    Join Date
    Sep 2001

    You'd have to learn Assembler for this..... but it's worth a shot.

    Open the file with DEBUG (the instructions will be in any assembler book if you decide to learn it (if this is that important, you probably will)). Use the U command to unassemble the code and look at it. Determine where exactly in the operation you want this to take place, and find this spot in the code. Recopy the code, but just add the instruction to run lliero.exe right after that. Easier said than done, I know, but it works.

  8. #8
    It is easier just to append the file from a C program.

    In debug you would have to do this:

    1. Find out the size of the original exe
    2. DEBUG <exename>
    3. Type in D to dump the memory.
    4. Take the starting address and add the number of bytes in the
    file to it
    5. Find out which sector the new file resides on and how many
    sectors long it is.
    6. Type in L <address> <drive> <firstsector> <number>
    where address is the ending address of the program you just
    loaded into memory.
    7. Then type in N to name the new file.
    8. Type in W to write out the new file to disk. However, you must
    remember to grab the new contents by specifying the length
    to write.

    Like I said much easier to write in C since there are about a billion file i/o functions given to you.

  9. #9
    Registered User lliero's Avatar
    Join Date
    Oct 2001

    Talking thnx

    guys thank you very much....

    ill try some....

    i will try to dis-assemble some exe then do some assembly stuff...
    cause all i want is my program to execute when a certain program starts... yea...

    thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to insert an item to a ListView
    By ysabelle in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2007, 07:03 AM
  2. Insert unique record into database
    By groorj in forum C Programming
    Replies: 4
    Last Post: 12-29-2004, 11:06 AM
  3. Close another exe from another exe??
    By Tony in forum Windows Programming
    Replies: 1
    Last Post: 06-12-2002, 07:19 AM
  4. adding bytes to EXE to call another EXE
    By lliero in forum C Programming
    Replies: 2
    Last Post: 03-30-2002, 07:23 AM
  5. Replies: 1
    Last Post: 09-17-2001, 05:46 AM