Changeset 6852 for trunk/src


Ignore:
Timestamp:
Sep 28, 2001, 9:43:03 AM (24 years ago)
Author:
sandervl
Message:

added options to strip fixups and to reroute imports to custom odin dll

Location:
trunk/src/win32k/pe2lx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/pe2lx/pe2lx.cpp

    r6493 r6852  
    1 /* $Id: pe2lx.cpp,v 1.32 2001-08-08 17:24:45 bird Exp $
     1/* $Id: pe2lx.cpp,v 1.33 2001-09-28 07:43:02 sandervl Exp $
    22 *
    33 * Pe2Lx class implementation. Ring 0 and Ring 3
     
    9494#include <stddef.h>                     /* C library stddef.h. */
    9595#include <stdarg.h>                     /* C library stdarg.h. */
     96#ifndef RING0
     97#include <stdio.h>
     98#endif
    9699
    97100#include "vprintf.h"                    /* win32k printf and vprintf. Not C library! */
     
    27802783    BufferedRVARead            *pImpThunkReader;    /* Buffered reader for thunk reads; ie. reading from the OrgiginalFirstThunk array. */
    27812784    ULONG                       ulModuleOrdinal;    /* Module ordinal. Valid as long as fImport is set. */
     2785    #ifndef RING0
     2786    ULONG                       ulCustomModOrdinal; /* Module ordinal of custom Odin dll. Valid as long as fImport is set. */
     2787    char                        szModuleName[128];
     2788    #endif
    27822789    ULONG                       ulRVAFirstThunk;    /* Current first thunk array RVA. Points at current entry. */
    27832790    ULONG                       ulRVAOrgFirstThunk; /* Current original first thunk array RVA. Points at current entry. */
     
    28312838        (ulRVABaseReloc = pNtHdrs->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress) > 0UL
    28322839        &&
    2833         ulRVABaseReloc < pNtHdrs->OptionalHeader.SizeOfImage;
     2840        ulRVABaseReloc < pNtHdrs->OptionalHeader.SizeOfImage
     2841        &&
     2842        areFixupsEnabled();
    28342843    #endif
    28352844    printInf(("\n"));
     
    28852894
    28862895    /* Make sure kernel32 is the first imported module */
    2887     if (rc == NO_ERROR)
    2888         rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
     2896    if (rc == NO_ERROR)
     2897    {
     2898        #ifndef RING0
     2899        if(hasCustomDll()) {
     2900            rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul));
     2901            ulCustomModOrdinal = ul;
     2902            strcpy(szModuleName, "KERNEL32");
     2903        }
     2904        else
     2905        #endif
     2906            rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
     2907    }
    28892908
    28902909    /* initiate the import variables */
     
    29152934                rc = pImpNameReader->dupString(ulModuleOrdinal, (PSZ*)SSToDS(&psz));
    29162935                if (rc == NO_ERROR)
    2917                     rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
    2918                 free(psz);
     2936                {
     2937                    #ifndef RING0
     2938                    if(hasCustomDll()) {
     2939                        ulModuleOrdinal = ulCustomModOrdinal;
     2940                        strcpy(szModuleName, psz);
     2941                        char *tmp = szModuleName;
     2942                        while(*tmp != 0 && *tmp != '.')
     2943                        {
     2944                            if(*tmp >= 'a' && *tmp <= 'z') {
     2945                                *tmp += ('A' - 'a');
     2946                            }
     2947                            tmp++;
     2948                        }
     2949                        *tmp = 0;
     2950                    }
     2951                    else
     2952                    #endif
     2953                        rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     2954
     2955                    free(psz);
     2956                }
    29192957            }
    29202958            else
     
    29502988            && ((paObjects[iObj].Misc.offTIBFix + paObjects[iObj].ulRVA) & ~(PAGESIZE-1UL)) == ulRVAPage)
    29512989        {
    2952             rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
     2990            #ifndef RING0
     2991            if(hasCustomDll()) {
     2992                rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul));
     2993                ulCustomModOrdinal = ul;
     2994            }
     2995            else
     2996            #endif
     2997                rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
    29532998            if (rc == NO_ERROR)
    29542999            {
     
    29573002                                         ul,
    29583003                                         pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_DLL ?
    2959                                             ORD_REGISTERPE2LXDLL : ORD_REGISTERPE2LXEXE);
     3004                                            ORD_REGISTERPE2LXDLL : ORD_REGISTERPE2LXEXE
     3005                #ifndef RING0
     3006                                         , "KERNEL32"
     3007                #endif
     3008                                         );
    29603009            }
    29613010            if (rc != NO_ERROR)
     
    29773026                    if (Thunk.u1.Ordinal & (ULONG)IMAGE_ORDINAL_FLAG)
    29783027                        rc = add32OrdImportFixup((WORD)(ulRVAFirstThunk & (PAGESIZE-1)),
    2979                                                  ulModuleOrdinal, Thunk.u1.Ordinal & 0xffff);
     3028                                                 ulModuleOrdinal, Thunk.u1.Ordinal & 0xffff
     3029                        #ifndef RING0
     3030                                                 , szModuleName
     3031                        #endif
     3032                                                 );
    29803033                    else if (Thunk.u1.Ordinal > 0UL && Thunk.u1.Ordinal < pNtHdrs->OptionalHeader.SizeOfImage)
    29813034                    {
     
    29853038                            break;
    29863039                        rc = add32NameImportFixup((WORD)(ulRVAFirstThunk & (PAGESIZE-1)),
    2987                                                   ulModuleOrdinal, psz);
     3040                                                  ulModuleOrdinal, psz
     3041                        #ifndef RING0
     3042                                                  , szModuleName
     3043                        #endif
     3044                                                 );
    29883045                        free(psz);
    29893046                    }
     
    30283085                            if (rc == NO_ERROR)
    30293086                            {
    3030                                 rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     3087                                #ifndef RING0
     3088                                if(hasCustomDll()) {
     3089                                    ulModuleOrdinal = ulCustomModOrdinal;
     3090                                    strcpy(szModuleName, psz);
     3091                                    char *tmp = szModuleName;
     3092                                    while(*tmp != 0 && *tmp != '.') {
     3093                                        if(*tmp >= 'a' && *tmp <= 'z') {
     3094                                            *tmp += ('A' - 'a');
     3095                                        }
     3096                                        tmp++;
     3097                                    }
     3098                                    *tmp = 0;
     3099                                }
     3100                                else
     3101                                #endif
     3102                                    rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
    30313103                                free(psz);
    30323104                            }
     
    38283900 *
    38293901 */
     3902#ifndef RING0
     3903ULONG  Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PSZ pszModuleName)
     3904#else
    38303905ULONG  Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal)
     3906#endif
    38313907{
    38323908    struct r32_rlc *prlc;
    38333909    ULONG           cbFixup;         /* size of the fixup record. */
     3910
     3911    #ifndef RING0
     3912    if(hasCustomDll() && pszModuleName)
     3913    {
     3914        char  searchstring[256];
     3915        char *found;
     3916
     3917        sprintf(searchstring, "%s.%d", pszModuleName, ulFunctionOrdinal);
     3918        found = strstr(options.pszCustomExports, searchstring);
     3919        if(found) {
     3920            while(*found != '@') {
     3921                found++;
     3922            }
     3923            ulFunctionOrdinal = atoi(++found);
     3924        }
     3925        else {
     3926            printf("Error: Export %s not found in table.\n\n", searchstring);
     3927            return ERROR_MOD_NOT_FOUND;
     3928        }
     3929    }
     3930    #endif
    38343931
    38353932    /* enough memory? */
     
    39534050 *
    39544051 */
     4052#ifndef RING0
     4053ULONG  Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PSZ pszModuleName)
     4054#else
    39554055ULONG  Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName)
     4056#endif
    39564057{
    39574058    APIRET          rc;
     
    39594060    ULONG           cbFixup;         /* size of the fixup record. */
    39604061    ULONG           offFnName;
     4062
     4063    #ifndef RING0
     4064    if(hasCustomDll())
     4065    {
     4066        char  searchstring[256];
     4067        char *found;
     4068        int   ordinal;
     4069
     4070        sprintf(searchstring, "%s.%s", pszModuleName, pszFnName);
     4071        found = strstr(options.pszCustomExports, searchstring);
     4072        if(found) {
     4073            while(*found != '@') {
     4074                found++;
     4075            }
     4076            ordinal = atoi(++found);
     4077            return add32OrdImportFixup(offSource, ulModuleOrdinal, ordinal, NULL);
     4078        }
     4079        else {
     4080            printf("Error: Export %s not found in table.\n\n", searchstring);
     4081            return ERROR_MOD_NOT_FOUND;
     4082        }
     4083    }
     4084    #endif
    39614085
    39624086    /* enough memory? */
     
    50095133    int i = 0;
    50105134
     5135    #ifndef RING0
     5136    if(hasCustomDll()) {
     5137        return pszWin32ModuleName;
     5138    }
     5139    #endif
    50115140    while (paLieList[i].pszWin32Name != NULL)
    50125141    {
  • trunk/src/win32k/pe2lx/pe2lxmain.cpp

    r5086 r6852  
    1 /* $Id: pe2lxmain.cpp,v 1.7 2001-02-10 11:11:48 bird Exp $
     1/* $Id: pe2lxmain.cpp,v 1.8 2001-09-28 07:43:03 sandervl Exp $
    22 *
    33 * Pe2Lx main program. (Ring 3 only!)
     
    3232#include <string.h>
    3333#include <stdlib.h>
     34#include <io.h>
     35#include <fcntl.h>
     36#include <sys/stat.h>
    3437#include "OS2Krnl.h"
    3538#include "modulebase.h"
     
    125128                    }
    126129                    break;
     130
     131                case 'f': //ignore internal fixups
     132                case 'F':
     133                    options.fSkipFixups = TRUE;
     134                    break;
     135
     136                case 'c':
     137                case 'C': //custom odin dll name
     138                    if(!hasCustomExports()) {
     139                        printf("Syntax error: export table file not specified (/O).\n\n");
     140                        return 5;
     141                    }
     142                    options.pszCustomDll = &argv[argi][3];
     143                    break;
     144                case 'o':
     145                case 'O':
     146                {
     147                    int fileIn = open(&argv[argi][3], O_RDONLY, S_IREAD);
     148                    int sizein = (int)_filelength(fileIn);
     149
     150                    options.pszCustomExports = (PSZ)malloc(sizein+1);
     151                    memset(options.pszCustomExports, 0, sizein+1);
     152                    read(fileIn, options.pszCustomExports, sizein);
     153                    close(fileIn);
     154                    break;
     155                }
    127156
    128157                default:
Note: See TracChangeset for help on using the changeset viewer.