Changeset 9957 for trunk/src


Ignore:
Timestamp:
Mar 31, 2003, 4:53:32 AM (22 years ago)
Author:
bird
Message:

Cleaned up Customb Dll handling, pluss exclude dll feature. Added support for all object RW.

Location:
trunk/src/win32k
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/win32k/include/options.h

    r9954 r9957  
    1 /* $Id: options.h,v 1.25 2003-03-31 01:22:45 bird Exp $
     1/* $Id: options.h,v 1.26 2003-03-31 02:53:31 bird Exp $
    22 *
    33 * Options.
     
    9292            FLAGS_PE_PE,            /* fPE           */     \
    9393            FLAGS_PEOO_FORCED,      /* fPEOneObject  */     \
     94            FALSE,                  /* fAllRWObjects */     \
     95            FALSE,                  /* fSkipFixups   */     \
    9496            INFOLEVEL_QUIET,        /* ulInfoLevel   */     \
    9597            FALSE,                  /* fElf          */     \
     
    98100            TRUE,                   /* fJava         */     \
    99101            FALSE,                  /* fNoLoader     */     \
    100             FALSE,                  /* fSkipFixups   */     \
    101102            NULL,                   /* pszCustomDll  */     \
    102103            NULL,                   /* pszCustomExports  */ \
     
    121122#define isPEOneObjectForced()       (options.fPEOneObject == FLAGS_PEOO_FORCED)
    122123
     124#define isAllRWObjectsEnabled()     (options.fAllRWObjects)
     125#define isAllRWObjectsDisabled()    (!options.fAllRWObjects)
     126
    123127#define isELFDisabled()             (!options.fElf)
    124128#define isELFEnabled()              (options.fElf)
     
    178182    ULONG       fPE;                    /* Flags set the type of conversion. */
    179183    ULONG       fPEOneObject;           /* All in one object. */
     184    ULONG       fAllRWObjects;          /* All objects are writable. */
     185    ULONG       fSkipFixups;            /* Base the image stripping of fixups. (Exe only please.) */
    180186    ULONG       ulInfoLevel;            /* Pe2Lx InfoLevel. */
    181187
     
    195201    ULONG       fNoLoader;              /* No loader stuff. !FIXME! We should import / functions even if this flag is set!!! */
    196202
    197     ULONG       fSkipFixups;
    198203    char *      pszCustomDll;           /* Pointer to custom odin dll name */
    199204    char *      pszCustomExports;       /* Pointer to custom export table */
  • trunk/src/win32k/include/pe2lx.h

    r9955 r9957  
    1 /* $Id: pe2lx.h,v 1.15 2003-03-31 01:23:14 bird Exp $
     1/* $Id: pe2lx.h,v 1.16 2003-03-31 02:53:32 bird Exp $
    22 *
    33 * Pe2Lx class declarations. Ring 0 and Ring 3
     
    110110    ULONG       addPageFixupEntry(BOOL fLast = FALSE);
    111111    ULONG       add32OffsetFixup(WORD offSource, ULONG ulTarget);
    112     #ifndef RING0
    113     ULONG       add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PSZ pszModuleName);
    114     ULONG       add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PSZ pszModuleName);
    115     #else
    116     ULONG       add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal);
    117     ULONG       add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName);
    118     #endif
     112    ULONG       add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PCSZ pszModuleName);
     113    ULONG       add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PCSZ pszModuleName);
    119114    ULONG       addModule(PCSZ pszModuleName, PULONG pulModuleOrdinal);
    120115    ULONG       addImportFunctionName(PCSZ pszFnName, PULONG poffFnName);
     
    140135    static BOOL setOdin32Path(const char *psz);
    141136    #ifndef RING0
    142     static BOOL isCustomDllExcluded(const char *pszModuleName);
     137    static BOOL isCustomDllExcluded(PCSZ pszModuleName);
    143138    #endif
    144139
  • trunk/src/win32k/pe2lx/pe2lx.cpp

    r7068 r9957  
    1 /* $Id: pe2lx.cpp,v 1.34 2001-10-15 20:46:20 sandervl Exp $
     1/* $Id: pe2lx.cpp,v 1.35 2003-03-31 02:52:49 bird Exp $
    22 *
    33 * Pe2Lx class implementation. Ring 0 and Ring 3
     
    19051905     */
    19061906    rfree(pVars);
     1907    NOREF(lLibPath);
    19071908    return ERROR_FILE_NOT_FOUND;//ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath);
    19081909
     
    25672568                paObjTab[i].o32_base     = ulImageBase + paObjects[i].ulRVA;
    25682569                paObjTab[i].o32_flags    = paObjects[i].flFlags;
     2570                if (isAllRWObjectsEnabled())
     2571                    paObjTab[i].o32_flags = OBJREAD | OBJWRITE | OBJBIGDEF;
    25692572                paObjTab[i].o32_pagemap  = ulPageMap;
    25702573                paObjTab[i].o32_mapsize  = ALIGN(paObjTab[i].o32_size, PAGESIZE) >> PAGESHIFT;
     
    27892792    char                        szModuleName[128];
    27902793    #endif
     2794    char *                      pszModuleName;      /* Pointer to the current modulename or NULL. Only used with Custombuild. */
    27912795    ULONG                       ulRVAFirstThunk;    /* Current first thunk array RVA. Points at current entry. */
    27922796    ULONG                       ulRVAOrgFirstThunk; /* Current original first thunk array RVA. Points at current entry. */
     
    28952899    }
    28962900
    2897     /* Make sure kernel32 is the first imported module */
    2898     if (rc == NO_ERROR)
    2899     {
    2900         #ifndef RING0
    2901         if(hasCustomDll()) {
    2902             rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul));
    2903             ulCustomModOrdinal = ul;
    2904             strcpy(szModuleName, "KERNEL32");
    2905         }
    2906         else
    2907         #endif
    2908             rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
    2909     }
     2901    /* Make sure kernel32/customdll is the first imported module */
     2902    #ifndef RING0
     2903    if (hasCustomDll())
     2904    {
     2905        rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul));
     2906        ulCustomModOrdinal = ul;
     2907    }
     2908    else
     2909    #endif
     2910        rc = addModule("KERNEL32.DLL", (PULONG)SSToDS(&ul));
    29102911
    29112912    /* initiate the import variables */
     
    29372938                if (rc == NO_ERROR)
    29382939                {
    2939                     #ifndef RING0
    2940                     if(hasCustomDll()) {
     2940                    pszModuleName = NULL;
     2941                    #ifdef RING0
     2942                    rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     2943
     2944                    #else
     2945                    /* Uppercase the module names, and skip the extension. */
     2946                    if (hasCustomDll())
     2947                    {
     2948                        strcpy((pszModuleName = (char*)SSToDS(szModuleName)), psz);
    29412949                        ulModuleOrdinal = ulCustomModOrdinal;
    2942                         strcpy(szModuleName, psz);
    2943                         char *tmp = szModuleName;
    2944                         while(*tmp != 0 && *tmp != '.')
    2945                         {
    2946                             if(*tmp >= 'a' && *tmp <= 'z') {
    2947                                 *tmp += ('A' - 'a');
    2948                             }
    2949                             tmp++;
    2950                         }
    2951                         *tmp = 0;
     2950                        for (char *pszTmp = pszModuleName; *pszTmp !='\0' && *pszTmp != '.'; pszTmp++)
     2951                            if (*pszTmp >= 'a' && *pszTmp <= 'z')
     2952                                *pszTmp += ('A' - 'a');
     2953                        *pszTmp = '\0';
    29522954                    }
    2953                     else
     2955                    if (!hasCustomDll() || isCustomDllExcluded(pszModuleName))
     2956                    {
     2957                        rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     2958                        szModuleName[0] = '\0';
     2959                        pszModuleName = NULL;
     2960                    }
    29542961                    #endif
    2955                         rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
    2956 
    29572962                    free(psz);
    29582963                }
     
    29902995            && ((paObjects[iObj].Misc.offTIBFix + paObjects[iObj].ulRVA) & ~(PAGESIZE-1UL)) == ulRVAPage)
    29912996        {
     2997            PCSZ pszTmp = NULL;
    29922998            #ifndef RING0
    2993             if(hasCustomDll()) {
     2999            if (hasCustomDll())
     3000            {
     3001                pszTmp = "KERNEL32";
    29943002                rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul));
    2995                 ulCustomModOrdinal = ul;
    29963003            }
    29973004            else
     
    30043011                                         ul,
    30053012                                         pNtHdrs->FileHeader.Characteristics & IMAGE_FILE_DLL ?
    3006                                             ORD_REGISTERPE2LXDLL : ORD_REGISTERPE2LXEXE
    3007                 #ifndef RING0
    3008                                          , "KERNEL32"
    3009                 #endif
    3010                                          );
     3013                                            ORD_REGISTERPE2LXDLL : ORD_REGISTERPE2LXEXE, pszTmp);
    30113014            }
    30123015            if (rc != NO_ERROR)
     
    30283031                    if (Thunk.u1.Ordinal & (ULONG)IMAGE_ORDINAL_FLAG)
    30293032                        rc = add32OrdImportFixup((WORD)(ulRVAFirstThunk & (PAGESIZE-1)),
    3030                                                  ulModuleOrdinal, Thunk.u1.Ordinal & 0xffff
    3031                         #ifndef RING0
    3032                                                  , szModuleName
    3033                         #endif
    3034                                                  );
     3033                                                 ulModuleOrdinal, Thunk.u1.Ordinal & 0xffff, pszModuleName);
    30353034                    else if (Thunk.u1.Ordinal > 0UL && Thunk.u1.Ordinal < pNtHdrs->OptionalHeader.SizeOfImage)
    30363035                    {
     
    30403039                            break;
    30413040                        rc = add32NameImportFixup((WORD)(ulRVAFirstThunk & (PAGESIZE-1)),
    3042                                                   ulModuleOrdinal, psz
    3043                         #ifndef RING0
    3044                                                   , szModuleName
    3045                         #endif
    3046                                                  );
     3041                                                  ulModuleOrdinal, psz, pszModuleName);
    30473042                        free(psz);
    30483043                    }
     
    30873082                            if (rc == NO_ERROR)
    30883083                            {
    3089                                 #ifndef RING0
    3090                                 if(hasCustomDll()) {
     3084                                pszModuleName = NULL;
     3085                                #ifdef RING0
     3086                                rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     3087
     3088                                #else
     3089                                if (hasCustomDll())
     3090                                {
     3091                                    strcpy((pszModuleName = (char*)SSToDS(szModuleName)), psz);
    30913092                                    ulModuleOrdinal = ulCustomModOrdinal;
    3092                                     strcpy(szModuleName, psz);
    3093                                     char *tmp = szModuleName;
    3094                                     while(*tmp != 0 && *tmp != '.') {
    3095                                         if(*tmp >= 'a' && *tmp <= 'z') {
    3096                                             *tmp += ('A' - 'a');
    3097                                         }
    3098                                         tmp++;
    3099                                     }
    3100                                     *tmp = 0;
     3093                                    for (char *pszTmp = pszModuleName; *pszTmp !='\0' && *pszTmp != '.'; pszTmp++)
     3094                                        if (*pszTmp >= 'a' && *pszTmp <= 'z')
     3095                                            *pszTmp += ('A' - 'a');
     3096                                    *pszTmp = '\0';
    31013097                                }
    3102                                 else
     3098                                if (!hasCustomDll() || isCustomDllExcluded(pszModuleName))
     3099                                {
     3100                                    rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
     3101                                    szModuleName[0] = '\0';
     3102                                    pszModuleName = NULL;
     3103                                }
    31033104                                #endif
    3104                                     rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));
    31053105                                free(psz);
    31063106                            }
     
    38513851 * @param     ulFunctionOrdinal  Function ordinal. Number of the export which is to be imported from
    38523852 *                               the module given by ulModuleOrdinal.
     3853 * @param     pszModuleName      The name of the module or NULL. For custombuild only.
    38533854 * @sketch    IF not enough memory for the fixup THEN (try) allocate more memory
    38543855 *            Fill in fixup record.
     
    39023903 *
    39033904 */
    3904 #ifndef RING0
    3905 ULONG  Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PSZ pszModuleName)
    3906 #else
    3907 ULONG  Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal)
    3908 #endif
     3905ULONG  Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PCSZ pszModuleName)
    39093906{
    39103907    struct r32_rlc *prlc;
     
    39123909
    39133910    #ifndef RING0
    3914     if(hasCustomDll() && pszModuleName)
    3915     {
    3916         char  searchstring[256];
    3917         char *found;
    3918 
    3919         sprintf(searchstring, "%s.%d ", pszModuleName, ulFunctionOrdinal);
    3920         found = strstr(options.pszCustomExports, searchstring);
    3921         if(found) {
    3922             while(*found != '@') {
    3923                 found++;
    3924             }
    3925             ulFunctionOrdinal = atoi(++found);
    3926         }
    3927         else {
    3928             printf("Error: Export %s not found in table.\n\n", searchstring);
     3911    if (pszModuleName != NULL && *pszModuleName && hasCustomDll() && !isCustomDllExcluded(pszModuleName))
     3912    {
     3913        /* Search for "DLL.EXPORT" in the translation file. */
     3914        char  szSearchString[256];
     3915        sprintf(szSearchString, "%s.%d ", pszModuleName, ulFunctionOrdinal);
     3916        const char * pszFound = strstr(options.pszCustomExports, szSearchString);
     3917        if (pszFound)
     3918        {
     3919            /* Following the DLL.EXPORT is a @ordinal. */
     3920            while (*pszFound != '@')
     3921                pszFound++;
     3922            return add32OrdImportFixup(offSource, ulModuleOrdinal, atoi(++pszFound), NULL);
     3923        }
     3924        else
     3925        {
     3926            printf("Error: Export %s not found in table.\n\n", szSearchString);
    39293927            return ERROR_MOD_NOT_FOUND;
    39303928        }
    39313929    }
     3930    #else
     3931    NOREF(pszModuleName);
    39323932    #endif
    39333933
     
    40004000 * @param     ulModuleOrdinal  Module ordinal in the import module name table (1 based!)
    40014001 * @param     pszFnName        Pointer to a readonly function name for the imported function.
     4002 * @param     pszModuleName    The name of the module or NULL. For custombuild only.
    40024003 * @sketch    IF not enough memory for the fixup THEN (try) allocate more memory
    40034004 *            Add function name to the import procedure name table.
     
    40524053 *
    40534054 */
    4054 #ifndef RING0
    4055 ULONG  Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PSZ pszModuleName)
    4056 #else
    4057 ULONG  Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName)
    4058 #endif
     4055ULONG  Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PCSZ pszModuleName)
    40594056{
    40604057    APIRET          rc;
     
    40644061
    40654062    #ifndef RING0
    4066     if(hasCustomDll())
    4067     {
    4068         char  searchstring[256];
    4069         char *found;
    4070         int   ordinal;
    4071 
    4072         sprintf(searchstring, "%s.%s ", pszModuleName, pszFnName);
    4073         found = strstr(options.pszCustomExports, searchstring);
    4074         if(found) {
    4075             while(*found != '@') {
    4076                 found++;
    4077             }
    4078             ordinal = atoi(++found);
    4079             return add32OrdImportFixup(offSource, ulModuleOrdinal, ordinal, NULL);
    4080         }
    4081         else {
    4082             printf("Error: Export %s not found in table.\n\n", searchstring);
     4063    if (pszModuleName != NULL && *pszModuleName && hasCustomDll() && !isCustomDllExcluded(pszModuleName))
     4064    {
     4065        /* Search for "DLL.EXPORT" in the translation file. */
     4066        char  szSearchString[256];
     4067        sprintf(szSearchString, "%s.%s ", pszModuleName, pszFnName);
     4068        const char * pszFound = strstr(options.pszCustomExports, szSearchString);
     4069        if (pszFound)
     4070        {
     4071            /* Following the DLL.EXPORT is a @ordinal. */
     4072            while (*pszFound != '@')
     4073                pszFound++;
     4074            return add32OrdImportFixup(offSource, ulModuleOrdinal, atoi(++pszFound), NULL);
     4075        }
     4076        else
     4077        {
     4078            printf("Error: Export %s not found in table.\n\n", szSearchString);
    40834079            return ERROR_MOD_NOT_FOUND;
    40844080        }
    40854081    }
     4082    #else
     4083    NOREF(pszModuleName);
    40864084    #endif
    40874085
     
    51335131PCSZ Pe2Lx::queryOdin32ModuleName(PCSZ pszWin32ModuleName)
    51345132{
     5133    #ifndef RING0
     5134    if (hasCustomDll() && !isCustomDllExcluded(pszWin32ModuleName))
     5135        return pszWin32ModuleName;
     5136    #endif
     5137
    51355138    int i = 0;
    5136 
    5137     #ifndef RING0
    5138     if(hasCustomDll()) {
    5139         return pszWin32ModuleName;
    5140     }
    5141     #endif
    51425139    while (paLieList[i].pszWin32Name != NULL)
    51435140    {
     
    51495146    return pszWin32ModuleName;
    51505147}
     5148
     5149
     5150#ifndef RING0
     5151/**
     5152 * Checks if this DLL is excluded from the custombuild dll or not.
     5153 * @returns TRUE if excluded.
     5154 * @returns FALSE not excluded.
     5155 * @param   pszModuleName   DLL in question.
     5156 */
     5157BOOL Pe2Lx::isCustomDllExcluded(PCSZ pszModuleName)
     5158{
     5159    if (options.pszCustomDllExclude == NULL)
     5160        return FALSE;
     5161    if (!pszModuleName)
     5162        return TRUE;
     5163    const char *psz = strstr(options.pszCustomDllExclude, pszModuleName);
     5164    return (psz && psz[-1] == ';' && psz[strlen(pszModuleName)] == ';');
     5165}
     5166#endif
    51515167
    51525168
  • trunk/src/win32k/pe2lx/pe2lxmain.cpp

    r6852 r9957  
    1 /* $Id: pe2lxmain.cpp,v 1.8 2001-09-28 07:43:03 sandervl Exp $
     1/* $Id: pe2lxmain.cpp,v 1.9 2003-03-31 02:52:50 bird Exp $
    22 *
    33 * Pe2Lx main program. (Ring 3 only!)
     
    129129                    break;
    130130
    131                 case 'f': //ignore internal fixups
     131                case 'f': /* ignore internal fixups */
    132132                case 'F':
    133133                    options.fSkipFixups = TRUE;
    134134                    break;
    135135
    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");
     136                case 'r': /* all read-write objects */
     137                case 'R':
     138                    if (argv[argi][2] != 'w' && argv[argi][2] != 'W')
     139                    {
     140                        printf("Syntax error: Invalid argument, '%s'\n", argv[argi]);
    140141                        return 5;
    141142                    }
     143                    options.fAllRWObjects = TRUE;
     144                    break;
     145
     146                case 'c': /* custom odin dll name */
     147                case 'C':
     148                    if (!hasCustomExports())
     149                    {
     150                        printf("Syntax error: export table file not specified (-o:).\n\n");
     151                        return 5;
     152                    }
    142153                    options.pszCustomDll = &argv[argi][3];
    143154                    break;
    144                 case 'o':
     155
     156                case 'o': /* custom odin dll ordinal mapping */
    145157                case 'O':
    146158                {
     
    152164                    read(fileIn, options.pszCustomExports, sizein);
    153165                    close(fileIn);
     166                    break;
     167                }
     168
     169                case 'x': /* custombuild exclude dll */
     170                case 'X':
     171                {
     172                    int cch = strlen(&argv[argi][3]);
     173                    if (!cch)
     174                    {
     175                        printf("Syntax error: optino -x: requires a dll name!");
     176                        return 5;
     177                    }
     178                    int cchNew = cch + 4;
     179                    if (options.pszCustomDllExclude)
     180                        cchNew += strlen(options.pszCustomDllExclude);
     181                    options.pszCustomDllExclude = (char*)realloc(options.pszCustomDllExclude, cchNew);
     182
     183                    char *psz = options.pszCustomDllExclude;
     184                    if (cchNew != cch + 4)
     185                        psz = psz + strlen(psz);
     186
     187                    /* copy the name in uppercase with ';' at both ends. */
     188                    *psz++ = ';';
     189                    for (strcpy(psz, &argv[argi][3]); *psz; psz++)
     190                        if (*psz >= 'a' && *psz <= 'z')
     191                            *psz += ('A' - 'a');
     192                    *psz++ =';';
     193                    *psz = '\0';
    154194                    break;
    155195                }
     
    293333           "                     *: Forced. Applied every time.\n"
    294334           "                Default: -1*\n"
     335           "  -rw           Make all segments writable. For use with -1+. A trick to make\n"
     336           "                it possible for OS/2 to load the objects following on another.\n"
     337           "                This of course doesn't solve the alignment difference. So if\n"
     338           "                you build the program pass /ALIGN:0x10000 to the linker.\n"
     339           "  -f            Strip fixups forcing. Don't use with DLLs, may cause traps.\n"
     340           "\n"
     341           " Custombuild options:\n"
     342           "  -o:<ordfile>  Ordinal file. form: <W32DLL>.<name/ord> @<CustDLLOrd>\n"
     343           "  -c:<custdll>  Custombuild dll. After -o:!\n"
     344           "  -x:<dll>      Exclude from custombuild. -x:MSVCRT for example.\n"
     345           "\n"
    295346           "  Win32File     Input Win32 Exe, Dll or other Win32 PE file.\n"
    296347           "  Odin32File    Output Odin32-file. If not specified the Win32-file is\n"
Note: See TracChangeset for help on using the changeset viewer.