Thread: Any code to create another executable?

  1. #16
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Nutshell
    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
    There are Modify permissions with M$Word......that would stop your friend cutting & pasting........

  2. #17
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    >>also, is it possible to make a program delete itself after executation?

    In windows, the way to do this is to put it in the Temp directory.
    I don't think there is a platform independant way to do it.

  3. #18
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Hi can u be kind enough to tell me howta do this in word? Any extra plugins and stuff needed?

  4. #19
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Hillbillie i modified ur code but it doesn't work, here is the code thnx. All the output file contains is many many "1, "s......

    Code:
    /* Takes a binary file and output its hex equivalent in a text file */
    
    #include <stdio.h>
    
    int main( int argc, char *argv[] )
    {
       FILE *fpBinary, *fpHex;
       unsigned short int c;
    
       if ( argc == 1 ) {
          printf( "%s\n\n%s\n%s\n\n\n", "Usage: bin2hex.exe < filename >",
                  "It takes a binary file and output its hexidecimal equivalent",
                  "in a text file ( hex.txt ) in the current directory." );
          system( "PAUSE" );
          return 0;
       }
    
       if ( ( fpBinary = fopen( argv[ 1 ], "rb" ) ) != NULL ) {
          if ( ( fpHex = fopen( "hex.txt", "w" ) ) != NULL ) {
             while ( c = fgetc( fpBinary ) != EOF ) {
                fprintf( fpHex, "%x, ", c );
             }
          }
          else
             printf( "\aError\n\n" );
       }
       else
          printf( "\aError\n\n" );
    
    
       system("PAUSE");
       return 0;
    
    }

  5. #20
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hey,

    I am fairly interested in this sort of area, and i understand how its been done using hex.

    But, i would like to know how to edit the exe output with user input. For example say in the main program i asked the user to input a text string that will be the window caption of the new exe. How would you then set the window title to this string then output the exe. Dunno if that sounds correct lol.... I guess you could modify the hex bit by bit but it would be very tricky, is there a simple way of doing this?

    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  6. #21
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    anyone can answer my question above the above post pls thnx.

    (TNT) i think u're talking about resource hackers again.

  7. #22
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you want to change a windows caption then look at WM_SETTEXT as sending this message to a window will do what you wish......

    If you are interested in Hex editing........take some time out to learn ASM

  8. #23
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    what i want to do is relatively. Can't u answer it in a simple way?

    thnx

  9. #24
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    My my, this thread has exploded...

    >why is there ffff?<

    That is hexadecimal for -1, which is what most standard C libraries use for EOF. It could be fixed easily to not print that out to the text file, but I'm lazy.

    >Hillbillie i modified ur code but it doesn't work, here is the code thnx. All the output file contains is many many "1, "s......<

    I received a few errors when compiling that code you posted. Do you want help on the errors or does yours compile fine and you need help on bugs? Please be more specfic.

  10. #25
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I couldn't compile. It compiles fine but when i use execute it, all the text file contains are many many "1, "s.

  11. #26
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    You _really_ should figure this out on your own. I don't like giving people that are having problems source code because you don't usually learn that way, but oh well. Here's what you were trying to do, but working :

    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    	FILE *input;
    	FILE *output;
    	int ch = 0;
    
    	if(argc != 3)
    	{
    		printf("\nBin2Hex V0.1\nOutputs a binary file's hexadecimal equivalent..\n");
    		printf("\nUsage: %s <input file> <output file>\n", argv[0]);
    		return 0;
    	}
    
    	input = fopen(argv[1], "rb");
    	output = fopen(argv[2], "w");
    
    	while(ch != EOF)
    	{
    		ch = fgetc(input);
    
    		if(ch != EOF)
    		{
    			fprintf(output, "%X, ", ch);
    		}
    	}
    
    	fcloseall();
    
    	return 0;
    }
    I also fixed that problem with it outputting 0xFFFF.
    Last edited by Hillbillie; 03-30-2002 at 06:50 PM.

  12. #27
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Ur code worked. BUt i really see no diffference between mine and yours except some minor changes which i think it's related to the problem such as seperating the assignment of 'ch'. THere's no difference! How come ur one works and mine doesn't....

  13. #28
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Wait i got it. It's this line:

    Code:
    while ( c = fgetc( fpBinary ) != EOF ) {
    should be

    Code:
    while ( ( c = fgetc( fpBinary ) ) != EOF ) {
    thnx to all, to confirm, is it really impossible to do it with plain text, instead of hex?

    thnx thnx

  14. #29
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    >thnx to all, to confirm, is it really impossible to do it with plain text, instead of hex?<

    I wouldn't say it's impossible, but it would be difficult to do. Some of the characters that are in binary files won't work well in strings or even as single characters.

  15. #30
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    You said not impossible. DO u know any tricks to get around the problem? IF not, it's fine. I already got what i wanted to know thnx

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, 11:26 AM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM