home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!sun-barr!ames!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: Program to convert .EXE to a "C" source file? I really need one!!
- Message-ID: <1993Jan7.235516.16627@organpipe.uug.arizona.edu>
- Date: 7 Jan 93 23:55:16 GMT
- 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>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 59
- In-Reply-To: ujd@pool.info.sunyit.edu (Jacek Dziembaj)
-
- /* Use: bin2c <infile.exe >outfile.c
- *
- * Note: this includes a few UN*Xisms, but I'm sure equivalent calls can
- * be substituted on other systems. Also, you should probably generate
- * random names (particularly under multitasking systems) instead of
- * relying on "/tmp/foo.exe" to be non-existant.
- */
-
- #include <stdio.h>
-
- char *s1[] = {
- "#include <stdio.h>",
- "",
- "int bytes[] = {",
- NULL
- } ;
-
- char *s2[] = {
- "-1 } ;",
- "",
- "int main() {",
- " int i ;",
- " FILE *f = fopen(\"/tmp/foo.exe\",\"w\") ;",
- " if( f == NULL ) {",
- " fprintf( stderr, \"FATAL ERROR: can't open temp file\\n\" ) ; exit(1) ;"
- " }",
- " for( i = 0 ; bytes[i] >= 0 ; i++ )",
- " fputc( bytes[i], f ) ;",
- " fclose(f) ;",
- " system( \"chmod +x /tmp/foo.exe\" ) ;",
- " system( \"/tmp/foo.exe\" ) ;",
- " system( \"rm /tmp/foo.exe\" ) ;"
- " return 0 ;",
- " }",
- NULL } ;
-
- void ps( char *s[] ) {
- int i ;
- for( i = 0 ; s[i] != NULL ; i++ ) puts( s[i] ) ;
- }
-
- int main() {
-
- int c, nc = 0 ;
-
- ps( s1 ) ;
-
- while( (c = getchar()) != EOF ) {
- if( nc++ % 16 == 0 ) putchar( '\n' ) ;
- printf( "%3d, ", c ) ;
- }
-
- ps( s2 ) ;
- }
-
- --
- [An intertialess drive] is not probable at all, at least in any extrapolation
- of present-day science. But as far as I can determine, it cannot be proved
- absolutely impossible, and that is enough for me. -E. E. "Doc" Smith
-