- Timestamp:
- Sep 8, 2000, 4:48:40 PM (25 years ago)
- Location:
- trunk/src/win32k/dev16
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/dev16/probkrnl.c
r4185 r4217 1 /* $Id: probkrnl.c,v 1.2 2 2000-09-04 16:40:48bird Exp $1 /* $Id: probkrnl.c,v 1.23 2000-09-08 14:48:40 bird Exp $ 2 2 * 3 3 * Description: Autoprobes the os2krnl file and os2krnl[*].sym files. … … 134 134 {FALSE, -1, 16, "_ldrpFileNameBuf", -1, -1, -1, -1, EPT_VARIMPORT32}, /* 40 */ 135 135 {FALSE, -1, 14, "SecPathFromSFN", -1, -1, -1, -1, EPT_PROCIMPORTNR32},/* 41 */ 136 {FALSE, -1, 14, "_ldrSetVMflags", -1, -1, -1, -1, EPT_PROC32}, /* 42 */ 136 137 137 138 }; … … 153 154 * privat data 154 155 */ 155 #if defined(DEBUGR3)156 static char DATA16_INIT szUsrOS2Krnl[50] = {0};157 static char DATA16_INIT szOS2Krnl[] = {"c:\\os2krnl"};158 #endif159 156 static char * DATA16_INIT apszSym[] = 160 157 { … … 178 175 179 176 /* Result from GetKernelInfo/ReadOS2Krnl. */ 180 staticunsigned char DATA16_INIT cObjects = 0;181 staticPOTE DATA16_INIT paKrnlOTEs = NULL;177 unsigned char DATA16_INIT cObjects = 0; 178 POTE DATA16_INIT paKrnlOTEs = NULL; 182 179 183 180 … … 257 254 *******************************************************************************/ 258 255 /* File an output replacements */ 259 staticHFILE fopen(const char * pszFilename, const char * pszIgnored);260 staticint fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile);261 staticint fseek(HFILE hfile, signed long off, int iOrg);262 staticunsigned long fsize(HFILE hFile);256 HFILE fopen(const char * pszFilename, const char * pszIgnored); 257 int fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile); 258 int fseek(HFILE hfile, signed long off, int iOrg); 259 unsigned long fsize(HFILE hFile); 263 260 264 261 /* C-library replacements and additions. */ 265 staticvoid kmemcpy(char *psz1, const char *psz2, int cch);266 staticchar * kstrstr(const char *psz1, const char *psz2);267 staticint kstrcmp(const char *psz1, const char *psz2);268 staticint kstrncmp(const char *psz1, const char *psz2, int cch);269 staticint kstrnicmp(const char *psz1, const char *psz2, int cch);270 staticint kstrlen(const char *psz);271 staticchar * kstrcpy(char * pszTarget, const char * pszSource);272 staticint kargncpy(char *pszTarget, const char *pszArg, unsigned cchMaxlen);262 void kmemcpy(char *psz1, const char *psz2, int cch); 263 char * kstrstr(const char *psz1, const char *psz2); 264 int kstrcmp(const char *psz1, const char *psz2); 265 int kstrncmp(const char *psz1, const char *psz2, int cch); 266 int kstrnicmp(const char *psz1, const char *psz2, int cch); 267 int kstrlen(const char *psz); 268 char * kstrcpy(char * pszTarget, const char * pszSource); 269 int kargncpy(char *pszTarget, const char *pszArg, unsigned cchMaxlen); 273 270 274 271 /* Workers */ 275 staticint LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects);276 staticint VerifyPrologs(void);277 staticint ProbeSymFile(const char *pszFilename);278 staticint GetKernelInfo(void);272 int LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects); 273 int VerifyPrologs(void); 274 int ProbeSymFile(const char *pszFilename); 275 int GetKernelInfo(void); 279 276 280 277 /* Ouput */ 281 staticvoid ShowResult(int rc);278 void ShowResult(int rc); 282 279 283 280 /* Others used while debugging in R3. */ 284 static int VerifyKernelVer(void); 285 static int ReadOS2Krnl(char *pszFilename); 286 static int ReadOS2Krnl2(HFILE hKrnl, unsigned long cbKrnl); 287 static int processFile(const char *pszFilename); 288 289 #if 0 /*ndef CODE16_INIT*/ 290 #pragma alloc_text(CODE16_INIT, fopen, fread, fseek, fsize) 291 #pragma alloc_text(CODE16_INIT, kmemcpy, kstrstr, kstrcmp, kstrncmp, kstrnicmp, kstrlen, kstrcpy, kargncpy) 292 #pragma alloc_text(CODE16_INIT, GetErrorMsg) 293 #pragma alloc_text(CODE16_INIT, LookupKrnlEntry, VerifyPrologs, ProbeSymFile, GetKernelInfo) 294 #pragma alloc_text(CODE16_INIT, ShowResult) 295 #pragma alloc_text(CODE16_INIT, VerifyKernelVer, ReadOS2Krnl, ReadOS2Krnl2, processFile) 296 #endif 281 int VerifyKernelVer(void); 282 int ReadOS2Krnl(char *pszFilename); 283 int ReadOS2Krnl2(HFILE hKrnl, unsigned long cbKrnl); 297 284 298 285 … … 309 296 * @remark binary and readonly is assumed! 310 297 */ 311 staticHFILE fopen(const char * pszFilename, const char * pszIgnored)298 HFILE fopen(const char * pszFilename, const char * pszIgnored) 312 299 { 313 300 HFILE hFile = 0; … … 338 325 * @param hFile Handle to file (HFILE) 339 326 */ 340 staticint fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile)327 int fread(void * pvBuffer, USHORT cbBlock, USHORT cBlock, HFILE hFile) 341 328 { 342 329 USHORT ulRead; … … 360 347 * @param org origin 361 348 */ 362 staticint fseek(HFILE hFile, signed long off, int iOrg)349 int fseek(HFILE hFile, signed long off, int iOrg) 363 350 { 364 351 ULONG ul; … … 373 360 * @remark This function sets the file position to end of file. 374 361 */ 375 staticunsigned long fsize(HFILE hFile)362 unsigned long fsize(HFILE hFile) 376 363 { 377 364 USHORT rc; … … 390 377 * @param cch length 391 378 */ 392 staticvoid kmemcpy(char *psz1, const char *psz2, int cch)379 void kmemcpy(char *psz1, const char *psz2, int cch) 393 380 { 394 381 while (cch-- != 0) … … 404 391 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 405 392 */ 406 staticchar *kstrstr(const char *psz1, const char *psz2)393 char *kstrstr(const char *psz1, const char *psz2) 407 394 { 408 395 while (*psz1 != '\0') … … 431 418 * @param psz2 String 2 432 419 */ 433 staticint kstrcmp(const char *psz1, const char *psz2);420 int kstrcmp(const char *psz1, const char *psz2); 434 421 { 435 422 while (*psz1 == *psz2 && *psz1 != '\0' && *psz2 != '\0') … … 450 437 * @param len length 451 438 */ 452 staticint kstrncmp(register const char *psz1, register const char *psz2, int cch)439 int kstrncmp(register const char *psz1, register const char *psz2, int cch) 453 440 { 454 441 int i = 0; … … 472 459 * @param len length 473 460 */ 474 staticint kstrnicmp(const char *psz1, const char *psz2, int cch)461 int kstrnicmp(const char *psz1, const char *psz2, int cch) 475 462 { 476 463 register char ch1, ch2; … … 498 485 * @author knut st. osmundsen 499 486 */ 500 staticint kstrlen(register const char * psz)487 int kstrlen(register const char * psz) 501 488 { 502 489 register int cch = 0; … … 514 501 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 515 502 */ 516 staticchar * kstrcpy(char * pszTarget, register const char * pszSource)503 char * kstrcpy(char * pszTarget, register const char * pszSource) 517 504 { 518 505 register char *psz = pszTarget; … … 534 521 * @param cchMaxlen - maximum chars to copy. 535 522 */ 536 staticint kargncpy(char * pszTarget, const char * pszArg, unsigned cchMaxlen)523 int kargncpy(char * pszTarget, const char * pszArg, unsigned cchMaxlen) 537 524 { 538 525 int i = 0; … … 603 590 * Implementation Of The Important Functions * 604 591 *******************************************************************************/ 605 #ifndef EXTRACT606 592 /** 607 593 * Checks if this kernel is within the kernel symbol database. … … 618 604 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 619 605 */ 620 staticint LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects)606 int LookupKrnlEntry(unsigned short usBuild, unsigned short fKernel, unsigned char cObjects) 621 607 { 622 608 int i; … … 673 659 return ERROR_PROB_SYMDB_KRNL_NOT_FOUND; 674 660 } 675 #endif /* !EXTRACT */676 661 677 662 … … 683 668 * is set to the failing procedure (if appliable). 684 669 */ 685 staticint VerifyPrologs(void)686 { 687 #if !defined( DEBUGR3) && !defined(EXTRACT)670 int VerifyPrologs(void) 671 { 672 #if !defined(EXTRACT) 688 673 APIRET rc; 689 674 HFILE hDev0 = 0; … … 741 726 * @remark Error codes starts at -50. 742 727 */ 743 staticint ProbeSymFile(const char * pszFilename)728 int ProbeSymFile(const char * pszFilename) 744 729 { 745 730 HFILE hSym; /* Filehandle */ … … 1001 986 * Not 0 on error. 1002 987 */ 1003 staticint GetKernelInfo(void)1004 { 1005 #if !defined( DEBUGR3) && !defined(EXTRACT) /* This IOCtl is not available after inittime! */988 int GetKernelInfo(void) 989 { 990 #if !defined(EXTRACT) /* This IOCtl is not available after inittime! */ 1006 991 static KRNLINFO DATA16_INIT KrnlInfo = {0}; 1007 992 APIRET rc; … … 1055 1040 1056 1041 #else 1057 #ifndef EXTRACT 1058 APIRET rc; 1059 1060 /*--------------*/ 1061 /* read kernel */ 1062 /*--------------*/ 1063 if (szUsrOS2Krnl[0] != '\0') 1064 { 1065 rc = ReadOS2Krnl(szUsrOS2Krnl); 1066 if (rc != NO_ERROR) 1067 { 1068 printf16("Warning: Invalid kernel file specified. Tries defaults.\n"); 1069 szUsrOS2Krnl[0] = '\0'; 1070 rc = ReadOS2Krnl(szOS2Krnl); 1071 } 1072 } 1073 else 1074 rc = ReadOS2Krnl(szOS2Krnl); 1075 return rc; 1076 #else 1077 return 0; 1078 #endif 1042 return 0; 1079 1043 #endif 1080 1044 } … … 1085 1049 * @param rc Return code. 1086 1050 */ 1087 #ifndef EXTRACT 1088 static void ShowResult(int rc) 1051 void ShowResult(int rc) 1089 1052 { 1090 1053 int i; … … 1101 1064 */ 1102 1065 if (rc == NO_ERROR || rc > ERROR_PROB_KRNL_LAST) 1103 {1104 #ifdef DEBUGR31105 printf16(" Found kernel: %s\n", szOS2Krnl);1106 #endif1107 1066 printf16(" Build: %ld - v%d.%d\n", 1108 1067 options.ulBuild, options.usVerMajor, options.usVerMinor); 1109 }1110 1068 else if (rc >= ERROR_PROB_KRNL_FIRST) 1111 1069 printf16(" Kernel probing failed with rc=%d.\n", rc); … … 1183 1141 switch (pReqPack->InitArgs[i]) 1184 1142 { 1185 #if defined(DEBUGR3)1186 case 'k':1187 case 'K': /* Kernel file */1188 i++;1189 i += kargncpy(szUsrOS2Krnl, &pReqPack->InitArgs[i], sizeof(szUsrOS2Krnl));1190 break;1191 #endif1192 1193 1143 case 'n': 1194 1144 case 'N': /* NoLoader */ … … 1245 1195 /* set driveletter in constants strings */ 1246 1196 usBootDrive = (char)usBootDrive + (char)'a' - 1; 1247 #if defined(DEBUGR3)1248 szOS2Krnl[0] = (char)usBootDrive;1249 #endif1250 1197 for (i = 0; apszSym[i] != NULL; i++) 1251 1198 apszSym[i][0] = (char)usBootDrive; … … 1315 1262 return rc; 1316 1263 } 1317 #endif 1318 1319 1320 #ifdef DEBUGR3 1321 /** 1322 * Verifies that build no, matches kernel number. 1323 * @returns 0 on equal, !0 on error. 1324 */ 1325 static int VerifyKernelVer(void) 1326 { 1327 int VerMinor, VerMajor; 1328 1329 VerMajor = options.ulBuild < 20000 ? 20 : 30/*?*/; 1330 VerMinor = options.ulBuild < 6600 ? 10 : options.ulBuild < 8000 ? 11 : options.ulBuild < 9000 ? 30 : 1331 options.ulBuild < 10000 ? 40 : options.ulBuild < 15000 ? 45 : 50; 1332 1333 return VerMajor - (int)options.usVerMajor | VerMinor - (int)options.usVerMinor; 1334 } 1335 1336 1337 /** 1338 * Reads and verifies OS/2 kernel. 1339 * @returns 0 on success. 1340 * One of the ERROR_PROB_KRNL_* defines on error. 1341 * @param pszFilename Filename of the OS/2 kernel. 1342 * @result options.ulBuild is set. 1343 * @remark This step will be eliminated by searching thru the DOSGROUP datasegment 1344 * in the kernel memory. This segment have a string "Internal revision 9.034[smp|uni]" 1345 * This would be much faster than reading the kernel file. It will also give us a more precise 1346 * answer to the question! This is currently a TODO issue. !FIXME! 1347 */ 1348 static int ReadOS2Krnl(char * pszFilename) 1349 { 1350 HFILE hKrnl; 1351 unsigned long cbKrnl; 1352 int rc; 1353 1354 hKrnl = fopen(pszFilename, "rb"); 1355 if (hKrnl != 0) 1356 { 1357 /* 1358 * Get size of kernel file. 1359 */ 1360 cbKrnl = fsize(hKrnl); 1361 if (!fseek(hKrnl, 0, SEEK_SET)) 1362 { 1363 /* 1364 * Call worker with filehandle and size. 1365 */ 1366 rc = ReadOS2Krnl2(hKrnl, cbKrnl); 1367 } 1368 else 1369 rc = ERROR_PROB_KRNL_SEEK_SIZE; 1370 fclose(hKrnl); 1371 } 1372 else 1373 { 1374 dprintf(("Could not open file\n")); 1375 rc = ERROR_PROB_KRNL_OPEN_FAILED; 1376 } 1377 return rc; 1378 } 1379 1380 1381 /** 1382 * Worker function for ReadOS2Krnl 1383 * @returns 0 on success. 1384 * One of the ERROR_PROB_KRNL_* defines on error. 1385 * @param hKrnl Handle to the kernel file. 1386 * @param cbKrnl Size of the kernel file. 1387 * @author knut st. osmundsen 1388 */ 1389 static int ReadOS2Krnl2(HFILE hKrnl, unsigned long cbKrnl) 1390 { 1391 #if defined(DEBUGR3) || !defined(EXTRACT) 1392 static KRNLINFO DATA16_INIT KrnlInfo = {0}; 1393 #endif 1394 int i, j; 1395 int rc = 0; 1396 char achBuffer[KERNEL_ID_STRING_LENGTH + KERNEL_READ_SIZE]; 1397 unsigned long offLXHdr; 1398 struct e32_exe *pLXHdr; 1399 1400 1401 /* 1402 * Find bldlevel string - for example: "@#IBM:14.020#@ IBM OS/2 Kernel - 14.020F" 1403 * Searching the entire file lineary from the start. 1404 */ 1405 if (fseek(hKrnl, 0, SEEK_SET)) 1406 return ERROR_PROB_KRNL_SEEK_FIRST; 1407 1408 if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, KERNEL_READ_SIZE, hKrnl)) 1409 return ERROR_PROB_KRNL_READ_FIRST; 1410 1411 i = KERNEL_ID_STRING_LENGTH; 1412 while (cbKrnl > 0) 1413 { 1414 if (i == KERNEL_READ_SIZE) 1415 { 1416 1417 kmemcpy(achBuffer, &achBuffer[KERNEL_READ_SIZE], KERNEL_ID_STRING_LENGTH); 1418 if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, cbKrnl > KERNEL_READ_SIZE ? KERNEL_READ_SIZE : (int)cbKrnl, hKrnl)) 1419 return ERROR_PROB_KRNL_READ_NEXT; 1420 1421 i = 0; 1422 } 1423 1424 if (kstrncmp("@#IBM:", &achBuffer[i], 6) == 0) 1425 break; 1426 1427 /* next */ 1428 i++; 1429 cbKrnl--; 1430 } 1431 1432 /* found it? */ 1433 if (cbKrnl == 0) 1434 { 1435 fclose(hKrnl); 1436 return ERROR_PROB_KRNL_TAG_NOT_FOUND; 1437 } 1438 1439 1440 /* 1441 * We've found the @#IBM: tag. So now we'll try read it. 1442 */ 1443 1444 /* displacement */ 1445 j = 0; 1446 while (j < 6 && achBuffer[i+10+j] != '#') 1447 j++; 1448 1449 /* verify signature */ 1450 if (kstrncmp(&achBuffer[i+10+j], "#@ IBM OS/2 Kernel", 19) != 0) 1451 return ERROR_PROB_KRNL_INV_SIGANTURE; 1452 1453 /* 1454 * read options.ulBuild 1455 */ 1456 options.ulBuild = (char)(achBuffer[i+6] - '0') * 1000; 1457 if (achBuffer[i+7] != '.') 1458 { 1459 /* this code is for Warp5 */ 1460 options.ulBuild *= 10; 1461 options.ulBuild += (char)(achBuffer[i+7] - '0') * 1000; 1462 i++; 1463 j--; 1464 if (achBuffer[i+7] != '.') 1465 { 1466 options.ulBuild *= 10; 1467 options.ulBuild += (unsigned long)(achBuffer[i+7] - '0') * 1000; 1468 i++; 1469 j--; 1470 } 1471 } 1472 1473 if (j == 0) 1474 { 1475 options.ulBuild += (achBuffer[i+ 8] - '0') * 10; 1476 options.ulBuild += (achBuffer[i+ 9] - '0') * 1; 1477 } 1478 else 1479 { 1480 if (j == 3) 1481 return ERROR_PROB_KRNL_INV_BUILD_NBR; 1482 options.ulBuild += (achBuffer[i+ 8] - '0') * 100; 1483 options.ulBuild += (achBuffer[i+ 9] - '0') * 10; 1484 options.ulBuild += (achBuffer[i+10] - '0'); 1485 } 1486 1487 /* 1488 * We've read the build number. Let's check that it matches the OS/2 1489 * version reported by DosGetInfoSeg. 1490 */ 1491 if (VerifyKernelVer()) 1492 return ERROR_PROB_KRNL_BUILD_VERSION; 1493 dprintf(("options.ulBuild: %d\n", options.ulBuild)); 1494 1495 /* get segment number */ 1496 /* read-MZheader */ 1497 if (fseek(hKrnl,0,SEEK_SET)) 1498 return ERROR_PROB_KRNL_MZ_SEEK; 1499 1500 if (!fread(achBuffer, 1, 0x40, hKrnl)) 1501 return ERROR_PROB_KRNL_MZ_READ; 1502 1503 offLXHdr = *(unsigned long int *)&achBuffer[0x3c]; 1504 1505 if (offLXHdr > 0x2000 && offLXHdr < 0x80) /* just to detect garbage */ 1506 return ERROR_PROB_KRNL_NEOFF_INVALID; 1507 1508 if (fseek(hKrnl, offLXHdr, SEEK_SET)) 1509 return ERROR_PROB_KRNL_NEOFF_SEEK; 1510 1511 if (!fread(achBuffer, 1, sizeof(struct e32_exe), hKrnl)) 1512 return ERROR_PROB_KRNL_LX_READ; 1513 1514 /* check LX-magic */ 1515 if (achBuffer[0] != 'L' || achBuffer[1] != 'X') 1516 return ERROR_PROB_KRNL_LX_SIGNATURE; 1517 1518 #if !defined(DEBUGR3) && !defined(EXTRACT) 1519 /* check object count - match it with what we got from the kernel. */ 1520 pLXHdr = (struct e32_exe *)achBuffer; 1521 if ((UCHAR)pLXHdr->e32_objcnt != cObjects) 1522 return ERROR_PROB_KRNL_OBJECT_CNT; 1523 1524 if (pLXHdr->e32_objcnt < 10) 1525 return ERROR_PROB_KRNL_OBJECT_CNR_10; 1526 1527 /* check objects sizes. */ 1528 if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET)) 1529 { 1530 struct o32_obj *pObj = (struct o32_obj *)achBuffer; 1531 for (i = 0; i < (int)cObjects; i++) 1532 { 1533 if (!fread(achBuffer, 1, sizeof(OTE), hKrnl)) 1534 return ERROR_PROB_KRNL_OTE_READ; 1535 if (pObj->o32_size < paKrnlOTEs[i].ote_size) 1536 return ERROR_PROB_KRNL_OTE_SIZE_MIS; 1537 } 1538 } 1539 else 1540 return ERROR_PROB_KRNL_OTE_SEEK; 1541 #else 1542 /* Since we can't get the OTEs from the kernel when debugging in RING-3, 1543 * we'll use what we find in the kernel. 1544 */ 1545 1546 /* object count */ 1547 pLXHdr = (struct e32_exe *)achBuffer; 1548 cObjects = (UCHAR)pLXHdr->e32_objcnt; 1549 paKrnlOTEs = &KrnlInfo.aObjects[0]; 1550 1551 /* get OTEs */ 1552 if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET)) 1553 { 1554 struct o32_obj *pObj = (struct o32_obj *)achBuffer; 1555 for (i = 0; i < (int)cObjects; i++) 1556 if (!fread(&paKrnlOTEs[i], 1, sizeof(struct o32_obj), hKrnl)) 1557 return ERROR_PROB_KRNL_OTE_READ; 1558 } 1559 else 1560 return ERROR_PROB_KRNL_OTE_SEEK; 1561 #endif 1562 1563 return NO_ERROR; 1564 } 1565 1566 1567 1568 /** 1569 * Debug - Main procedure for standalone testing. 1570 */ 1571 void main(int argc, char **argv) 1572 { 1573 char szParm[512]; 1574 RPINITIN ReqPack; 1575 int j; 1576 int i = 0; 1577 int argi = 0; 1578 1579 while (argi < argc) 1580 { 1581 j = 0; 1582 while (argv[argi][j] != '\0') 1583 szParm[i++] = argv[argi][j++]; 1584 szParm[i++] = ' '; 1585 1586 /* next */ 1587 argi++; 1588 } 1589 szParm[i++] = '\0'; 1590 1591 ReqPack.InitArgs = szParm; 1592 1593 ProbeKernel(&ReqPack); 1594 } 1595 #endif 1596 1597 1598 #ifdef EXTRACT 1599 /** 1600 * Dumps writes a KRNLDBENTRY struct to stderr for the given .sym-file. 1601 * The filesnames are on this format: 1602 * nnnn[n]tm.SYM 1603 * Where: n - are the build number 4 or 5 digits. 1604 * t - kernel type. R = retail, H = half strict, A = all strict. 1605 * m - UNI or SMP. U = UNI processor kernel. S = SMP processor kernel. 4 = Warp 4 FP13+ 1606 * @returns NO_ERROR on success. Untracable error code on error. 1607 * @param pszFilename Pointer to read only filename of the .sym-file. 1608 * @status completely implemented. 1609 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 1610 * @remark Currently only retail kernels are processed. See note below. 1611 */ 1612 static int processFile(const char *pszFilename) 1613 { 1614 APIRET rc; 1615 int cch = kstrlen(pszFilename); 1616 1617 DosWrite(2, (char*)pszFilename, cch, &rc); 1618 DosWrite(2, "\r\n", 2, &rc); 1619 1620 /* Filename check */ 1621 if (cch < 10 || cch > 11 1622 || !(pszFilename[0] >= '0' && pszFilename[0] <= '9') 1623 || !(pszFilename[1] >= '0' && pszFilename[1] <= '9') 1624 || !(pszFilename[2] >= '0' && pszFilename[2] <= '9') 1625 || !(pszFilename[3] >= '0' && pszFilename[3] <= '9') 1626 || !(pszFilename[cch-7] >= '0' && pszFilename[cch-7] <= '9') 1627 || !(pszFilename[cch-6] == 'A' || pszFilename[cch-6] == 'H' || pszFilename[cch-6] == 'R') 1628 || !(pszFilename[cch-5] == 'S' || pszFilename[cch-5] == 'U' || pszFilename[cch-5] == '4') 1629 ) 1630 { 1631 printf16("invalid filename: %s\n", pszFilename); 1632 return 2; 1633 } 1634 1635 /* 1636 * Probe kernelfile 1637 */ 1638 rc = ProbeSymFile(pszFilename); 1639 1640 1641 /* 1642 * on success dump a struct for this kernel 1643 */ 1644 if (rc == 0) 1645 { 1646 int i; 1647 1648 /** @remark 1649 * Currently information for retail kernels are usable, but we'll 1650 * generate it for the debug kernels too, but this information 1651 * is enclaved within an "#ifdef ALLKERNELS ... #endif". 1652 */ 1653 if (pszFilename[cch-6] != 'R') 1654 printf16("#ifdef ALLKERNELS\n"); 1655 1656 printf16(" { /* %s */\n" 1657 " %.*s, ", 1658 pszFilename, 1659 cch - 6, &pszFilename[0] /* build number */ 1660 ); 1661 1662 switch (pszFilename[cch - 5]) 1663 { 1664 case 'S': printf16("KF_SMP"); break; 1665 case '4': printf16("KF_UNI | KF_W4"); break; 1666 case 'U': printf16("KF_UNI"); break; 1667 } 1668 switch (pszFilename[cch - 6]) 1669 { 1670 case 'A': printf16(" | KF_ALLSTRICT"); break; 1671 case 'H': printf16(" | KF_HALFSTRICT"); break; 1672 } 1673 printf16(", %d,\n" 1674 " {\n", 1675 aImportTab[0].iObject + 1); /* ASSUMES that DOSCODE32 is the last object. */ 1676 1677 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 1678 { 1679 char *psz = aImportTab[i].achName; 1680 printf16(" {%-2d, 0x%08lx}, /* %s */\n", 1681 aImportTab[i].iObject, 1682 aImportTab[i].fFound ? aImportTab[i].offObject : 0xFFFFFFFFUL, 1683 (char *)&aImportTab[i].achName[0] 1684 ); 1685 } 1686 printf16(" }\n" 1687 " },\n"); 1688 1689 /** @remark 1690 * Currently information for retail kernels are usable, but we'll 1691 * generate it for the debug kernels too, but this information 1692 * is enclaved within an "#ifdef ALLKERNELS ... #endif". 1693 */ 1694 if (pszFilename[cch-6] != 'R') 1695 printf16("#endif\n"); 1696 } 1697 else 1698 printf16("ProbeSymFile failed with rc=%d\n", rc); 1699 1700 return rc; 1701 } 1702 1703 1704 /** 1705 * Extract program. 1706 * 1707 * This is some initial trial-and-error for creating an "database" of 1708 * kernel entrypoints. 1709 * 1710 * Output to stderr the structs generated for the passed in *.sym file. 1711 * 1712 */ 1713 int main(int argc, char **argv) 1714 { 1715 APIRET rc; 1716 const char * psz; 1717 1718 /* 1719 * Set paKrnlOTEs to point to an zeroed array of OTEs. 1720 */ 1721 static KRNLINFO DATA16_INIT KrnlInfo = {0}; 1722 paKrnlOTEs = &KrnlInfo.aObjects[0]; 1723 1724 if (argc > 1) 1725 { 1726 /* 1727 * Arguments: extract.exe <symfiles...> 1728 */ 1729 int i; 1730 for (i = 1; i < argc; i++) 1731 { 1732 rc = processFile(argv[i]); 1733 if (rc != NO_ERROR) 1734 { 1735 printf16("processFile failed with rc=%d for file %s\n", 1736 rc, argv[i]); 1737 if (psz = GetErrorMsg(rc)) 1738 printf16("%s\n", psz); 1739 return rc; 1740 } 1741 } 1742 } 1743 else 1744 { 1745 /* 1746 * Arguments: extract.exe 1747 * 1748 * Action: Scan current directory for *.sym files. 1749 * 1750 */ 1751 USHORT usSearch = 1; 1752 HDIR hDir = HDIR_CREATE; 1753 FILEFINDBUF ffb; 1754 int i; 1755 1756 printf16("/* $Id: probkrnl.c,v 1.22 2000-09-04 16:40:48 bird Exp $\n" 1757 "*\n" 1758 "* Autogenerated kernel symbol database.\n" 1759 "*\n" 1760 "* Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)\n" 1761 "*\n" 1762 "* Project Odin Software License can be found in LICENSE.TXT\n" 1763 "*\n" 1764 "*/\n"); 1765 1766 printf16("\n" 1767 "#define INCL_NOPMAPI\n" 1768 "#define INCL_NOBASEAPI\n" 1769 "#include <os2.h>\n" 1770 "#include \"DevSegDf.h\"\n" 1771 "#include \"probkrnl.h\"\n" 1772 "#include \"options.h\"\n" 1773 "\n"); 1774 1775 printf16("KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = \n" 1776 "{\n"); 1777 1778 rc = DosFindFirst("*.sym", &hDir, FILE_NORMAL, 1779 &ffb, sizeof(ffb), 1780 &usSearch, 0UL); 1781 while (rc == NO_ERROR & usSearch > 0) 1782 { 1783 rc = processFile(&ffb.achName[0]); 1784 if (rc != NO_ERROR) 1785 { 1786 printf16("processFile failed with rc=%d for file %s\n", 1787 rc, &ffb.achName[0]); 1788 if (psz = GetErrorMsg(rc)) 1789 printf16("%s\n", psz); 1790 return rc; 1791 } 1792 1793 /* next file */ 1794 rc = DosFindNext(hDir, &ffb, sizeof(ffb), &usSearch); 1795 } 1796 DosFindClose(hDir); 1797 1798 printf16(" { /* Terminating entry */\n" 1799 " 0,0,0,\n" 1800 " {\n"); 1801 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 1802 printf16(" {0,0},\n"); 1803 printf16(" }\n" 1804 " }\n" 1805 "}; /* end of aKrnlSymDB[] */\n" 1806 ); 1807 } 1808 1809 1810 return rc; 1811 } 1812 #endif /* EXTRACT */ 1813 1264
Note:
See TracChangeset
for help on using the changeset viewer.