home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19387 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.1 KB  |  73 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
  2. From: dave@cs.arizona.edu (Dave Schaumann)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Program to convert .EXE to a "C" source file?  I really need one!!
  5. Message-ID: <1993Jan7.235516.16627@organpipe.uug.arizona.edu>
  6. Date: 7 Jan 93 23:55:16 GMT
  7. References: <1993Jan2.203527.27050@news2.cis.umn.edu> <1993Jan4.022241.4493@pony.Ingres.COM> <C0B6x5.DA6@ulowell.ulowell.edu> <1993Jan7.131240.10795@pool.info.sunyit.edu>
  8. Sender: news@organpipe.uug.arizona.edu
  9. Reply-To: dave@cs.arizona.edu (Dave Schaumann)
  10. Organization: University of Arizona
  11. Lines: 59
  12. In-Reply-To: ujd@pool.info.sunyit.edu (Jacek Dziembaj)
  13.  
  14. /* Use: bin2c <infile.exe >outfile.c
  15.  *
  16.  * Note: this includes a few UN*Xisms, but I'm sure equivalent calls can
  17.  *   be substituted on other systems.  Also, you should probably generate     
  18.  *   random names (particularly under multitasking systems) instead of
  19.  *   relying on "/tmp/foo.exe" to be non-existant.
  20.  */
  21.  
  22. #include <stdio.h>
  23.  
  24. char *s1[] = {
  25.   "#include <stdio.h>",
  26.   "",
  27.   "int bytes[] = {",
  28.   NULL
  29.   } ;
  30.  
  31. char *s2[] = {
  32.   "-1 } ;",
  33.   "",
  34.   "int main() {",
  35.   "  int i ;",
  36.   "  FILE *f = fopen(\"/tmp/foo.exe\",\"w\") ;",
  37.   "  if( f == NULL ) {",
  38.   "    fprintf( stderr, \"FATAL ERROR: can't open temp file\\n\" ) ; exit(1) ;"
  39.   "    }",
  40.   "  for( i = 0 ; bytes[i] >= 0 ; i++ )",
  41.   "    fputc( bytes[i], f ) ;",
  42.   "  fclose(f) ;",
  43.   "  system( \"chmod +x /tmp/foo.exe\" ) ;",
  44.   "  system( \"/tmp/foo.exe\" ) ;",
  45.   "  system( \"rm /tmp/foo.exe\" ) ;"
  46.   "  return 0 ;",
  47.   "  }",
  48.   NULL } ;
  49.  
  50. void ps( char *s[] ) {
  51.   int i ;
  52.   for( i = 0 ; s[i] != NULL ; i++ ) puts( s[i] ) ;
  53.   }
  54.  
  55. int main() {
  56.  
  57.   int c, nc = 0 ;
  58.  
  59.   ps( s1 ) ;
  60.  
  61.   while( (c = getchar()) != EOF ) {
  62.     if( nc++ % 16 == 0 ) putchar( '\n' ) ;
  63.     printf( "%3d, ", c ) ;
  64.     }
  65.  
  66.   ps( s2 ) ;
  67.   }
  68.  
  69. -- 
  70. [An intertialess drive] is not probable at all, at least in any extrapolation
  71. of present-day science.  But as far as I can determine, it cannot be proved
  72. absolutely impossible, and that is enough for me.        -E. E. "Doc" Smith
  73.