Changeset 2501 for trunk/src/win32k/dev32/d32init.c
- Timestamp:
- Jan 22, 2000, 7:21:03 PM (26 years ago)
- File:
-
- 1 edited
-
trunk/src/win32k/dev32/d32init.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/dev32/d32init.c
r1678 r2501 1 /* $Id: d32init.c,v 1. 4 1999-11-10 01:45:30bird Exp $1 /* $Id: d32init.c,v 1.5 2000-01-22 18:20:57 bird Exp $ 2 2 * 3 3 * d32init.c - 32-bits init routines. … … 19 19 #define INCL_NOPMAPI 20 20 #define LDR_INCL_INITONLY 21 21 22 22 23 /******************************************************************************* … … 43 44 *******************************************************************************/ 44 45 static ULONG readnum(const char *pszNum); 45 static int interpretFunctionProlog(char *p );46 static int interpretFunctionProlog(char *p, BOOL fOverload); 46 47 static int procInit(void); 47 48 48 49 49 50 /* externs located in 16-bit data segement */ 50 extern ULONG _TKSSBase16;51 extern USHORT _R0FlatCS16;52 extern USHORT _R0FlatDS16;51 extern ULONG _TKSSBase16; 52 extern USHORT _R0FlatCS16; 53 extern USHORT _R0FlatDS16; 53 54 54 55 55 56 /* extern(s) located in calltab.asm */ 56 extern char callTab[NUMBER_OF_PROCS][MAXSIZE_PROLOG];57 extern char callTab[NUMBER_OF_PROCS][MAXSIZE_PROLOG]; 57 58 58 59 … … 88 89 while (pszTmp != NULL) 89 90 { 90 charcch;91 int cch; 91 92 pszTmp++; //skip [-/] 92 93 cch = strlen(pszTmp); … … 309 310 if (pszNum[1] == 'x' || pszNum[1] == 'X') 310 311 { 311 ulBase = =16;312 ulBase = 16; 312 313 pszNum += 2; 313 314 } 314 315 else 315 316 { 316 ulBase = =8;317 ulBase = 8; 317 318 i = 1; 318 319 } … … 364 365 } 365 366 366 /* verify known function prolog. (only EPT_PROC) */ 367 if (_aProcTab[i].fType == EPT_PROC) 368 { 369 if ((cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress)) <= 0 && cb + 5 >= MAXSIZE_PROLOG) 370 { 371 kprintf(("VerifyProcTab32: verify failed for procedure no.%d\n",i)); 372 return STATUS_DONE | STERR | 3; 373 } 374 } 375 else 376 { 377 kprintf(("VerifyProcTab32: only EPT_PROC is implemented\n",i)); 378 return STATUS_DONE | STERR | 4; 367 switch (_aProcTab[i].fType) 368 { 369 case EPT_PROC: 370 case EPT_PROCIMPORT: 371 /* verify known function prolog. */ 372 if ((cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC)) 373 <= 0 && cb + 5 >= MAXSIZE_PROLOG) 374 { 375 kprintf(("VerifyProcTab32: verify failed for procedure no.%d\n",i)); 376 return STATUS_DONE | STERR | 3; 377 } 378 break; 379 380 default: 381 kprintf(("VerifyProcTab32: only EPT_PROC is implemented\n",i)); 382 return STATUS_DONE | STERR | 4; 379 383 } 380 384 } … … 408 412 if (pSMTE != NULL) 409 413 { 410 pOTEBuf->cObjects = pSMTE->smte_objcnt;414 pOTEBuf->cObjects = (unsigned char)pSMTE->smte_objcnt; 411 415 if (pSMTE->smte_objcnt <= MAXKRNLOBJECTS) 412 416 { … … 433 437 kprintf(("GetOTEs32: failed. usRc = %d\n", usRc)); 434 438 435 return usRc | (usRc != 0 ? STATUS_DONE | STERR : STATUS_DONE);439 return (USHORT)(usRc | (usRc != NO_ERROR ? STATUS_DONE | STERR : STATUS_DONE)); 436 440 } 437 441 … … 442 446 * where the jmp instr should be placed. 443 447 * On error it returns 0. 444 * @param p Pointer to prolog. 448 * @param pach Pointer to prolog. 449 * @param fOverload TRUE: Function is to be overloaded. 450 * FALSE: Function is to be imported. 445 451 */ 446 static int interpretFunctionProlog(char *p )452 static int interpretFunctionProlog(char *pach, BOOL fOverload) 447 453 { 448 int length;449 454 int rc; 450 455 … … 459 464 */ 460 465 461 if (p [0] == 0x55 && p[1] == 0x8b)462 { 463 if (p [2] == 0xec)466 if (pach[0] == 0x55 && pach[1] == 0x8b) 467 { 468 if (pach[2] == 0xec) 464 469 rc = 3; 465 470 else … … 472 477 * There will never be any doubt when something goes wrong! 473 478 */ 474 switch(p [rc])479 switch(pach[rc]) 475 480 { 476 481 case 0x33: /* xor (ldrClose, ldrOpen) */ … … 478 483 break; 479 484 case 0x8b: 480 if (p [rc+1] == 0x0d)485 if (pach[rc+1] == 0x0d) 481 486 rc += 6; 482 487 else … … 490 495 break; 491 496 default: 492 kprintf(("interpretFunctionProlog: unknown instruction 0x%x \n", p[rc]));497 kprintf(("interpretFunctionProlog: unknown instruction 0x%x\n", pach[rc])); 493 498 return 0; 494 499 } … … 496 501 } 497 502 else 498 rc = 0; 503 { 504 /* special case for IOSftReadAt and IOSftWriteAt */ 505 if (fOverload == FALSE && pach[0] == 0xB8 && (pach[5] == 0xEB || pach[5] == 0x55)) 506 rc = 5; 507 else 508 rc = 0; 509 } 499 510 500 511 return rc; … … 512 523 int cb; 513 524 514 /* verify */ 525 /* 526 * verify proctable 527 */ 515 528 for (i = 0; i < NUMBER_OF_PROCS; i++) 516 529 { 517 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress); 530 if (_aProcTab[i].fType != EPT_PROC && _aProcTab[i].fType != EPT_PROCIMPORT) 531 { 532 kprintf(("procInit: EPT_VAR is not supported. (procedure no.%d, cb=%d)\n", i, cb)); 533 return 1; 534 } 535 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, _aProcTab[i].fType == EPT_PROC); 518 536 if (cb <= 0 || cb + 5 >= MAXSIZE_PROLOG) 519 537 { 520 kprintf((" rehookFunctions: verify failed for procedure no.%d, cb=%d\n", i, cb));538 kprintf(("procInit: verify failed for procedure no.%d, cb=%d\n", i, cb)); 521 539 return 1; 522 540 } 523 541 } 524 542 525 /* rehook */ 543 /* 544 * rehook / import 545 */ 526 546 for (i = 0; i < NUMBER_OF_PROCS; i++) 527 547 { 528 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress); 529 if (cb > 0 && cb + 5 < MAXSIZE_PROLOG) 530 { 531 char *pMy; 532 switch (i) 548 switch (_aProcTab[i].fType) 549 { 550 case EPT_PROC: 533 551 { 534 case iLDRREAD: pMy = (char*)myldrRead; break; 535 case iLDROPEN: pMy = (char*)myldrOpen; break; 536 case iLDRCLOSE: pMy = (char*)myldrClose; break; 537 case iLDRQAPPTYPE: pMy = (char*)myLDRQAppType; break; 538 539 default: 540 kprintf(("rehookFunctions: Someone has added function without updating the switch! i=%d\n", i)); 541 Int3(); 542 return 2; 552 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, TRUE); 553 if (cb > 0 && cb + 5 < MAXSIZE_PROLOG) 554 { 555 static unsigned auFuncs[NUMBER_OF_PROCS] = /* This table must be updated with the overloading functions. */ 556 { 557 (unsigned)myldrRead, 558 (unsigned)myldrOpen, 559 (unsigned)myldrClose, 560 (unsigned)myLDRQAppType, 561 (unsigned)myldrEnum32bitRelRecs, 562 0, 563 0, 564 0, 565 0, 566 0, 567 }; 568 569 /* copy function prolog */ 570 memcpy(callTab[i], (void*)_aProcTab[i].ulAddress, (size_t)cb); 571 572 /* jump from calltab to original function */ 573 callTab[i][cb] = 0xE9; /* jmp */ 574 *(unsigned*)(void*)&callTab[i][cb+1] = _aProcTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5]; 575 576 577 /* jump from original function to my function - an cli(?) could be needed here */ 578 *(char*)_aProcTab[i].ulAddress = 0xE9; /* jmp */ 579 *(unsigned*)(_aProcTab[i].ulAddress + 1) = auFuncs[i] - (_aProcTab[i].ulAddress + 5); 580 } 581 else 582 { /* !fatal! - this could never happen really... */ 583 kprintf(("procInit: FATAL verify failed for procedure no.%d when rehooking it!\n",i)); 584 Int3(); /* ipe - later! */ 585 return 1; 586 } 587 break; 543 588 } 544 589 545 /* copy function prolog */ 546 memcpy(callTab[i], (void*)_aProcTab[i].ulAddress, (size_t)cb); 547 548 /* jump from calltab to original function */ 549 callTab[i][cb] = 0xE9; /* jmp */ 550 *(unsigned*)&callTab[i][cb+1] = _aProcTab[i].ulAddress + cb - (unsigned)&callTab[i][cb+5]; 551 552 /* jump from original function to my function - an cli could be needed here */ 553 *(char*)_aProcTab[i].ulAddress = 0xE9; /* jmp */ 554 *(unsigned*)(_aProcTab[i].ulAddress + 1) = (unsigned)pMy - (_aProcTab[i].ulAddress + 5); 555 } 556 else 557 { 558 /* !fatal! - this could never happen really... */ 559 kprintf(("rehookFunctions: FATAL verify failed for procedure no.%d when rehooking it!\n",i)); 560 Int3(); /* ipe - later! */ 561 return 1; 562 } 563 } 590 case EPT_PROCIMPORT: 591 { 592 cb = interpretFunctionProlog((char*)_aProcTab[i].ulAddress, FALSE); 593 if (cb > 0 && cb + 5 < MAXSIZE_PROLOG) 594 { 595 /* jump from calltab to original function */ 596 callTab[i][0] = 0xE9; /* jmp */ 597 *(unsigned*)(void*)&callTab[i][1] = _aProcTab[i].ulAddress - (unsigned)&callTab[i][cb+5]; 598 } 599 else 600 { /* !fatal! - this could never happen really... */ 601 kprintf(("procInit: FATAL verify failed for procedure no.%d when importing it!\n",i)); 602 Int3(); /* ipe - later! */ 603 return 1; 604 } 605 break; 606 } 607 608 default: 609 kprintf(("procInit: EPT_VAR is not supported. (procedure no.%d, cb=%d)\n", i, cb)); 610 Int3(); /* ipe - later! */ 611 return 1; 612 } /* switch - type */ 613 } /* for */ 564 614 565 615 return NO_ERROR;
Note:
See TracChangeset
for help on using the changeset viewer.
