- Timestamp:
- Feb 20, 2000, 12:52:00 AM (26 years ago)
- Location:
- trunk/src/win32k
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/dev16/probkrnl.c
r2827 r2831 1 /* $Id: probkrnl.c,v 1.1 0 2000-02-19 08:40:29 bird Exp $1 /* $Id: probkrnl.c,v 1.11 2000-02-19 23:51:59 bird Exp $ 2 2 * 3 3 * Description: Autoprobes the os2krnl file and os2krnl[*].sym files. … … 83 83 84 84 /* 85 * a ProcTab defines the imported and overloaded OS/2 kernel functions.86 * IMPORTANT: a ProcTab has a sibling array in d32init.c, aulProc, which must87 * match entry by entry. Adding/removing/shuffling a ProcTab, aulProc85 * aImportTab defines the imported and overloaded OS/2 kernel functions. 86 * IMPORTANT: aImportTab has a sibling array in d32init.c, aulProc, which must 87 * match entry by entry. Adding/removing/shuffling aImportTab, aulProc 88 88 * has to be updated immediately! 89 89 */ 90 PROCS aProcTab[NUMBER_OF_PROCS] = 91 {/* iFound cchName offObject fType */ 92 /* iObject achName ulAddress */ 93 {FALSE, -1, 8, "_ldrRead", -1, -1, EPT_PROC}, /* 0 */ 94 {FALSE, -1, 8, "_ldrOpen", -1, -1, EPT_PROC}, /* 1 */ 95 {FALSE, -1, 9, "_ldrClose", -1, -1, EPT_PROC}, /* 2 */ 96 {FALSE, -1, 12, "_LDRQAppType", -1, -1, EPT_PROCIMPORT}, /* 3 */ /* to be removed? */ 97 {FALSE, -1, 20, "_ldrEnum32bitRelRecs", -1, -1, EPT_PROC}, /* 4 */ 98 {FALSE, -1, 10, "_IOSftOpen", -1, -1, EPT_PROCIMPORT}, /* 5 */ 99 {FALSE, -1, 11, "_IOSftClose", -1, -1, EPT_PROCIMPORT}, /* 6 */ 100 {FALSE, -1, 15, "_IOSftTransPath", -1, -1, EPT_PROCIMPORT}, /* 7 */ 101 {FALSE, -1, 12, "_IOSftReadAt", -1, -1, EPT_PROCIMPORT}, /* 8 */ 102 {FALSE, -1, 13, "_IOSftWriteAt", -1, -1, EPT_PROCIMPORT}, /* 9 */ 103 {FALSE, -1, 12, "_SftFileSize", -1, -1, EPT_PROCIMPORT}, /* 10 */ 104 {FALSE, -1, 11, "_VMAllocMem", -1, -1, EPT_PROCIMPORT}, /* 11 */ 105 {FALSE, -1, 11, "_VMGetOwner", -1, -1, EPT_PROCIMPORT}, /* 12 */ 106 {FALSE, -1, 11, "g_tkExecPgm", -1, -1, EPT_PROC} /* 13 */ 90 IMPORTKRNLSYM aImportTab[NBR_OF_KRNLIMPORTS] = 91 {/* iFound cchName offObject usSel */ 92 /* iObject achName ulAddress fType */ 93 {FALSE, -1, 8, "_ldrRead", -1, -1, -1, EPT_PROC32}, /* 0 */ 94 {FALSE, -1, 8, "_ldrOpen", -1, -1, -1, EPT_PROC32}, /* 1 */ 95 {FALSE, -1, 9, "_ldrClose", -1, -1, -1, EPT_PROC32}, /* 2 */ 96 {FALSE, -1, 12, "_LDRQAppType", -1, -1, -1, EPT_PROCIMPORT32}, /* 3 */ /* to be removed? */ 97 {FALSE, -1, 20, "_ldrEnum32bitRelRecs", -1, -1, -1, EPT_PROC32}, /* 4 */ 98 {FALSE, -1, 10, "_IOSftOpen", -1, -1, -1, EPT_PROCIMPORT32}, /* 5 */ 99 {FALSE, -1, 11, "_IOSftClose", -1, -1, -1, EPT_PROCIMPORT32}, /* 6 */ 100 {FALSE, -1, 15, "_IOSftTransPath", -1, -1, -1, EPT_PROCIMPORT32}, /* 7 */ 101 {FALSE, -1, 12, "_IOSftReadAt", -1, -1, -1, EPT_PROCIMPORT32}, /* 8 */ 102 {FALSE, -1, 13, "_IOSftWriteAt", -1, -1, -1, EPT_PROCIMPORT32}, /* 9 */ 103 {FALSE, -1, 12, "_SftFileSize", -1, -1, -1, EPT_PROCIMPORT32}, /* 10 */ 104 {FALSE, -1, 11, "_VMAllocMem", -1, -1, -1, EPT_PROCIMPORT32}, /* 11 */ 105 {FALSE, -1, 11, "_VMGetOwner", -1, -1, -1, EPT_PROCIMPORT32}, /* 12 */ 106 {FALSE, -1, 11, "g_tkExecPgm", -1, -1, -1, EPT_PROC32}, /* 13 */ 107 {FALSE, -1, 11, "f_FuStrLenZ", -1, -1, -1, EPT_PROCIMPORT16}, /* 14 */ 108 {FALSE, -1, 8, "f_FuBuff", -1, -1, -1, EPT_PROCIMPORT16} /* 15 */ 109 /* {FALSE, -1, 11, "", -1, -1, -1, EPT_PROCIMPORT16} */ /* 16 */ 107 110 }; 108 111 … … 156 159 static void kmemcpy(char *p1, const char *p2, int len); 157 160 static int kstrcmp(const char *p1, const char *p2); 161 static char *kstrstr(const char *psz1, const char *psz2); 158 162 static int kstrncmp(const char *p1, const char *p2, int len); 159 163 static int kstrlen(const char *p); … … 177 181 178 182 183 184 185 /******************************************************************************* 186 * Implementation of Internal Helper Functions * 187 *******************************************************************************/ 179 188 180 189 /** … … 309 318 #endif 310 319 320 321 322 /** 323 * Finds psz2 in psz2. 324 * @returns Pointer to occurence of psz2 in psz1. 325 * @param psz1 String to be search. 326 * @param psz2 Substring to search for. 327 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no) 328 */ 329 static char *kstrstr(const char *psz1, const char *psz2) 330 { 331 while (*psz1 != '\0') 332 { 333 register int i = 0; 334 while (psz2[i] != '\0' && psz1[i] == psz2[i]) 335 i++; 336 337 /* found it? */ 338 if (psz2[i] == '\0') 339 return (char*)psz1; 340 if (psz1[i] == '\0' ) 341 break; 342 psz1++; 343 } 344 345 return NULL; 346 } 347 348 349 311 350 /** 312 351 * kstrncmp - String 'n' compare. … … 400 439 401 440 402 /** 403 * Verifies the that the addresses in aProcTab are valid. 441 442 /******************************************************************************* 443 * Implementation Of The Important Function * 444 *******************************************************************************/ 445 446 /** 447 * Verifies the that the addresses in aImportTab are valid. 404 448 * This is done at Ring-0 of course. 405 449 * @returns 0 if ok, not 0 if not ok. … … 430 474 431 475 /** 432 * Check a symbol efile. Searches for the wanted entry-point addresses.476 * Check a symbol file. Searches for the wanted entry-point addresses. 433 477 * @returns 0 on success - something else on failiure. 434 478 * @param pszFilename Name of file to probe. … … 438 482 static int ProbeSymFile(char * pszFilename) 439 483 { 440 HFILE SymFile; 441 MAPDEF MapDef; 442 SEGDEF SegDef; 443 SYMDEF32 SymDef32; 444 SYMDEF16 SymDef16; 445 char Buffer[256]; 446 unsigned long SymNum; 447 unsigned long SegOffset, SymOffset, SymPtrOffset; 448 unsigned long i; 449 unsigned long ulSegments; 450 int LeftToFind; 484 HFILE hSym; /* Filehandle */ 485 int cLeftToFind; /* Symbols left to find */ 486 unsigned long iSeg; /* Outer search loop: Segment number */ 487 unsigned iSym; /* Middle search loop: Symbol number */ 488 unsigned i; /* Inner search loop: ProcTab index */ 451 489 int rc; 452 490 453 /* open symbole file */ 454 SymFile = fopen(pszFilename, "rb"); 455 if (SymFile==0) 491 MAPDEF MapDef; /* Mapfile header */ 492 SEGDEF SegDef; /* Segment header */ 493 SYMDEF32 SymDef32; /* Symbol definition 32-bit */ 494 SYMDEF16 SymDef16; /* Symbol definition 16-bit */ 495 char achBuffer[256]; /* Name buffer */ 496 unsigned long offSegment; /* Segment definition offset */ 497 unsigned long offSymPtr; /* Symbol pointer(offset) offset */ 498 unsigned short offSym; /* Symbol definition offset */ 499 500 501 /* 502 * Open the symbol file 503 */ 504 hSym = fopen(pszFilename, "rb"); 505 if (hSym==0) 456 506 { 457 507 dprintf(("Error opening file %s\n", pszFilename)); … … 459 509 } 460 510 461 /* read header and display it */ 462 rc = fread(&MapDef, sizeof(MAPDEF), 1, SymFile); 463 if (rc) 464 { 465 Buffer[0] = MapDef.achModName[0]; 466 fread(&Buffer[1], 1, MapDef.cbModName, SymFile); 467 Buffer[MapDef.cbModName] = '\0'; 468 dprintf(("*Module name: %s\n", Buffer)); 469 dprintf(("*Segments: %d\n*MaxSymbolLength: %d\n", MapDef.cSegs, MapDef.cbMaxSym)); 470 dprintf(("*ppNextMap: 0x%x\n\n", MapDef.ppNextMap )); 471 } 472 else 473 { 474 fclose(SymFile); 511 512 /* 513 * (Open were successfully.) 514 * Now read header and display it. 515 */ 516 rc = fread(&MapDef, sizeof(MAPDEF), 1, hSym); 517 if (!rc) 518 { /* oops! read failed, close file and fail. */ 519 fclose(hSym); 475 520 return -51; 476 521 } 477 478 /* verify module name */ 479 if (MapDef.cbModName == 7 && kstrncmp(Buffer, "OS2KRNL", 7) != 0) 480 { 522 achBuffer[0] = MapDef.achModName[0]; 523 fread(&achBuffer[1], 1, MapDef.cbModName, hSym); 524 achBuffer[MapDef.cbModName] = '\0'; 525 dprintf(("*Module name: %s\n", achBuffer)); 526 dprintf(("*Segments: %d\n*MaxSymbolLength: %d\n", MapDef.cSegs, MapDef.cbMaxSym)); 527 dprintf(("*ppNextMap: 0x%x\n\n", MapDef.ppNextMap )); 528 529 530 /* 531 * Verify that the modulename of the symbol file is OS2KRNL. 532 */ 533 if (MapDef.cbModName == 7 && kstrncmp(achBuffer, "OS2KRNL", 7) != 0) 534 { /* modulename was not OS2KRNL, fail. */ 481 535 dprintf(("Modulename verify failed\n")); 482 fclose( SymFile);536 fclose(hSym); 483 537 return -51; 484 538 } 485 539 486 /* verify correct number of segments */ 487 ulSegments = MapDef.cSegs; 488 if (ulSegments != KrnlOTEs.cObjects) 489 { 540 541 /* 542 * Verify that the number of segments is equal to the number objects in OS2KRNL. 543 */ 544 if (MapDef.cSegs != KrnlOTEs.cObjects) 545 { /* incorrect count of segments. */ 490 546 dprintf(("Segment No. verify failed\n")); 491 fclose( SymFile);547 fclose(hSym); 492 548 return -52; 493 549 } 494 550 495 SegOffset= SEGDEFOFFSET(MapDef); 496 /* skip to last segment - ASSUMES all imports located in 32-bit code segment. */ 497 for (i = 0; i < ulSegments; i++ ) 498 { 499 if (fseek(SymFile, SegOffset, SEEK_SET)) 500 { 501 fclose(SymFile); 551 552 /* 553 * Reset ProcTab 554 */ 555 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 556 aImportTab[i].fFound = 0; 557 558 559 /* 560 * Fileoffset of the first segment. 561 * And set cLeftToFind. 562 */ 563 offSegment = SEGDEFOFFSET(MapDef); 564 cLeftToFind = NBR_OF_KRNLIMPORTS; 565 566 /* 567 * Search thru the entire file, segment by segment. 568 * 569 * ASSUME: last segment is the only 32-bit code segment. 570 * 571 */ 572 for (iSeg = 0; iSeg < MapDef.cSegs; iSeg++, offSegment = NEXTSEGDEFOFFSET(SegDef)) 573 { 574 int fSegEPTBitType; /* Type of segment, 16 or 32 bit, expressed in EPT_XXBIT flags */ 575 int fCode; /* Set if this is a code segment, else clear. */ 576 577 /* 578 * Read the segment definition. 579 */ 580 if (fseek(hSym, offSegment, SEEK_SET)) 581 { /* Failed to seek to the segment definition, fail! */ 582 fclose(hSym); 502 583 return -53; 503 584 } 504 rc = fread(&SegDef, sizeof(SEGDEF), 1, SymFile); 505 if (i+1 < ulSegments) 506 SegOffset = NEXTSEGDEFOFFSET(SegDef); 507 } 508 509 Buffer[0] = SegDef.achSegName[0]; 510 rc = fread(&Buffer[1], 1, SegDef.cbSegName, SymFile); 511 512 /* verify that this is DOSHIGH32CODE */ 513 if (SegDef.cbSegName != 13 && kstrncmp(Buffer, "DOSHIGH32CODE", 13) != 0) 514 { 515 dprintf(("DOSHIGH32CODE verify failed \n")); 516 fclose(SymFile); 517 return -54; 518 } 519 520 for (i = 0; i < NUMBER_OF_PROCS; i++) 521 aProcTab[i].fFound = 0 ; 522 523 /* search for the entry-point names */ 524 for (LeftToFind = NUMBER_OF_PROCS, SymNum = 0; SymNum < SegDef.cSymbols && LeftToFind; SymNum++) 525 { 526 SymPtrOffset = SYMDEFOFFSET(SegOffset, SegDef, SymNum); 527 rc = fseek(SymFile, SymPtrOffset, SEEK_SET); 528 rc = fread(&SymOffset, sizeof(unsigned short int), 1, SymFile); 529 SymOffset &=0xffff; 530 rc = fseek(SymFile, SymOffset+SegOffset, SEEK_SET); 531 532 if (SegDef.bFlags & 0x01) 585 rc = fread(&SegDef, sizeof(SEGDEF), 1, hSym); 586 if (!rc) 587 { /* Failed to read the segment definition, fail! */ 588 fclose(hSym); 589 return -53; 590 } 591 592 /* 593 * Some debugging info. 594 */ 595 achBuffer[0] = SegDef.achSegName[0]; 596 fread(&achBuffer[1], 1, SegDef.cbSegName, hSym); 597 achBuffer[SegDef.cbSegName] = '\0'; 598 dprintf(("Segment %.2li Flags=0x%02x cSymbols=0x%04x Name=%s\n", 599 iSeg, SegDef.bFlags, SegDef.cSymbols, &achBuffer[0])); 600 601 /* 602 * Determin segment bit type. 603 */ 604 fSegEPTBitType = SEG32BitSegment(SegDef) ? EPT_32BIT : EPT_16BIT; 605 fCode = kstrstr(achBuffer, "CODE") != NULL; 606 607 /* 608 * Search thru all the symbols in this segment 609 * while we look for the requested symbols in aImportTab. 610 */ 611 for (iSym = 0; iSym < SegDef.cSymbols && cLeftToFind; iSym++) 533 612 { 534 rc = fread(&SymDef32, sizeof(SYMDEF32), 1, SymFile); 535 Buffer[0] = SymDef32.achSymName[0]; 536 rc = fread(&Buffer[1], 1, SymDef32.cbSymName, SymFile); 537 Buffer[SymDef32.cbSymName] = '\0'; 538 } else 539 { 540 rc = fread(&SymDef16, sizeof(SYMDEF16), 1, SymFile); 541 Buffer[0] = SymDef16.achSymName[0]; 542 rc = fread(&Buffer[1], 1, SymDef16.cbSymName, SymFile); 543 Buffer[SymDef16.cbSymName] = '\0'; 544 } 545 546 /* search proctable */ 547 for (i = 0; i < NUMBER_OF_PROCS; i++) 548 { 549 if (!aProcTab[i].fFound && aProcTab[i].cchName == (SegDef.bFlags & 0x01 ? SymDef32.cbSymName : SymDef16.cbSymName)) 613 unsigned cchName; 614 /* 615 * Fileoffset of the current symbol. 616 * Set filepointer to that position. 617 * Read word (which is the offset of the symbol). 618 */ 619 offSymPtr = SYMDEFOFFSET(offSegment, SegDef, iSym); 620 rc = fseek(hSym, offSymPtr, SEEK_SET); 621 if (rc) 622 { /* Symboloffset seek failed, try read next symbol. */ 623 dprintf(("Warning: Seek failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc)); 624 continue; 625 } 626 rc = fread(&offSym, sizeof(unsigned short int), 1, hSym); 627 if (!rc) 628 { /* Symboloffset read failed, try read next symbol. */ 629 dprintf(("Warning: read failed (offSymPtr=%d, rc=%d)\n", offSymPtr, rc)); 630 continue; 631 } 632 rc = fseek(hSym, offSym + offSegment, SEEK_SET); 633 if (rc) 634 { /* Symbol Seek failed, try read next symbol. */ 635 dprintf(("Warning: Seek failed (offSym=%d, rc=%d)\n", offSym, rc)); 636 continue; 637 } 638 639 640 /* 641 * Read symbol and symbolname. 642 */ 643 if (SegDef.bFlags & 0x01) 644 rc = fread(&SymDef32, sizeof(SYMDEF32), 1, hSym); 645 else 646 rc = fread(&SymDef16, sizeof(SYMDEF16), 1, hSym); 647 if (!rc) 648 { /* Symbol read failed, try read next symbol */ 649 dprintf(("Warning: Read(1) failed (offSym=%d, rc=%d)\n", offSym, rc)); 650 continue; 651 } 652 achBuffer[0] = (SegDef.bFlags & 0x01) ? SymDef32.achSymName[0] : SymDef16.achSymName[0]; 653 cchName = (SegDef.bFlags & 0x01) ? SymDef32.cbSymName : SymDef16.cbSymName; 654 rc = fread(&achBuffer[1], 1, cchName, hSym); 655 if (!rc) 656 { /* Symbol read failed, try read next symbol */ 657 dprintf(("Warning: Read(2) failed (offSym=%d, rc=%d)\n", offSym, rc)); 658 continue; 659 } 660 achBuffer[cchName] = '\0'; 661 662 663 /* 664 * Search proctable. 665 */ 666 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 550 667 { 551 if (kstrncmp(aProcTab[i].achName, Buffer, aProcTab[i].cchName) == 0) 552 { 553 aProcTab[i].offObject = (SegDef.bFlags & 0x01 ? SymDef32.wSymVal : SymDef16.wSymVal); 554 aProcTab[i].ulAddress= aProcTab[i].offObject + KrnlOTEs.aObjects[KrnlOTEs.cObjects-1].ote_base; 555 556 if (aProcTab[i].offObject < KrnlOTEs.aObjects[KrnlOTEs.cObjects-1].ote_size) 668 if (!aImportTab[i].fFound /* Not allready found */ 669 && (aImportTab[i].fType & EPT_BIT_MASK) == fSegEPTBitType /* Equal bittype */ 670 && (fCode || (aImportTab[i].fType & EPT_VARIMPORT)) /* Don't look for code in a data segment and vice versa */ 671 && aImportTab[i].cchName == cchName /* Equal name length */ 672 && kstrncmp(aImportTab[i].achName, achBuffer, cchName) == 0 /* Equal name */ 673 ) 674 { /* Symbol was found */ 675 aImportTab[i].offObject = (SegDef.bFlags & 0x01 ? SymDef32.wSymVal : SymDef16.wSymVal); 676 aImportTab[i].ulAddress = aImportTab[i].offObject + KrnlOTEs.aObjects[iSeg].ote_base; 677 aImportTab[i].usSel = KrnlOTEs.aObjects[iSeg].ote_sel; 678 679 /* Paranoia test! */ 680 if (aImportTab[i].offObject < KrnlOTEs.aObjects[iSeg].ote_size) 557 681 { 558 aProcTab[i].fFound = TRUE; 559 LeftToFind--; 560 dprintf(("Found: %s at off 0x%lx addr 0x%lx\n", aProcTab[i].achName, aProcTab[i].offObject, aProcTab[i].ulAddress)); 561 break; 682 aImportTab[i].fFound = TRUE; 683 cLeftToFind--; 684 dprintf(("Found: %s at off 0x%lx addr 0x%lx, sel=0x%x\n", 685 aImportTab[i].achName, aImportTab[i].offObject, 686 aImportTab[i].ulAddress, aImportTab[i].usSel)); 562 687 } 563 else 564 { 565 fclose(SymFile); 566 return -56; 567 } 688 else/* test failed, continue on next symbol*/ 689 dprintf(("Error: Paranoia test failed for %s\n", aImportTab[i].achName));; 690 break; 568 691 } 569 } 570 } 571 } 572 573 fclose(SymFile); 574 return LeftToFind == 0 ? VerifyPrologs() : -57; 692 693 } /* aImportTab for-loop */ 694 695 } /* Symbol for-loop */ 696 697 } /* Segment for-loop */ 698 699 /* 700 * Close symbol file. 701 */ 702 fclose(hSym); 703 704 /* 705 * If not all procedures were found fail. 706 */ 707 if (cLeftToFind != 0) 708 return -57; 709 710 /* 711 * Verify function prologs and return. 712 */ 713 return VerifyPrologs(); 575 714 } 576 715 … … 598 737 * @result ulBuild is set. 599 738 */ 600 static int ReadOS2Krnl(char * filename)601 { 602 HFILE krnl;739 static int ReadOS2Krnl(char * pszFilename) 740 { 741 HFILE hKrnl; 603 742 unsigned long cbKrnl; 604 743 int rc; 605 744 606 krnl = fopen(filename, "rb");607 if ( krnl != 0)608 { 609 cbKrnl = fsize( krnl);610 if (!fseek( krnl, 0, SEEK_SET))611 rc = ReadOS2Krnl2( krnl, cbKrnl);745 hKrnl = fopen(pszFilename, "rb"); 746 if (hKrnl != 0) 747 { 748 cbKrnl = fsize(hKrnl); 749 if (!fseek(hKrnl, 0, SEEK_SET)) 750 rc = ReadOS2Krnl2(hKrnl, cbKrnl); 612 751 else 613 752 rc = -2; 614 fclose( krnl);753 fclose(hKrnl); 615 754 } 616 755 else … … 626 765 * @returns 0 on success. 627 766 * errorcodes on failure. (-1 >= rc >= -14) 767 * @param hKrnl 628 768 * @param 629 769 * @equiv … … 634 774 * @remark 635 775 */ 636 static int ReadOS2Krnl2(HFILE krnl, unsigned long cbKrnl)776 static int ReadOS2Krnl2(HFILE hKrnl, unsigned long cbKrnl) 637 777 { 638 778 int i, j; 639 779 int rc = 0; 640 char Buffer[KERNEL_ID_STRING_LENGTH + KERNEL_READ_SIZE];780 char achBuffer[KERNEL_ID_STRING_LENGTH + KERNEL_READ_SIZE]; 641 781 unsigned long offLXHdr; 642 782 struct e32_exe *pLXHdr; … … 644 784 645 785 /* find bldlevel string - "@#IBM:14.020#@ IBM OS/2 Kernel - 14.020F" */ 646 cbKrnl = fsize( krnl);647 if (fseek( krnl, 0, SEEK_SET))786 cbKrnl = fsize(hKrnl); 787 if (fseek(hKrnl, 0, SEEK_SET)) 648 788 return -2; 649 789 650 if (!fread(& Buffer[KERNEL_ID_STRING_LENGTH], 1, KERNEL_READ_SIZE, krnl))790 if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, KERNEL_READ_SIZE, hKrnl)) 651 791 return -3; 652 792 … … 657 797 { 658 798 659 kmemcpy( Buffer, &Buffer[KERNEL_READ_SIZE], KERNEL_ID_STRING_LENGTH);660 if (!fread(& Buffer[KERNEL_ID_STRING_LENGTH], 1, cbKrnl > KERNEL_READ_SIZE ? KERNEL_READ_SIZE : (int)cbKrnl, krnl))799 kmemcpy(achBuffer, &achBuffer[KERNEL_READ_SIZE], KERNEL_ID_STRING_LENGTH); 800 if (!fread(&achBuffer[KERNEL_ID_STRING_LENGTH], 1, cbKrnl > KERNEL_READ_SIZE ? KERNEL_READ_SIZE : (int)cbKrnl, hKrnl)) 661 801 return -3; 662 802 … … 664 804 } 665 805 666 if (kstrncmp("@#IBM:", & Buffer[i], 6) == 0)806 if (kstrncmp("@#IBM:", &achBuffer[i], 6) == 0) 667 807 break; 668 808 … … 674 814 if (cbKrnl == 0) 675 815 { 676 fclose( krnl);816 fclose(hKrnl); 677 817 return -4; 678 818 } … … 680 820 /* displacement */ 681 821 j = 0; 682 while (j < 6 && Buffer[i+10+j] != '#')822 while (j < 6 && achBuffer[i+10+j] != '#') 683 823 j++; 684 824 685 825 /* verify signature */ 686 if (kstrncmp(& Buffer[i+10+j], "#@ IBM OS/2 Kernel", 19) != 0)826 if (kstrncmp(&achBuffer[i+10+j], "#@ IBM OS/2 Kernel", 19) != 0) 687 827 return -5; 688 828 689 829 /* read ulBuild */ 690 ulBuild = (char)( Buffer[i+6] - '0') * 1000;691 if ( Buffer[i+7] != '.')830 ulBuild = (char)(achBuffer[i+6] - '0') * 1000; 831 if (achBuffer[i+7] != '.') 692 832 { 693 833 /* this code is for Warp5 */ 694 834 ulBuild *= 10; 695 ulBuild += (char)( Buffer[i+7] - '0') * 1000;835 ulBuild += (char)(achBuffer[i+7] - '0') * 1000; 696 836 i++; 697 837 j--; 698 if ( Buffer[i+7] != '.')838 if (achBuffer[i+7] != '.') 699 839 { 700 840 ulBuild = ulBuild * 10; 701 ulBuild = ulBuild + (unsigned long)( Buffer[i+7] - '0') * 1000;841 ulBuild = ulBuild + (unsigned long)(achBuffer[i+7] - '0') * 1000; 702 842 i++; 703 843 j--; … … 707 847 if (j == 0) 708 848 { 709 ulBuild += ( Buffer[i+ 8] - '0') * 10;710 ulBuild += ( Buffer[i+ 9] - '0') * 1;849 ulBuild += (achBuffer[i+ 8] - '0') * 10; 850 ulBuild += (achBuffer[i+ 9] - '0') * 1; 711 851 } else 712 852 { 713 853 if (j == 3) 714 854 return -9; 715 ulBuild += ( Buffer[i+ 8] - '0') * 100;716 ulBuild += ( Buffer[i+ 9] - '0') * 10;717 ulBuild += ( Buffer[i+10] - '0');855 ulBuild += (achBuffer[i+ 8] - '0') * 100; 856 ulBuild += (achBuffer[i+ 9] - '0') * 10; 857 ulBuild += (achBuffer[i+10] - '0'); 718 858 } 719 859 … … 724 864 /* get segment number */ 725 865 /* read-MZheader */ 726 if (fseek( krnl,0,SEEK_SET))866 if (fseek(hKrnl,0,SEEK_SET)) 727 867 return -2; 728 868 729 if (!fread( Buffer, 1, 0x40, krnl))869 if (!fread(achBuffer, 1, 0x40, hKrnl)) 730 870 return -3; 731 871 732 offLXHdr = *(unsigned long int *)& Buffer[0x3c];872 offLXHdr = *(unsigned long int *)&achBuffer[0x3c]; 733 873 734 874 if (offLXHdr > 0x2000 && offLXHdr < 0x80) /* just to detect garbage */ 735 875 return -6; 736 876 737 if (fseek( krnl, offLXHdr, SEEK_SET))877 if (fseek(hKrnl, offLXHdr, SEEK_SET)) 738 878 return -2; 739 879 740 if (!fread( Buffer, 1, sizeof(struct e32_exe), krnl))880 if (!fread(achBuffer, 1, sizeof(struct e32_exe), hKrnl)) 741 881 return -3; 742 882 743 883 /* check LX-magic */ 744 if ( Buffer[0] != 'L' ||Buffer[1] != 'X')884 if (achBuffer[0] != 'L' || achBuffer[1] != 'X') 745 885 return -7; 746 886 747 887 #ifndef DEBUGR3 748 888 /* check object count - match it with what we got from the kernel. */ 749 pLXHdr = (struct e32_exe *) Buffer;889 pLXHdr = (struct e32_exe *)achBuffer; 750 890 if ((UCHAR)pLXHdr->e32_objcnt != KrnlOTEs.cObjects) 751 891 return -8; … … 755 895 756 896 /* check objects (sizes and flags(?)) */ 757 if (!fseek( krnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))758 { 759 struct o32_obj *pObj = (struct o32_obj *) Buffer;897 if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET)) 898 { 899 struct o32_obj *pObj = (struct o32_obj *)achBuffer; 760 900 for (i = 0; i < (int)KrnlOTEs.cObjects; i++) 761 901 { 762 if (!fread( Buffer, 1, sizeof(OTE), krnl))902 if (!fread(achBuffer, 1, sizeof(OTE), hKrnl)) 763 903 return -11; 764 904 if (pObj->o32_size < KrnlOTEs.aObjects[i].ote_size) … … 779 919 780 920 /* object count */ 781 pLXHdr = (struct e32_exe *) Buffer;921 pLXHdr = (struct e32_exe *)achBuffer; 782 922 KrnlOTEs.cObjects = (UCHAR)pLXHdr->e32_objcnt; 783 923 784 924 /* get OTEs */ 785 if (!fseek( krnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET))786 { 787 struct o32_obj *pObj = (struct o32_obj *) Buffer;925 if (!fseek(hKrnl, (LONG)offLXHdr + (LONG)pLXHdr->e32_objtab, SEEK_SET)) 926 { 927 struct o32_obj *pObj = (struct o32_obj *)achBuffer; 788 928 for (i = 0; i < (int)KrnlOTEs.cObjects; i++) 789 if (!fread(&KrnlOTEs.aObjects[i], 1, sizeof(struct o32_obj), krnl))929 if (!fread(&KrnlOTEs.aObjects[i], 1, sizeof(struct o32_obj), hKrnl)) 790 930 return -11; 791 931 } … … 911 1051 puts(szUsrSym); 912 1052 913 for (i = 0; i < N UMBER_OF_PROCS; i++)1053 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 914 1054 { 915 1055 if ((i % 2) == 0) … … 917 1057 else 918 1058 puts(" "); 919 puts(a ProcTab[i].achName);920 for (j = a ProcTab[i].cchName; j < 20; j++)1059 puts(aImportTab[i].achName); 1060 for (j = aImportTab[i].cchName; j < 20; j++) 921 1061 puts(" "); 922 1062 923 1063 puts(" at "); 924 if (a ProcTab[i].fFound)925 ShowHexNumber(a ProcTab[i].ulAddress);1064 if (aImportTab[i].fFound) 1065 ShowHexNumber(aImportTab[i].ulAddress); 926 1066 else 927 1067 puts(szMsgfailed); -
trunk/src/win32k/dev32/d32init.c
r2827 r2831 1 /* $Id: d32init.c,v 1.1 0 2000-02-19 08:40:29 bird Exp $1 /* $Id: d32init.c,v 1.11 2000-02-19 23:51:59 bird Exp $ 2 2 * 3 3 * d32init.c - 32-bits init routines. … … 54 54 55 55 /* extern(s) located in calltab.asm */ 56 extern char callTab[N UMBER_OF_PROCS][MAXSIZE_PROLOG];56 extern char callTab[NBR_OF_KRNLIMPORTS][MAXSIZE_PROLOG]; 57 57 58 58 /* extern(s) located in mytkExecPgm.asm */ … … 342 342 343 343 /** 344 * Verifies the a ProcTab.344 * Verifies the aImportTab. 345 345 * @returns 0 if ok. !0 if not ok. 346 346 * @remark Called from IOCtl. … … 352 352 353 353 /* verify */ 354 for (i = 0; i < N UMBER_OF_PROCS; i++)354 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 355 355 { 356 356 /* verify that it is found */ 357 if (!_a ProcTab[i].fFound)357 if (!_aImportTab[i].fFound) 358 358 { 359 359 kprintf(("VerifyProcTab32: procedure no.%d was not found!\n", i)); … … 362 362 363 363 /* verify read/writeable. - FIXME */ 364 if (_a ProcTab[i].ulAddress < 0xffe00000UL)364 if (_aImportTab[i].ulAddress < 0xffe00000UL) 365 365 { 366 366 kprintf(("VerifyProcTab32: procedure no.%d has an invlalid address, %#08x!\n", 367 i, _a ProcTab[i].ulAddress));367 i, _aImportTab[i].ulAddress)); 368 368 return STATUS_DONE | STERR | 2; 369 369 } 370 370 371 switch (_a ProcTab[i].fType)371 switch (_aImportTab[i].fType) 372 372 { 373 373 case EPT_PROC: 374 374 case EPT_PROCIMPORT: 375 375 /* verify known function prolog. */ 376 if ((cb = interpretFunctionProlog((char*)_a ProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC))376 if ((cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC)) 377 377 <= 0 && cb + 5 >= MAXSIZE_PROLOG) 378 378 { … … 534 534 * verify proctable 535 535 */ 536 for (i = 0; i < N UMBER_OF_PROCS; i++)537 { 538 if (_a ProcTab[i].fType != EPT_PROC && _aProcTab[i].fType != EPT_PROCIMPORT)536 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 537 { 538 if (_aImportTab[i].fType != EPT_PROC && _aImportTab[i].fType != EPT_PROCIMPORT) 539 539 { 540 540 kprintf(("procInit: EPT_VAR is not supported. (procedure no.%d, cb=%d)\n", i, cb)); 541 541 return 1; 542 542 } 543 cb = interpretFunctionProlog((char*)_a ProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC);543 cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, _aImportTab[i].fType == EPT_PROC); 544 544 if (cb <= 0 || cb + 5 >= MAXSIZE_PROLOG) 545 545 { … … 552 552 * rehook / import 553 553 */ 554 for (i = 0; i < N UMBER_OF_PROCS; i++)555 { 556 switch (_a ProcTab[i].fType)554 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++) 555 { 556 switch (_aImportTab[i].fType) 557 557 { 558 558 case EPT_PROC: 559 559 { 560 cb = interpretFunctionProlog((char*)_a ProcTab[i].ulAddress, TRUE);560 cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, TRUE); 561 561 if (cb > 0 && cb + 5 < MAXSIZE_PROLOG) 562 562 { 563 static unsigned auFuncs[N UMBER_OF_PROCS] = /* This table must be updated with the overloading functions. */563 static unsigned auFuncs[NBR_OF_KRNLIMPORTS] = /* This table must be updated with the overloading functions. */ 564 564 { 565 565 (unsigned)myldrRead, … … 580 580 581 581 /* copy function prolog */ 582 memcpy(callTab[i], (void*)_a ProcTab[i].ulAddress, (size_t)cb);582 memcpy(callTab[i], (void*)_aImportTab[i].ulAddress, (size_t)cb); 583 583 584 584 /* jump from calltab to original function */ 585 585 callTab[i][cb] = 0xE9; /* jmp */ 586 *(unsigned*)(void*)&callTab[i][cb+1] = _a ProcTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5];586 *(unsigned*)(void*)&callTab[i][cb+1] = _aImportTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5]; 587 587 588 588 589 589 /* jump from original function to my function - an cli(?) could be needed here */ 590 *(char*)_a ProcTab[i].ulAddress = 0xE9; /* jmp */591 *(unsigned*)(_a ProcTab[i].ulAddress + 1) = auFuncs[i] - (_aProcTab[i].ulAddress + 5);590 *(char*)_aImportTab[i].ulAddress = 0xE9; /* jmp */ 591 *(unsigned*)(_aImportTab[i].ulAddress + 1) = auFuncs[i] - (_aImportTab[i].ulAddress + 5); 592 592 } 593 593 else … … 602 602 case EPT_PROCIMPORT: 603 603 { 604 cb = interpretFunctionProlog((char*)_a ProcTab[i].ulAddress, FALSE);604 cb = interpretFunctionProlog((char*)_aImportTab[i].ulAddress, FALSE); 605 605 if (cb > 0 && cb + 5 < MAXSIZE_PROLOG) 606 606 { 607 607 /* jump from calltab to original function */ 608 608 callTab[i][0] = 0xE9; /* jmp */ 609 *(unsigned*)(void*)&callTab[i][1] = _a ProcTab[i].ulAddress - (unsigned)&callTab[i][cb+5];609 *(unsigned*)(void*)&callTab[i][1] = _aImportTab[i].ulAddress - (unsigned)&callTab[i][cb+5]; 610 610 } 611 611 else -
trunk/src/win32k/include/dev16.h
r2799 r2831 1 /* $Id: dev16.h,v 1. 4 2000-02-15 23:39:19bird Exp $1 /* $Id: dev16.h,v 1.5 2000-02-19 23:52:00 bird Exp $ 2 2 * dev16 - 16-bit specific. Should not be used in 32-bit C/C++. 3 3 * … … 40 40 41 41 /* 42 * Get Kernel OTEs. No params. No data. a ProcTab is used.42 * Get Kernel OTEs. No params. No data. aImportTab is used. 43 43 */ 44 44 #define D16_IOCTL_VERIFYPROCTAB 0x42 -
trunk/src/win32k/include/dev1632.h
r2799 r2831 1 /* $Id: dev1632.h,v 1. 2 2000-02-15 23:39:19bird Exp $1 /* $Id: dev1632.h,v 1.3 2000-02-19 23:52:00 bird Exp $ 2 2 * dev1632.h - Common header file for 16-bit and 32-bit C 3 3 * … … 46 46 #ifdef _OS2Krnl_h_ 47 47 48 48 49 #define MAXKRNLOBJECTS 24 49 50 typedef struct _KRNLOBJTABLE -
trunk/src/win32k/include/probkrnl.h
r2827 r2831 1 /* $Id: probkrnl.h,v 1. 7 2000-02-19 08:40:30 bird Exp $1 /* $Id: probkrnl.h,v 1.8 2000-02-19 23:52:00 bird Exp $ 2 2 * 3 3 * Include file for ProbKrnl. … … 16 16 * Defined Constants And Macros * 17 17 *******************************************************************************/ 18 #define NUMBER_OF_PROCS 14 19 #define MAX_LENGTH_NAME 32 18 #define NBR_OF_KRNLIMPORTS 16 /* When this is changed make sure to */ 19 /* update the arrays in d32init.c and */ 20 /* probkrnl32.c */ 21 #define MAX_LENGTH_NAME 32 /* Max length for the function. */ 20 22 21 /* entry-point type flag */ 22 #define EPT_PROC 0 /* procedure - overload procedure*/ 23 #define EPT_PROCIMPORT 1 /* procedure - import only */ 24 #define EPT_VAR 2 /* variable/non-procedure - not implemented yet */ 23 /* Entry-Point Type flag */ 24 #define EPT_PROC 0x00 /* procedure - overload procedure*/ 25 #define EPT_PROCIMPORT 0x01 /* procedure 32bit - import only */ 26 #define EPT_VARIMPORT 0x02 /* variable/non-procedure 32bit - not implemented yet */ 27 #define EPT_32BIT 0x00 /* 16 bit entry-point */ 28 #define EPT_16BIT 0x80 /* 32 bit entry-point */ 29 #define EPT_BIT_MASK 0x80 /* Mask bit entry-point */ 30 #define EPT16BitEntry(a) (((a).fType & EPT_BIT_MASK) == EPT_16BIT) 31 #define EPT32BitEntry(a) (((a).fType & EPT_BIT_MASK) == EPT_32BIT) 32 33 /* 32bit types */ 34 #define EPT_PROC32 (EPT_PROC | EPT_32BIT) 35 #define EPT_PROCIMPORT32 (EPT_PROCIMPORT | EPT_32BIT) 36 37 /* 16bit types */ 38 #define EPT_PROC16 (EPT_PROC | EPT_16BIT) /* no implemented yet! */ 39 #define EPT_PROCIMPORT16 (EPT_PROCIMPORT | EPT_16BIT) /* far proc in calltab with a far jmp. */ 25 40 26 41 … … 29 44 *******************************************************************************/ 30 45 #pragma pack(1) 31 typedef struct tag PROCS46 typedef struct tagIMPORTKRNLSYM 32 47 { 33 unsigned char fFound; 34 unsigned char iObject; 35 unsigned short int cchName; 36 unsigned char achName[MAX_LENGTH_NAME]; 37 unsigned long int offObject; 38 unsigned long int ulAddress; 39 unsigned char fType; 40 } PROCS; 48 unsigned char fFound; /* This is set when name is found */ 49 unsigned char iObject; /* Object number the name was found in*/ 50 unsigned short int cchName; /* Length of the name (optmize search) (INPUT) */ 51 unsigned char achName[MAX_LENGTH_NAME]; /* Name (INPUT) */ 52 unsigned long int offObject; /* Offset into the object */ 53 unsigned long int ulAddress; /* 32-bit flat address */ 54 unsigned short int usSel; /* Select of the object */ 55 unsigned char fType; /* Entry-Point Type Flags */ 56 } IMPORTKRNLSYM; 41 57 #pragma pack() 42 58 … … 47 63 * NOTE! These are only available at init time! * 48 64 *******************************************************************************/ 49 extern PROCS _aProcTab[NUMBER_OF_PROCS]; /* 'aProcTab'in PrbKrnl.c */50 extern unsigned long int _ulBuild; 51 extern unsigned short int _usVerMajor; 52 extern unsigned short int _usVerMinor; 65 extern IMPORTKRNLSYM _aImportTab[NBR_OF_KRNLIMPORTS]; /* 'aImportTab' in PrbKrnl.c */ 66 extern unsigned long int _ulBuild; /* 'ulBuild' in PrbKrnl.c */ 67 extern unsigned short int _usVerMajor; /* 'usVerMajor' in PrbKrnl.c */ 68 extern unsigned short int _usVerMinor; /* 'usVerMinor' in PrbKrnl.c */ 53 69 54 70 #ifdef INCL_16 /* 16-bit only */ -
trunk/src/win32k/include/sym.h
r1678 r2831 1 /* $Id: sym.h,v 1. 2 1999-11-10 01:45:34bird Exp $1 /* $Id: sym.h,v 1.3 2000-02-19 23:52:00 bird Exp $ 2 2 * 3 3 * Sym-file definitions and structs. … … 52 52 } SEGDEF; 53 53 54 #define SEG_FLAGS_32BIT 0x01 /* 32bit segment is set. 16-bit segment if clear */ 55 #define SEG32BitSegment(a) (((a).bFlags & 0x01) == SEG_FLAGS_32BIT) 56 #define SEG16BitSegment(a) (((a).bFlags & 0x01) == 0) 57 54 58 typedef struct 55 59 { -
trunk/src/win32k/ldr/calltab.asm
r2827 r2831 1 ; $Id: calltab.asm,v 1. 6 2000-02-19 08:40:30 bird Exp $1 ; $Id: calltab.asm,v 1.7 2000-02-19 23:52:00 bird Exp $ 2 2 ; 3 3 ; callTab - Call back again table - table with entry for each function which is overrided. … … 50 50 ; Imported and Overrided OS/2 kernel functions are called tru this table. 51 51 ; 52 ; This array of near procedures are parallel to the a ProcTab array in dev16\ProbKrnl.c.52 ; This array of near procedures are parallel to the aImportTab array in dev16\ProbKrnl.c. 53 53 ; Remember to update both!. 54 54 ;
Note:
See TracChangeset
for help on using the changeset viewer.