int main(int argc, char *argv[]) { char *opt = NULL; int verbose = 0, fipsmode = 1, i = 0; FILE *fp = NULL; /* Process command line arguments */ i = 0; while(++i < argc) { opt = argv[i]; if (0 /*match*/ == strcmp(opt,"-v")) verbose = 1; else if (0 /*match*/ == strcmp(opt,"-c")) fipsmode = 0; else if ('-' == opt[0]) { doUsage(argv[0]); exit(1); } else break; } /* Enter FIPS mode by default */ if (fipsmode) { if(verbose) { printf("Attempting FIPS mode...\n"); } if(FIPS_mode_set(1)) { if(verbose) { printf("FIPS mode enabled\n"); } } else { ERR_load_crypto_strings(); ERR_print_errors_fp(stderr); exit(2); } } /* If no file arguments, process stdin */ if (i >= argc) { doFile(stdin); } else { while((i < argc) && (opt = argv[i++])) { if ((fp = fopen(opt,"rb")) == NULL) { fprintf(stderr,"Unable to open file \"%s\"\n", opt); exit(1); } if(verbose) { printf("%s: ", opt); } doFile(fp); fclose(fp), fp = NULL; } } return 0; }
int main( int argc, char *argv[] ) { int in, out, i, rcparm = 0, pcnt; int Rflag = FALSE, nflag = FALSE; int uflag = FALSE; int dllflag = FALSE; char *wext = NULL; long tsize = 0; char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME]; char ext[_MAX_EXT]; char rex[_MAX_PATH]; char exe[_MAX_PATH]; char dll[_MAX_PATH]; char res[_MAX_PATH]; char winext[_MAX_PATH]; char rc[256]; long totalsize; const char **arglist; char *path = NULL; int currarg,len; simple_header re; long exelen; char *desc = NULL; /* * get parms */ if( argc < 2 ) { doUsage( NULL ); } currarg=1; while( currarg < argc ) { #ifdef __UNIX__ if( argv[ currarg ][0] == '-' ) { #else if( argv[ currarg ][0] == '/' || argv[ currarg ][0] == '-' ) { #endif len = strlen( argv[ currarg ] ); for( i=1; i<len; i++ ) { switch( argv[ currarg ][i] ) { case '?': doUsage( NULL ); case 'D': currarg++; desc = argv[ currarg ]; break; case 's': currarg++; wext = argv[ currarg ]; break; case 'q': quietFlag = TRUE; break; case 'u': uflag = TRUE; break; case 'n': nflag = TRUE; break; case 'd': dllflag = TRUE; break; case 'R': case 'r': Rflag=TRUE; rcparm = currarg+1; if( rcparm == argc ) { doUsage("must specify resource compiler command line" ); } break; } } if( Rflag ) { break; } } else { if( path != NULL ) { doUsage( "Only one executable may be specified" ); } path = argv[ currarg ]; } currarg++; } if( path == NULL ) { doUsage( "No executable to bind" ); } doBanner(); /* * get files to use */ _splitpath( path, drive, dir, fname, ext ); _makepath( rex, drive, dir, fname, ".rex" ); if( dllflag ) { _makepath( dll, drive, dir, fname, ".dll" ); } _makepath( exe, drive, dir, fname, ".exe" ); _makepath( res, drive, dir, fname, "" ); /* * do the unbind */ if( uflag ) { if( ext[0] == 0 ) { path = exe; } in = open( path, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", path ); } out = open( rex, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, PMODE_RWX ); if( out < 0 ) { doError( "Could not open %s", rex ); } lseek( in, MAGIC_OFFSET, SEEK_SET ); read( in, &exelen, sizeof( unsigned_32 ) ); lseek( in, exelen, SEEK_SET ); read( in, &re, sizeof( re ) ); if( re.signature != ('M' & ('Q' << 8)) ) { doError( "Not a bound Open Watcom 32-bit Windows application" ); } lseek( in, exelen, SEEK_SET ); CopyFile( in, out, path, rex ); close( in ); close( out ); myPrintf( ".rex file %s created", rex ); exit( 0 ); } if( wext == NULL ) { if( dllflag ) { FindExtender( "w386dll.ext", winext ); } else { FindExtender( "win386.ext", winext ); } } else { strcpy( winext, wext ); } if( dllflag ) { myPrintf("Loading 32-bit Windows DLL Supervisor \"%s\"\n",winext ); } else { myPrintf("Loading 32-bit Windows Supervisor \"%s\"\n",winext ); } /* * open files */ in = open( winext, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", winext ); } out = open( exe, O_CREAT | O_TRUNC|O_WRONLY | O_BINARY, PMODE_RWX ); if( out < 0 ) { doError( "Could not open %s", exe ); } /* * copy extender over */ CopyFile( in, out, winext, exe ); close( in ); close( out ); /* * run the resource compiler */ if( !nflag ) { myPrintf( "Invoking the resource compiler...\n" ); if( Rflag ) { strcpy( rc, RC_STR ); arglist = myAlloc( sizeof(char *) *(argc-rcparm +3) ); pcnt = 1; for( i=rcparm;i<argc;i++ ) { arglist[pcnt++] = argv[i]; strcat( rc," " ); strcat( rc, argv[i] ); } } else { sprintf( rc, RC_STR " %s", res ); arglist = myAlloc( sizeof(char *) * 3 ); arglist[1] = res; pcnt = 2; } arglist[0] = RC_STR; arglist[pcnt] = NULL; myPrintf( "%s\n",rc ); i = spawnvp( P_WAIT, RC_STR, arglist ); if( i == -1 ) { remove( exe ); switch( errno ) { case E2BIG: doError( "Argument list too big. Resource compiler step failed." ); break; case ENOENT: doError( "Could not find " RC_STR ".exe." ); break; case ENOMEM: doError( "Not enough memory. Resource compiler step failed." ); break; } doError( "Unknown error %d, resource compiler step failed.", errno ); } if( i != 0 ) { remove( exe ); errPrintf( "Resource compiler failed, return code = %d\n", i ); exit( i ); } } /* * copy the rex file onto the end */ in = open( rex, O_RDONLY | O_BINARY ); if( in < 0 ) { doError( "Could not open %s", rex ); } out = open( exe, O_RDWR | O_BINARY ); if( out < 0 ) { doError( "Could not open %s", exe ); } lseek( out, 0, SEEK_END ); tsize = tell( out ); totalsize = CopyFile( in, out, rex, exe ); close( in ); /* * noodle the file: change name, and then * write the file size into the old exe header (for * use by the loader) */ lseek( out, MAGIC_OFFSET, SEEK_SET ); write( out, &tsize, sizeof( tsize ) ); len = strlen( fname ); memset( &fname[len],' ',8-len ); updateNHStuff( out, fname, desc ); close( out ); if( dllflag ) { remove( dll ); rename( exe,dll ); myPrintf("Created \"%s\" (%ld + %ld = %ld bytes)\n", dll, tsize,totalsize, tsize+totalsize ); } else { myPrintf("Created \"%s\" (%ld + %ld = %ld bytes)\n", exe, tsize,totalsize, tsize+totalsize ); } return( 0 ); } /* main */