Ignore:
Timestamp:
Jan 22, 2000, 7:21:03 PM (26 years ago)
Author:
bird
Message:

Temporary backup checkin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/dev32/d32init.c

    r1678 r2501  
    1 /* $Id: d32init.c,v 1.4 1999-11-10 01:45:30 bird Exp $
     1/* $Id: d32init.c,v 1.5 2000-01-22 18:20:57 bird Exp $
    22 *
    33 * d32init.c - 32-bits init routines.
     
    1919#define INCL_NOPMAPI
    2020#define LDR_INCL_INITONLY
     21
    2122
    2223/*******************************************************************************
     
    4344*******************************************************************************/
    4445static ULONG    readnum(const char *pszNum);
    45 static int      interpretFunctionProlog(char *p);
     46static int      interpretFunctionProlog(char *p, BOOL fOverload);
    4647static int      procInit(void);
    4748
    4849
    4950/* externs located in 16-bit data segement */
    50 extern ULONG  _TKSSBase16;
    51 extern USHORT _R0FlatCS16;
    52 extern USHORT _R0FlatDS16;
     51extern ULONG    _TKSSBase16;
     52extern USHORT   _R0FlatCS16;
     53extern USHORT   _R0FlatDS16;
    5354
    5455
    5556/* extern(s) located in calltab.asm */
    56 extern char callTab[NUMBER_OF_PROCS][MAXSIZE_PROLOG];
     57extern char     callTab[NUMBER_OF_PROCS][MAXSIZE_PROLOG];
    5758
    5859
     
    8889    while (pszTmp != NULL)
    8990    {
    90         char cch;
     91        int cch;
    9192        pszTmp++; //skip [-/]
    9293        cch = strlen(pszTmp);
     
    309310        if (pszNum[1] == 'x' || pszNum[1] == 'X')
    310311        {
    311             ulBase == 16;
     312            ulBase = 16;
    312313            pszNum += 2;
    313314        }
    314315        else
    315316        {
    316             ulBase == 8;
     317            ulBase = 8;
    317318            i = 1;
    318319        }
     
    364365        }
    365366
    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;
    379383        }
    380384    }
     
    408412        if (pSMTE != NULL)
    409413        {
    410             pOTEBuf->cObjects = pSMTE->smte_objcnt;
     414            pOTEBuf->cObjects = (unsigned char)pSMTE->smte_objcnt;
    411415            if (pSMTE->smte_objcnt <= MAXKRNLOBJECTS)
    412416            {
     
    433437        kprintf(("GetOTEs32: failed. usRc = %d\n", usRc));
    434438
    435     return usRc | (usRc != 0 ? STATUS_DONE | STERR : STATUS_DONE);
     439    return (USHORT)(usRc | (usRc != NO_ERROR ? STATUS_DONE | STERR : STATUS_DONE));
    436440}
    437441
     
    442446 *            where the jmp instr should be placed.
    443447 *            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.
    445451 */
    446 static int interpretFunctionProlog(char *p)
     452static int interpretFunctionProlog(char *pach, BOOL fOverload)
    447453{
    448     int length;
    449454    int rc;
    450455
     
    459464     */
    460465
    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)
    464469            rc = 3;
    465470        else
     
    472477             * There will never be any doubt when something goes wrong!
    473478             */
    474             switch(p[rc])
     479            switch(pach[rc])
    475480            {
    476481                case 0x33: /* xor (ldrClose, ldrOpen) */
     
    478483                    break;
    479484                case 0x8b:
    480                     if (p[rc+1] == 0x0d)
     485                    if (pach[rc+1] == 0x0d)
    481486                        rc += 6;
    482487                    else
     
    490495                    break;
    491496                default:
    492                     kprintf(("interpretFunctionProlog: unknown instruction 0x%x \n", p[rc]));
     497                    kprintf(("interpretFunctionProlog: unknown instruction 0x%x\n", pach[rc]));
    493498                    return 0;
    494499            }
     
    496501    }
    497502    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    }
    499510
    500511    return rc;
     
    512523    int cb;
    513524
    514     /* verify */
     525    /*
     526     * verify proctable
     527     */
    515528    for (i = 0; i < NUMBER_OF_PROCS; i++)
    516529    {
    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);
    518536        if (cb <= 0 || cb + 5 >= MAXSIZE_PROLOG)
    519537        {
    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));
    521539            return 1;
    522540        }
    523541    }
    524542
    525     /* rehook */
     543    /*
     544     * rehook / import
     545     */
    526546    for (i = 0; i < NUMBER_OF_PROCS; i++)
    527547    {
    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:
    533551            {
    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;
    543588            }
    544589
    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 */
    564614
    565615    return NO_ERROR;
Note: See TracChangeset for help on using the changeset viewer.