Changeset 3940
- Timestamp:
- Nov 10, 2014, 9:16:06 PM (10 years ago)
- Location:
- trunk/emx/src/emxomf
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/emx/src/emxomf/emxomfld.c ¶
r3731 r3940 728 728 729 729 if ( ( uBuf.OmfHdr.len >= sizeof(uBuf.OmfHdr) 730 && cbRead > sizeof( sizeof(uBuf.OmfHdr)) )730 && cbRead > sizeof(uBuf.OmfHdr) ) 731 731 && ( uBuf.OmfHdr.type == THEADR 732 732 /*|| uBuf.OmfHdr.type == LIBADR - doubt wlink can handle this */) -
TabularUnified trunk/emx/src/emxomf/emxomfstrip.c ¶
r3939 r3940 19 19 #include <string.h> 20 20 #include <sys/stat.h> 21 #include <sys/omflib.h> 21 22 #if defined(_MSC_VER) || defined(__WATCOMC__) 22 23 # include <io.h> 24 # define ftruncate _chsize 23 25 #endif 26 27 24 28 25 29 /******************************************************************************* … … 58 62 unsigned cbThis = cb < sizeof(abBuf) ? (unsigned)cb : sizeof(abBuf); 59 63 if (fread(abBuf, cbThis, 1, pSrc) != 1) 60 return error(" Read error (@%#lx) from'%s': %s\n", offSrc, pszSrcName, strerror(errno));61 if (fwrite(abBuf, cbThis, 1, p Src) != 1)62 return error(" Write error to'%s': %s\n", pszDstName, strerror(errno));64 return error("fread (@%#lx) failed on '%s': %s\n", offSrc, pszSrcName, strerror(errno)); 65 if (fwrite(abBuf, cbThis, 1, pDst) != 1) 66 return error("fwrite failed on '%s': %s\n", pszDstName, strerror(errno)); 63 67 cb -= cbThis; 64 68 offSrc += cbThis; 65 69 } 66 70 return 0; 71 } 72 73 74 static int isNbSignature(byte const *pbMagic) 75 { 76 return pbMagic[0] == 'N' 77 && pbMagic[1] == 'B' 78 && pbMagic[2] >= '0' && pbMagic[2] <= '1' 79 && pbMagic[3] >= '0' && pbMagic[3] <= '9'; 80 } 81 82 83 static int isLxDebugInfoSignature(byte const *pbMagic) 84 { 85 return isNbSignature(pbMagic); 67 86 } 68 87 … … 89 108 struct exe1p2_header mz; 90 109 struct os2_header lx; 110 byte abBuf[32]; 91 111 } uHdr; 92 112 union … … 120 140 return error("Failed to read the header of '%s': %s\n", pOpts->pszInFile, strerror(errno)); 121 141 } 142 else if ( uHdr.abBuf[0] == THEADR 143 && (uHdr.abBuf[1] > 3 || uHdr.abBuf[2]) ) 144 return error("%s: Stripping OMF object files is not currently supported!\n", pOpts->pszInFile); 145 else if ( uHdr.abBuf[0] == LIBHDR 146 && (uHdr.abBuf[1] > 3 || uHdr.abBuf[2]) ) 147 return error("%s: Stripping OMF library files is not currently supported!\n", pOpts->pszInFile); 122 148 else 123 149 return error("Header of '%s' is not recognized (%#x)\n", pOpts->pszInFile, uHdr.mz.e_magic); … … 128 154 */ 129 155 if ( uHdr.lx.debug_offset != 0 130 && uHdr.lx.debug_size != 0 )131 { 132 offDbg = uHdr.lx.debug_offset + offLX;156 && uHdr.lx.debug_size != 0 && 0) 157 { 158 offDbg = uHdr.lx.debug_offset; 133 159 cbDbg = uHdr.lx.debug_size; 160 if ( offDbg > StIn.st_size 161 || cbDbg > StIn.st_size 162 || (off_t)offDbg + cbDbg > StIn.st_size) 163 return error("Debug info indicated by the LX header of '%s' makes no sense! (%#lx + %#lx = %#lx (file: %#x)\n", 164 pOpts->pszInFile, offDbg, cbDbg, offDbg + cbDbg, (unsigned long)StIn.st_size); 165 166 if ( fseek(pInFile, offDbg, SEEK_SET) != 0 167 || fread(&uBuf, 4, 1, pInFile) != 1) 168 return error("Error seeking/reading debug info header (@%#lx) in '%s': %s\n", 169 offDbg, pOpts->pszInFile, strerror(errno)); 170 if (!isLxDebugInfoSignature(uBuf.abBuf)) 171 { 172 /* Try add the LX offset. */ 173 if ( fseek(pInFile, offDbg + offLX, SEEK_SET) == 0 174 && fread(&uBuf.abBuf[4], 4, 1, pInFile) == 0 175 && isLxDebugInfoSignature(&uBuf.abBuf[4])) 176 offDbg += offLX; 177 else 178 return error("Debug info indicated by the LX header of '%s' is not recognized! (magic: %02x %02x %02x %02x)\n", 179 pOpts->pszInFile, uBuf.abBuf[0], uBuf.abBuf[1], uBuf.abBuf[2], uBuf.abBuf[3]); 180 } 181 134 182 if (offDbg + cbDbg != StIn.st_size) /* (This can be relaxed if we wish.) */ 135 return error("Debug info indicated by the LX header is not at the end of '%s'\n", pOpts->pszInFile); 183 return error("Debug info indicated by the LX header is not at the end of '%s'! (%#lx + %#lx = %#lx (file: %#x)\n", 184 pOpts->pszInFile, offDbg, cbDbg, offDbg + cbDbg, (unsigned long)StIn.st_size); 136 185 } 137 186 /* … … 144 193 if (fread(&uBuf, 8, 1, pInFile) != 1) 145 194 return error("Error reading last 8 bytes of '%s': %s\n", pOpts->pszInFile, strerror(errno)); 146 if ( uBuf.abBuf[0] == 'N' 147 && uBuf.abBuf[1] == 'B' 148 && uBuf.abBuf[2] >= '0' && uBuf.abBuf[2] <= '9' 149 && uBuf.abBuf[3] >= '0' && uBuf.abBuf[3] <= '9') 195 if (isNbSignature(uBuf.abBuf)) 150 196 { 151 197 int iVer = (uBuf.abBuf[2] - '0') * 10 + (uBuf.abBuf[3] - '0'); … … 159 205 pOpts->pszInFile, cbDbg, (unsigned long)StIn.st_size); 160 206 offDbg = (unsigned long)StIn.st_size - cbDbg; 161 } 162 } 163 164 /* 165 * Anything to strip? 207 208 if ( fseek(pInFile, offDbg, SEEK_SET) != 0 209 || fread(&uBuf.abBuf[4], 4, 1, pInFile) != 1) 210 return error("Error seeking/reading debug info header (@%#lx) in '%s': %s\n", 211 offDbg, pOpts->pszInFile, strerror(errno)); 212 if (uBuf.adwBuf[0] != uBuf.adwBuf[1]) 213 return error("Debug header does not match trailer in '%s': %02x %02x %02x %02x != %02x %02x %02x %02x\n", 214 pOpts->pszInFile, 215 uBuf.abBuf[0], uBuf.abBuf[1], uBuf.abBuf[2], uBuf.abBuf[3], 216 uBuf.abBuf[4+0], uBuf.abBuf[4+1], uBuf.abBuf[4+2], uBuf.abBuf[4+3]); 217 } 218 } 219 220 /* 221 * Did we find anything to strip? If not return immediately indicating this. 166 222 */ 167 223 if (cbDbg == 0) … … 205 261 * Truncate the output file if it's the same as the input. 206 262 */ 207 if (rc == 0 && pOutFile != pInFile) 208 { 209 #if defined(_MSC_VER) || defined(__WATCOMC__) 210 if (_chsize(fileno(pOutFile), offDbg) == 0) 211 #else 212 if (ftruncate(fileno(pOutFile), offDbg) == 0) 213 #endif 263 if (rc == 0 && pOutFile == pInFile) 264 { 265 if (ftruncate(fileno(pOutFile), offDbg) != 0) 214 266 return error("Error truncating '%s': %s\n", pOpts->pszInFile, strerror(errno)); 215 267 } … … 248 300 * Parse the options. 249 301 */ 250 while ((ch = getopt_long(argc, argv, "dD:g sSxXvV", NULL, NULL)) != EOF)302 while ((ch = getopt_long(argc, argv, "dD:go:sSxXvV", NULL, NULL)) != EOF) 251 303 { 252 304 switch (ch) … … 275 327 printf(VERSION INNOTEK_VERSION "\n"); 276 328 return 0; 329 330 default: 331 return usage(stderr, 1); 277 332 } 278 333 } … … 287 342 * Process the files. 288 343 */ 289 while (optind < argc) 344 while ( optind < argc 345 && rcExit == 0) 290 346 { 291 347 /* Open the input and maybe output file. */ … … 302 358 int fNull = 0; 303 359 FILE *pOutFile; 304 if (Opts.pszOutFile) 360 if (!Opts.pszOutFile) 361 pOutFile = pInFile; 362 else 305 363 { 306 364 if (strcmp(Opts.pszOutFile, "/dev/null")) … … 317 375 FILE *pDbgFile = NULL; 318 376 if (Opts.pszDbgFile) 319 pDbgFile = fopen(Opts.psz OutFile, "wb");377 pDbgFile = fopen(Opts.pszDbgFile, "wb"); 320 378 if (pDbgFile || !Opts.pszDbgFile) 321 379 { … … 337 395 } 338 396 else 339 rcExit = error("Failed opening outputfile '%s': %s\n", Opts.pszDbgFile, strerror(errno));397 rcExit = error("Failed opening debug info file '%s': %s\n", Opts.pszDbgFile, strerror(errno)); 340 398 if (pOutFile && pOutFile != pInFile && fclose(pOutFile) != 0) 341 399 rcExit = error("fclose failed on '%s': %s\n", Opts.pszOutFile, strerror(errno)); … … 348 406 else 349 407 rcExit = error("Failed opening '%s': %s\n", Opts.pszInFile, strerror(errno)); 408 optind++; 350 409 } 351 410
Note:
See TracChangeset
for help on using the changeset viewer.