Changeset 127 for trunk/src/helpers/dosh2.c
- Timestamp:
- Jan 5, 2002, 8:11:10 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh2.c
r126 r127 65 65 #include "helpers\dosh.h" 66 66 #include "helpers\ensure.h" 67 #include "helpers\nls.h" 67 68 #include "helpers\standards.h" 68 69 #include "helpers\stringh.h" … … 441 442 *@@changed V0.9.16 (2001-12-08) [umoeller]: fLibrary was never set, works for LX and NE now 442 443 *@@changed V0.9.16 (2001-12-08) [umoeller]: some speed optimizations, changed some return codes 444 *@@changed V0.9.16 (2002-01-04) [umoeller]: added fixes for COM, BAT, CMD extensions 443 445 */ 444 446 … … 446 448 PEXECUTABLE* ppExec) 447 449 { 448 APIRET arc = NO_ERROR; 449 450 ULONG ulAction = 0; 451 HFILE hFile; 450 APIRET arc = NO_ERROR; 451 452 452 PEXECUTABLE pExec = NULL; 453 454 PXFILE pFile = NULL; 455 ULONG cbFile = 0; 456 PCSZ pExt; 457 BOOL fOpenFile = FALSE; 453 458 454 459 if (!ppExec) … … 460 465 memset(pExec, 0, sizeof(EXECUTABLE)); 461 466 462 if (!(arc = DosOpen((PSZ)pcszExecutable, 463 &hFile, 464 &ulAction, // out: action taken 465 0, // in: new file (ignored for read-mode) 466 0, // in: new file attribs (ignored) 467 // open-flags 468 OPEN_ACTION_FAIL_IF_NEW 469 | OPEN_ACTION_OPEN_IF_EXISTS, 470 // open-mode 471 OPEN_FLAGS_FAIL_ON_ERROR // report errors to caller 472 | OPEN_FLAGS_SEQUENTIAL 473 | OPEN_FLAGS_NOINHERIT 474 // | OPEN_SHARE_DENYNONE 475 | OPEN_SHARE_DENYWRITE // changed V0.9.16 (2001-12-08) [umoeller] 476 | OPEN_ACCESS_READONLY, // read-only mode 477 NULL))) // no EAs 467 // check some of the default extensions 468 // V0.9.16 (2002-01-04) [umoeller] 469 if (pExt = doshGetExtension(pcszExecutable)) 470 { 471 if (!stricmp(pExt, "COM")) 472 { 473 // I am not willing to find out more about the 474 // .COM executable format, so for this one case, 475 // let OS/2 determine what we have here 476 ULONG ulDosAppType = 0; 477 if (!(arc = DosQueryAppType((PSZ)pcszExecutable, &ulDosAppType))) 478 { 479 if (ulDosAppType & FAPPTYP_DOS) // 0x20 480 pExec->ulOS = EXEOS_DOS3; 481 else 482 pExec->ulOS = EXEOS_OS2; 483 484 pExec->ulExeFormat = EXEFORMAT_COM; 485 } 486 } 487 else if (!stricmp(pExt, "BAT")) 488 { 489 pExec->ulOS = EXEOS_DOS3; 490 pExec->ulExeFormat = EXEFORMAT_TEXT_BATCH; 491 } 492 else if (!stricmp(pExt, "CMD")) 493 { 494 pExec->ulOS = EXEOS_OS2; 495 pExec->ulExeFormat = EXEFORMAT_TEXT_CMD; 496 } 497 else 498 fOpenFile = TRUE; 499 } 500 501 if ( (fOpenFile) 502 && (!(arc = doshOpen((PSZ)pcszExecutable, 503 XOPEN_READ_EXISTING, 504 &cbFile, 505 &pFile))) 506 ) 478 507 { 479 508 // file opened successfully: 509 pExec->pFile = pFile; 480 510 481 511 // read old DOS EXE header … … 485 515 { 486 516 pExec->cbDosExeHeader = sizeof(DOSEXEHEADER); 487 if (!(arc = doshReadAt( hFile,517 if (!(arc = doshReadAt(pFile, 488 518 0, 489 FILE_BEGIN,490 519 &pExec->cbDosExeHeader, // in/out 491 520 (PBYTE)pExec->pDosExeHeader))) … … 554 583 if (!(pbHeader = (PBYTE)malloc(cbRead))) 555 584 arc = ERROR_NOT_ENOUGH_MEMORY; 556 else if (!(arc = doshReadAt( hFile,585 else if (!(arc = doshReadAt(pFile, 557 586 ulNewHeaderOfs, 558 FILE_BEGIN,559 587 &cbRead, 560 588 pbHeader))) … … 626 654 // plus an extended header, so check what 627 655 // we've got 628 ULONG cbPE = 24629 + ((PPEHEADER)pbHeader)->usHeaderSize;656 ULONG cbPE = sizeof(PEHEADER); // 24 657 // + ((PPEHEADER)pbHeader)->usHeaderSize; 630 658 pExec->pPEHeader = (PPEHEADER)realloc(pbHeader, 631 659 cbPE); … … 635 663 pExec->f32Bits = TRUE; 636 664 665 /* 637 666 // we have the first 24 bytes already, so 638 // go for the next chunk 639 if (cbRead = pExec->pPEHeader->usHeaderSize) 667 // go for the next chunk, if this is more 668 // than we have in PEHEADER 669 if ( (cbRead < cbPE) 670 && (cbRead = pExec->pPEHeader->usHeaderSize) 671 ) 640 672 { 673 _Pmpf((" usHdrSize %d, sizeof(PEHEADER) %d, cbRead %d, cbPE %d --> reading extended header", 674 pExec->pPEHeader->usHeaderSize, 675 sizeof(PEHEADER), 676 cbRead, 677 cbPE)); 641 678 if (!(arc = doshReadAt(hFile, 642 679 ulNewHeaderOfs + 24, … … 647 684 } 648 685 else 686 { 649 687 arc = ERROR_BAD_EXE_FORMAT; 688 FREE(pExec->pPEHeader); 689 } 650 690 } 691 else 692 _Pmpf((" already got extended header")); 693 */ 651 694 } 652 695 } 653 696 else 697 { 654 698 // strange type: 655 699 arc = ERROR_INVALID_EXE_SIGNATURE; 656 657 if (pbCheckOS) 700 FREE(pbHeader); 701 } 702 703 if ((!arc) && (pbCheckOS)) 658 704 { 659 705 // BYTE to check for operating system … … 681 727 } 682 728 } 683 } 684 } 685 } // end if (!(arc = DosSetFilePtr(hFile, 686 } // end if pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER)); 687 688 // store exec's HFILE 689 pExec->hfExe = hFile; 729 } // end if (!(arc = doshReadAt(hFile, 730 } // end if (fLoadNewHeader) 731 } // end if (!(arc = doshReadAt(hFile, 732 } // end else if (!(pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER)))) 733 690 734 } // end if (!(arc = DosOpen((PSZ)pcszExecutable, 691 735 … … 941 985 else 942 986 { 987 PXFILE pFile = pExec->pFile; 988 943 989 ULONG ulNRNTOfs = 0; 944 990 … … 978 1024 // move EXE file pointer to offset of non-resident name table 979 1025 // (from LX header) 980 if (!(arc = DosSetFilePtr(p Exec->hfExe, // file is still open1026 if (!(arc = DosSetFilePtr(pFile->hf, // file is still open 981 1027 ulNRNTOfs, // ofs determined above 982 1028 FILE_BEGIN, … … 990 1036 else 991 1037 { 992 if (!(arc = DosRead(p Exec->hfExe,1038 if (!(arc = DosRead(pFile->hf, 993 1039 pszNameTable, 994 1040 2000, … … 1069 1115 PFSYSMODULE paModules = NULL; 1070 1116 int i; 1117 HFILE hfExe = pExec->pFile->hf; 1071 1118 1072 1119 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] … … 1092 1139 memset(paModules, 0, cb); // V0.9.9 (2001-04-03) [umoeller] 1093 1140 1094 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1141 ENSURE_SAFE(DosSetFilePtr(hfExe, 1095 1142 pExec->pLXHeader->ulImportModTblOfs 1096 1143 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1103 1150 1104 1151 // reading the length of the module name 1105 ENSURE_SAFE(DosRead( pExec->hfExe, &bLen, 1, &ulDummy));1152 ENSURE_SAFE(DosRead(hfExe, &bLen, 1, &ulDummy)); 1106 1153 1107 1154 // reading the module name 1108 ENSURE_SAFE(DosRead( pExec->hfExe,1155 ENSURE_SAFE(DosRead(hfExe, 1109 1156 paModules[i].achModuleName, 1110 1157 bLen, … … 1143 1190 // then we read the name in the import table 1144 1191 1145 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1192 ENSURE_SAFE(DosSetFilePtr(hfExe, 1146 1193 pExec->pNEHeader->usModRefTblOfs 1147 1194 + ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller] … … 1150 1197 &ulDummy)); 1151 1198 1152 ENSURE_SAFE(DosRead( pExec->hfExe, &usOfs, 2, &ulDummy));1153 1154 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1199 ENSURE_SAFE(DosRead(hfExe, &usOfs, 2, &ulDummy)); 1200 1201 ENSURE_SAFE(DosSetFilePtr(hfExe, 1155 1202 pExec->pNEHeader->usImportTblOfs 1156 1203 + ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller] … … 1159 1206 &ulDummy)); 1160 1207 1161 ENSURE_SAFE(DosRead( pExec->hfExe, &bLen, 1, &ulDummy));1162 1163 ENSURE_SAFE(DosRead( pExec->hfExe,1208 ENSURE_SAFE(DosRead(hfExe, &bLen, 1, &ulDummy)); 1209 1210 ENSURE_SAFE(DosRead(hfExe, 1164 1211 paModules[i].achModuleName, 1165 1212 bLen, … … 1224 1271 1225 1272 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1273 HFILE hfExe = pExec->pFile->hf; 1226 1274 1227 1275 if (pExec->pDosExeHeader) … … 1229 1277 ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs; 1230 1278 1231 ENSURE(DosSetFilePtr( pExec->hfExe,1279 ENSURE(DosSetFilePtr(hfExe, 1232 1280 pExec->pLXHeader->ulEntryTblOfs 1233 1281 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1241 1289 bFlag; 1242 1290 1243 ENSURE(DosRead( pExec->hfExe, &bCnt, 1, &ulDummy));1291 ENSURE(DosRead(hfExe, &bCnt, 1, &ulDummy)); 1244 1292 1245 1293 if (bCnt == 0) … … 1247 1295 break; 1248 1296 1249 ENSURE(DosRead( pExec->hfExe, &bType, 1, &ulDummy));1297 ENSURE(DosRead(hfExe, &bType, 1, &ulDummy)); 1250 1298 1251 1299 switch (bType & 0x7F) … … 1269 1317 1270 1318 case 1: 1271 ENSURE(DosSetFilePtr( pExec->hfExe,1319 ENSURE(DosSetFilePtr(hfExe, 1272 1320 sizeof(USHORT), 1273 1321 FILE_CURRENT, … … 1276 1324 for (i = 0; i < bCnt; i ++) 1277 1325 { 1278 ENSURE(DosRead( pExec->hfExe, &bFlag, 1, &ulDummy));1326 ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy)); 1279 1327 1280 1328 if (bFlag & 0x01) … … 1291 1339 usOrdinal++; 1292 1340 1293 ENSURE(DosSetFilePtr( pExec->hfExe,1341 ENSURE(DosSetFilePtr(hfExe, 1294 1342 sizeof(USHORT), 1295 1343 FILE_CURRENT, … … 1308 1356 1309 1357 case 2: 1310 ENSURE(DosSetFilePtr( pExec->hfExe,1358 ENSURE(DosSetFilePtr(hfExe, 1311 1359 sizeof(USHORT), 1312 1360 FILE_CURRENT, … … 1315 1363 for (i = 0; i < bCnt; i ++) 1316 1364 { 1317 ENSURE(DosRead( pExec->hfExe, &bFlag, 1, &ulDummy));1365 ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy)); 1318 1366 1319 1367 if (bFlag & 0x01) … … 1330 1378 usOrdinal++; 1331 1379 1332 ENSURE(DosSetFilePtr( pExec->hfExe,1380 ENSURE(DosSetFilePtr(hfExe, 1333 1381 sizeof(USHORT) + sizeof(USHORT), 1334 1382 FILE_CURRENT, … … 1347 1395 1348 1396 case 3: 1349 ENSURE(DosSetFilePtr( pExec->hfExe,1397 ENSURE(DosSetFilePtr(hfExe, 1350 1398 sizeof(USHORT), 1351 1399 FILE_CURRENT, … … 1354 1402 for (i = 0; i < bCnt; i ++) 1355 1403 { 1356 ENSURE(DosRead( pExec->hfExe, &bFlag, 1, &ulDummy));1404 ENSURE(DosRead(hfExe, &bFlag, 1, &ulDummy)); 1357 1405 1358 1406 if (bFlag & 0x01) … … 1369 1417 usOrdinal++; 1370 1418 1371 ENSURE(DosSetFilePtr( pExec->hfExe,1419 ENSURE(DosSetFilePtr(hfExe, 1372 1420 sizeof(ULONG), 1373 1421 FILE_CURRENT, … … 1385 1433 1386 1434 case 4: 1387 ENSURE(DosSetFilePtr( pExec->hfExe,1435 ENSURE(DosSetFilePtr(hfExe, 1388 1436 sizeof(USHORT), 1389 1437 FILE_CURRENT, … … 1392 1440 for (i = 0; i < bCnt; i ++) 1393 1441 { 1394 ENSURE(DosSetFilePtr( pExec->hfExe,1442 ENSURE(DosSetFilePtr(hfExe, 1395 1443 sizeof(BYTE) + sizeof(USHORT) + sizeof(ULONG), 1396 1444 FILE_CURRENT, … … 1464 1512 1465 1513 ULONG ulNewHeaderOfs = 0; 1514 HFILE hfExe = pExec->pFile->hf; 1466 1515 1467 1516 if (pExec->pDosExeHeader) … … 1469 1518 ulNewHeaderOfs = pExec->pDosExeHeader->ulNewHeaderOfs; 1470 1519 1471 ENSURE(DosSetFilePtr( pExec->hfExe,1520 ENSURE(DosSetFilePtr(hfExe, 1472 1521 pExec->pNEHeader->usEntryTblOfs 1473 1522 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1481 1530 bFlag; 1482 1531 1483 ENSURE(DosRead( pExec->hfExe, &bCnt, 1, &ulDummy));1532 ENSURE(DosRead(hfExe, &bCnt, 1, &ulDummy)); 1484 1533 1485 1534 if (bCnt == 0) … … 1487 1536 break; 1488 1537 1489 ENSURE(DosRead( pExec->hfExe, &bType, 1, &ulDummy));1538 ENSURE(DosRead(hfExe, &bType, 1, &ulDummy)); 1490 1539 1491 1540 if (bType) … … 1493 1542 for (i = 0; i < bCnt; i++) 1494 1543 { 1495 ENSURE(DosRead( pExec->hfExe,1544 ENSURE(DosRead(hfExe, 1496 1545 &bFlag, 1497 1546 1, … … 1514 1563 { 1515 1564 // moveable segment 1516 ENSURE(DosSetFilePtr( pExec->hfExe,1565 ENSURE(DosSetFilePtr(hfExe, 1517 1566 5, 1518 1567 FILE_CURRENT, … … 1522 1571 { 1523 1572 // fixed segment or constant (0xFE) 1524 ENSURE(DosSetFilePtr( pExec->hfExe,1573 ENSURE(DosSetFilePtr(hfExe, 1525 1574 2, 1526 1575 FILE_CURRENT, … … 1585 1634 USHORT usOrdinal; 1586 1635 PFSYSFUNCTION pFunction; 1636 HFILE hfExe = pExec->pFile->hf; 1587 1637 1588 1638 while (TRUE) … … 1592 1642 // int i; 1593 1643 1594 ENSURE(DosRead( pExec->hfExe, &bLen, 1, &ulDummy));1644 ENSURE(DosRead(hfExe, &bLen, 1, &ulDummy)); 1595 1645 1596 1646 if (bLen == 0) … … 1598 1648 break; 1599 1649 1600 ENSURE(DosRead( pExec->hfExe, &achName, bLen, &ulDummy));1650 ENSURE(DosRead(hfExe, &achName, bLen, &ulDummy)); 1601 1651 achName[bLen] = 0; 1602 1652 1603 ENSURE(DosRead( pExec->hfExe, &usOrdinal, sizeof(USHORT), &ulDummy));1653 ENSURE(DosRead(hfExe, &usOrdinal, sizeof(USHORT), &ulDummy)); 1604 1654 1605 1655 if ((pFunction = (PFSYSFUNCTION)bsearch(&usOrdinal, … … 1668 1718 ULONG ulDummy; 1669 1719 1720 HFILE hfExe = pExec->pFile->hf; 1670 1721 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1671 1722 … … 1702 1753 // we now scan the resident name table entries 1703 1754 1704 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1755 ENSURE_SAFE(DosSetFilePtr(hfExe, 1705 1756 pExec->pLXHeader->ulResdNameTblOfs 1706 1757 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1713 1764 // whose offset is _from the begining of the file_ 1714 1765 1715 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1766 ENSURE_SAFE(DosSetFilePtr(hfExe, 1716 1767 pExec->pLXHeader->ulNonResdNameTblOfs, 1717 1768 FILE_BEGIN, … … 1750 1801 // we now scan the resident name table entries 1751 1802 1752 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1803 ENSURE_SAFE(DosSetFilePtr(hfExe, 1753 1804 pExec->pNEHeader->usResdNameTblOfs 1754 1805 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1761 1812 // whose offset is _from the begining of the file_ 1762 1813 1763 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1814 ENSURE_SAFE(DosSetFilePtr(hfExe, 1764 1815 pExec->pNEHeader->ulNonResdTblOfs, 1765 1816 FILE_BEGIN, … … 1842 1893 PFSYSRESOURCE paResources = NULL; 1843 1894 1895 HFILE hfExe = pExec->pFile->hf; 1844 1896 ULONG ulNewHeaderOfs = 0; // V0.9.12 (2001-05-03) [umoeller] 1845 1897 … … 1886 1938 memset(paResources, 0, cb); // V0.9.9 (2001-04-03) [umoeller] 1887 1939 1888 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1940 ENSURE_SAFE(DosSetFilePtr(hfExe, 1889 1941 pLXHeader->ulResTblOfs 1890 1942 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1894 1946 for (i = 0; i < cResources; i++) 1895 1947 { 1896 ENSURE_SAFE(DosRead( pExec->hfExe, &rs, 14, &ulDummy));1948 ENSURE_SAFE(DosRead(hfExe, &rs, 14, &ulDummy)); 1897 1949 1898 1950 paResources[i].ulID = rs.name; … … 1912 1964 * (paResources[i].ulFlag - 1)); 1913 1965 1914 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,1966 ENSURE_SAFE(DosSetFilePtr(hfExe, 1915 1967 ulOfsThis, 1916 1968 FILE_BEGIN, 1917 1969 &ulDummy)); 1918 1970 1919 ENSURE_SAFE(DosRead( pExec->hfExe, &ot, sizeof(ot), &ulDummy));1971 ENSURE_SAFE(DosRead(hfExe, &ot, sizeof(ot), &ulDummy)); 1920 1972 1921 1973 paResources[i].ulFlag = ((ot.o32_flags & OBJWRITE) … … 1968 2020 // we first read the resources IDs and types 1969 2021 1970 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2022 ENSURE_SAFE(DosSetFilePtr(hfExe, 1971 2023 pNEHeader->usResTblOfs 1972 2024 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 1976 2028 for (i = 0; i < cResources; i++) 1977 2029 { 1978 ENSURE_SAFE(DosRead( pExec->hfExe, &rti, sizeof(rti), &ulDummy));2030 ENSURE_SAFE(DosRead(hfExe, &rti, sizeof(rti), &ulDummy)); 1979 2031 1980 2032 paResources[i].ulID = rti.name; … … 1986 2038 for (i = 0; i < cResources; i++) 1987 2039 { 1988 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2040 ENSURE_SAFE(DosSetFilePtr(hfExe, 1989 2041 ulNewHeaderOfs // V0.9.12 (2001-05-03) [umoeller] 1990 2042 + pNEHeader->usSegTblOfs … … 1996 2048 &ulDummy)); 1997 2049 1998 ENSURE_SAFE(DosRead( pExec->hfExe, &ns, sizeof(ns), &ulDummy));2050 ENSURE_SAFE(DosRead(hfExe, &ns, sizeof(ns), &ulDummy)); 1999 2051 2000 2052 paResources[i].ulSize = ns.ns_cbseg; … … 2013 2065 ULONG ulDummy; 2014 2066 2015 ENSURE(DosSetFilePtr( pExec->hfExe,2067 ENSURE(DosSetFilePtr(hfExe, 2016 2068 pNEHeader->usResTblOfs 2017 2069 + ulNewHeaderOfs, // V0.9.12 (2001-05-03) [umoeller] … … 2019 2071 &ulDummy)); 2020 2072 2021 ENSURE(DosRead( pExec->hfExe,2073 ENSURE(DosRead(hfExe, 2022 2074 &usAlignShift, 2023 2075 sizeof(usAlignShift), … … 2029 2081 USHORT usCount; 2030 2082 2031 ENSURE(DosRead( pExec->hfExe,2083 ENSURE(DosRead(hfExe, 2032 2084 &usTypeID, 2033 2085 sizeof(usTypeID), … … 2037 2089 break; 2038 2090 2039 ENSURE(DosRead( pExec->hfExe,2091 ENSURE(DosRead(hfExe, 2040 2092 &usCount, 2041 2093 sizeof(usCount), 2042 2094 &ulDummy)); 2043 2095 2044 ENSURE(DosSetFilePtr( pExec->hfExe,2096 ENSURE(DosSetFilePtr(hfExe, 2045 2097 sizeof(ULONG), 2046 2098 FILE_CURRENT, … … 2050 2102 2051 2103 // first pass, skip NAMEINFO table 2052 ENSURE(DosSetFilePtr( pExec->hfExe,2104 ENSURE(DosSetFilePtr(hfExe, 2053 2105 usCount*6*sizeof(USHORT), 2054 2106 FILE_CURRENT, … … 2067 2119 memset(paResources, 0, cb); 2068 2120 2069 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2121 ENSURE_SAFE(DosSetFilePtr(hfExe, 2070 2122 pNEHeader->usResTblOfs 2071 2123 + ulNewHeaderOfs, … … 2073 2125 &ulDummy)); 2074 2126 2075 ENSURE_SAFE(DosRead( pExec->hfExe,2127 ENSURE_SAFE(DosRead(hfExe, 2076 2128 &usAlignShift, 2077 2129 sizeof(usAlignShift), … … 2084 2136 int i; 2085 2137 2086 ENSURE_SAFE(DosRead( pExec->hfExe,2138 ENSURE_SAFE(DosRead(hfExe, 2087 2139 &usTypeID, 2088 2140 sizeof(usTypeID), … … 2092 2144 break; 2093 2145 2094 ENSURE_SAFE(DosRead( pExec->hfExe,2146 ENSURE_SAFE(DosRead(hfExe, 2095 2147 &usCount, 2096 2148 sizeof(usCount), 2097 2149 &ulDummy)); 2098 2150 2099 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2151 ENSURE_SAFE(DosSetFilePtr(hfExe, 2100 2152 sizeof(ULONG), 2101 2153 FILE_CURRENT, … … 2109 2161 usID; 2110 2162 2111 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2163 ENSURE_SAFE(DosSetFilePtr(hfExe, 2112 2164 sizeof(USHORT), 2113 2165 FILE_CURRENT, 2114 2166 &ulDummy)); 2115 2167 2116 ENSURE_SAFE(DosRead( pExec->hfExe,2168 ENSURE_SAFE(DosRead(hfExe, 2117 2169 &usLength, 2118 2170 sizeof(USHORT), 2119 2171 &ulDummy)); 2120 ENSURE_SAFE(DosRead( pExec->hfExe,2172 ENSURE_SAFE(DosRead(hfExe, 2121 2173 &usFlags, 2122 2174 sizeof(USHORT), 2123 2175 &ulDummy)); 2124 ENSURE_SAFE(DosRead( pExec->hfExe,2176 ENSURE_SAFE(DosRead(hfExe, 2125 2177 &usID, 2126 2178 sizeof(USHORT), 2127 2179 &ulDummy)); 2128 2180 2129 ENSURE_SAFE(DosSetFilePtr( pExec->hfExe,2181 ENSURE_SAFE(DosSetFilePtr(hfExe, 2130 2182 2*sizeof(USHORT), 2131 2183 FILE_CURRENT, … … 2234 2286 else 2235 2287 { 2288 PXFILE pFile = pExec->pFile; 2236 2289 ULONG ulNewHeaderOfs = 0; 2237 2290 ULONG cb; … … 2246 2299 (PBYTE*)&pExec->pRsTbl, 2247 2300 &cb))) 2248 && (!(arc = doshReadAt(p Exec->hfExe,2301 && (!(arc = doshReadAt(pFile, 2249 2302 pLXHeader->ulResTblOfs 2250 2303 + ulNewHeaderOfs, 2251 FILE_BEGIN,2252 2304 &cb, 2253 2305 (PBYTE)pExec->pRsTbl))) … … 2259 2311 (PBYTE*)&pExec->pObjTbl, 2260 2312 &cb))) 2261 && (!(arc = doshReadAt(p Exec->hfExe,2313 && (!(arc = doshReadAt(pFile, 2262 2314 pLXHeader->ulObjTblOfs 2263 2315 + ulNewHeaderOfs, 2264 FILE_BEGIN,2265 2316 &cb, 2266 2317 (PBYTE)pExec->pObjTbl))) … … 2272 2323 (PBYTE*)&pExec->pObjPageTbl, 2273 2324 &cb))) 2274 && (!(arc = doshReadAt(p Exec->hfExe,2325 && (!(arc = doshReadAt(pFile, 2275 2326 pLXHeader->ulObjPageTblOfs 2276 2327 + ulNewHeaderOfs, 2277 FILE_BEGIN,2278 2328 &cb, 2279 2329 (PBYTE)pExec->pObjPageTbl))) … … 2341 2391 else 2342 2392 { 2393 PXFILE pFile = pExec->pFile; 2343 2394 ULONG ulNewHeaderOfs = 0; 2344 2395 ULONG cb; … … 2353 2404 (PBYTE*)&pExec->paOS2NEResTblEntry, 2354 2405 &cb))) 2355 && (!(arc = doshReadAt(p Exec->hfExe,2406 && (!(arc = doshReadAt(pFile, 2356 2407 pNEHeader->usResTblOfs 2357 2408 + ulNewHeaderOfs, 2358 FILE_BEGIN,2359 2409 &cb, 2360 2410 (PBYTE)pExec->paOS2NEResTblEntry))) … … 2366 2416 (PBYTE*)&pExec->paOS2NESegments, 2367 2417 &cb))) 2368 && (!(arc = doshReadAt(p Exec->hfExe,2418 && (!(arc = doshReadAt(pFile, 2369 2419 pNEHeader->usResTblOfs 2370 2420 + ulNewHeaderOfs 2371 2421 - cb, // pNEHeader->usResSegmCount * sizeof(struct new_seg) 2372 FILE_BEGIN,2373 2422 &cb, 2374 2423 (PBYTE)pExec->paOS2NESegments))) … … 2461 2510 } 2462 2511 2463 if (pExec->hfExe) 2464 arc = DosClose(pExec->hfExe); 2512 doshClose(&pExec->pFile); 2465 2513 2466 2514 free(pExec); … … 4113 4161 } 4114 4162 } 4163 4164 /* 4165 *@@category: Helpers\Control program helpers\Wildcard matching 4166 * See doshMatch. 4167 */ 4168 4169 /* ****************************************************************** 4170 * 4171 * Wildcard matching 4172 * 4173 ********************************************************************/ 4174 4175 /* 4176 * PerformMatch: 4177 * compares a single path component. The input strings must 4178 * not have slashes or backslashes in them. 4179 * 4180 * fHasDot must be true if pName contains at least one dot. 4181 * 4182 * Note that this function is recursive. 4183 */ 4184 4185 BOOL PerformMatch(PCSZ pMask, 4186 PCSZ pName, 4187 int fHasDot) 4188 { 4189 while (TRUE) 4190 { 4191 // go thru the pMask char by char 4192 switch (*pMask) 4193 { 4194 case 0: 4195 // if we've reached the end of the mask, 4196 // we better have the end of the name too 4197 if (*pName == 0) 4198 return TRUE; 4199 return FALSE; 4200 4201 case '?': 4202 // a question mark matches one single character; 4203 // it does _not_ match a dot; 4204 // at the end of the component, it also matches 4205 // no characters 4206 if ( (*pName != '.') 4207 && (*pName != 0) 4208 ) 4209 ++pName; 4210 ++pMask; 4211 break; 4212 4213 case '*': 4214 // asterisk matches zero or more characters 4215 4216 // skip extra asterisks 4217 do 4218 { 4219 ++pMask; 4220 } while (*pMask == '*'); 4221 4222 // pMask points to after '*'; 4223 // pName is unchanged... so for each pName 4224 // that follows, check if it matches 4225 while (TRUE) 4226 { 4227 if (PerformMatch(pMask, pName, fHasDot)) 4228 // the remainder matched: 4229 // then everything matches 4230 return TRUE; 4231 4232 if (*pName == 0) 4233 return FALSE; 4234 4235 // didn't match: try next pName 4236 ++pName; 4237 } 4238 4239 case '.': 4240 // a dot matches a dot only, even if the name doesn't 4241 // have one at the end 4242 ++pMask; 4243 if (*pName == '.') 4244 ++pName; 4245 else if ( (fHasDot) 4246 || (*pName != 0) 4247 ) 4248 return FALSE; 4249 break; 4250 4251 default: 4252 if (*pMask++ != *pName++) 4253 return FALSE; 4254 break; 4255 } 4256 } 4257 } 4258 4259 /* 4260 *@@ doshMatch: 4261 * this matches '*' and '?' wildcards, similar to what 4262 * DosEditName does. It returns TRUE if the given name 4263 * matches the given mask. 4264 * 4265 * However, this does not require a file to be present, but 4266 * works on strings only. 4267 * 4268 * This accepts both short and fully qualified masks and 4269 * names, but the following rules apply: 4270 * 4271 * -- Either both the mask and the name must be fully 4272 * qualified, or both must not. Otherwise the match fails. 4273 * 4274 * -- If fully qualified, only the last component may contain 4275 * wildcards. 4276 * 4277 * -- This compares without respect to case always. 4278 * 4279 * -- As opposed to the WPS, this handles multiple dots in 4280 * filenames correctly. For example, the WPS will not 4281 * match "*.ZIP" against "whatever-0.9.3.zip", but this 4282 * one will. 4283 * 4284 * This replaces strhMatchOS2 which has been removed with 4285 * V0.9.16 and is a lot faster than the old code, which has 4286 * been completely rewritten. 4287 * 4288 *@@added V0.9.16 (2002-01-01) [umoeller] 4289 */ 4290 4291 BOOL doshMatch(const char *pcszMask, // in: mask (e.g. "*.txt") 4292 const char *pcszName) // in: string to check (e.g. "test.txt") 4293 { 4294 BOOL brc = FALSE; 4295 4296 int iMaskDrive = -1, 4297 iNameDrive = -1; 4298 4299 ULONG cbMask = strlen(pcszMask), 4300 cbName = strlen(pcszName); 4301 PSZ pszMask = (PSZ)_alloca(cbMask + 1), 4302 pszName = (PSZ)_alloca(cbName + 1); 4303 4304 PCSZ pLastMaskComponent, 4305 pLastNameComponent; 4306 4307 ULONG cbMaskPath = 0, 4308 cbNamePath = 0; 4309 4310 CHAR c; 4311 4312 memcpy(pszMask, pcszMask, cbMask + 1); 4313 nlsUpper(pszMask, cbMask); 4314 memcpy(pszName, pcszName, cbName + 1); 4315 nlsUpper(pszName, cbName); 4316 4317 if (pLastMaskComponent = strrchr(pszMask, '\\')) 4318 { 4319 // length of path component 4320 cbMaskPath = pLastMaskComponent - pszMask; 4321 pLastMaskComponent++; 4322 } 4323 else 4324 pLastMaskComponent = pszMask; 4325 4326 if (pLastNameComponent = strrchr(pszName, '\\')) 4327 { 4328 // length of path component 4329 cbNamePath = pLastNameComponent - pszName; 4330 pLastNameComponent++; 4331 } 4332 else 4333 pLastNameComponent = pszName; 4334 4335 // compare paths; if the lengths are different 4336 // or memcmp fails, we can't match 4337 if ( (cbMaskPath == cbNamePath) // can both be null 4338 && ( (cbMaskPath == 0) 4339 || (!memcmp(pszMask, pszName, cbMaskPath)) 4340 ) 4341 ) 4342 { 4343 // alright, paths match: 4344 brc = PerformMatch(pLastMaskComponent, 4345 pLastNameComponent, 4346 // has dot? 4347 (strchr(pLastNameComponent, '.') != NULL)); 4348 4349 } 4350 4351 return brc; 4352 } 4353 4354
Note:
See TracChangeset
for help on using the changeset viewer.