Any code to create another executable?

This is a discussion on Any code to create another executable? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hi, Is there any way or code to create another .exe file during program execution? If it's possible, can i ...

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    Any code to create another executable?

    Hi,

    Is there any way or code to create another .exe file during program execution? If it's possible, can i hard-code all the codings needed in the new executable?

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    guess what a compiler is an example of...
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    What about packing all the binary in the code, and then output it as a file and rename it as .exe ? or are there any other ways?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Well, theoretically you could write a file within a program (containing lots of MQ@% characters) and save it as binary and naming it XXX.exe. However I highly doubt there is an easy way to do this.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    i got all these unterminated characters errors during compile ii think it's because the binary is too long.

    I tried save the funny character into a text file, read it one character at a time and output it as .exe but output is incorrect.

  6. #6
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >I tried save the funny character into a text file, read it one character at a time and output it as .exe but output is incorrect.<

    Did you open the new file in text or binary mode? Anyway, to answer your first question, you could have an array of hexidecimal numbers, each representing an ASCII character. Just write these to a file (that was opened in binary mode). Give it the appropriate extension and viola.

  7. #7
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    i dunno how to do hex. And i did open the new file using mode "wb"

    thnx

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Unless you're going to be modifying the way the file is written, and its all constants, just copy and paste each line of the file (the best option would be EDIT.com from Dos,), and then use each of the lines in between ""'s in a printf or cout statement.

  9. #9
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >i dunno how to do hex. And i did open the new file using mode "wb"<

    If you can't do hex, just do an array of ASCII characters (decimal form). I don't even know why I said hex in the first place - decimal would do just as good.

    >then use each of the lines in between ""'s in a printf or cout statement.<

    That wouldn't work because an executable file has characters that don't like to be treated as C/C++ strings (null characters, quotes, those weird looking characters, etc.). That's why hexadecimal or decimal would be a good choice.

  10. #10
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Okay, here's a sample I whipped up. I hope this is what you were talking about. Sorry I used hex, but it was the easiest for me. If it's too much of a problem, I can fix it.

    You'll notice (when you compile and run it) that it creates a file named "program.exe". Run it. It's the winhelp.exe program found in Windows, so you'll need that devil to run it. Hope this helps.
    Attached Files Attached Files

  11. #11
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    hey that worked perfectly. One question. How do u convert decimal stuff to hex, in other words, how do u know the hex equivalent. ALso, do u havta use array? And did u copy and paste each element? Coz there are commas between each one. Anyway that was exactly what i wanted and i'll appreciate it if u tell me how u did it.

    thnx

  12. #12
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    First a wrote simple program that converts a program into a text file that is hexadecimal with commas. Then I just copied that into an array.

    This is the program that converts an executable to user readable hexadecimal:
    Code:
    #include <stdio.h>
    
    int main()
    {
    	FILE *file;
    	FILE *file2;
    	signed short int ch = 0;
    
    	file = fopen("program.exe", "rb");
    	file2 = fopen("program.txt", "w");
    
    	while(ch != EOF)
    	{
    		ch = fgetc(file);
    		fprintf(file2, "%x, ", ch);
    	}
    
    	fcloseall();
    
    	return 0;
    }
    You have to open the file it creates and delete ", ffff, " at the end. Then copy the whole file into an array.

  13. #13
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    why is there ffff?

    also, is it possible to make a program delete itself after executation?

  14. #14
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Nutshell
    also, is it possible to make a program delete itself after executation?
    Aghh....so that's what your your up to........

  15. #15
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Just out of curiosity..........

    But i do hav one application. Say i want to let my friend have a look at a project i've done - a normal school project in a word file. But i don't want him to copy and paste anything in it. SO if i convert the text file into an image file and display in a program which deletes itself after say 5 minutes then he won't have time to do anything except having a look?

    pls i wanna know, and i have no bad intention what so ever

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create EAN code in c#
    By Limpan in forum C# Programming
    Replies: 3
    Last Post: 05-18-2009, 05:37 AM
  2. how to properly call an executable from C code?
    By remy06 in forum C Programming
    Replies: 3
    Last Post: 05-14-2009, 03:48 AM
  3. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  4. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  5. Replies: 4
    Last Post: 01-15-2002, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21