Changeset 9957 for trunk/src/win32k/pe2lx/pe2lx.cpp
- Timestamp:
- Mar 31, 2003, 4:53:32 AM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/pe2lx/pe2lx.cpp
r7068 r9957 1 /* $Id: pe2lx.cpp,v 1.3 4 2001-10-15 20:46:20 sandervlExp $1 /* $Id: pe2lx.cpp,v 1.35 2003-03-31 02:52:49 bird Exp $ 2 2 * 3 3 * Pe2Lx class implementation. Ring 0 and Ring 3 … … 1905 1905 */ 1906 1906 rfree(pVars); 1907 NOREF(lLibPath); 1907 1908 return ERROR_FILE_NOT_FOUND;//ldrOpenPath(pachFilename, (USHORT)cchFilename, pLdrLv, pful, lLibPath); 1908 1909 … … 2567 2568 paObjTab[i].o32_base = ulImageBase + paObjects[i].ulRVA; 2568 2569 paObjTab[i].o32_flags = paObjects[i].flFlags; 2570 if (isAllRWObjectsEnabled()) 2571 paObjTab[i].o32_flags = OBJREAD | OBJWRITE | OBJBIGDEF; 2569 2572 paObjTab[i].o32_pagemap = ulPageMap; 2570 2573 paObjTab[i].o32_mapsize = ALIGN(paObjTab[i].o32_size, PAGESIZE) >> PAGESHIFT; … … 2789 2792 char szModuleName[128]; 2790 2793 #endif 2794 char * pszModuleName; /* Pointer to the current modulename or NULL. Only used with Custombuild. */ 2791 2795 ULONG ulRVAFirstThunk; /* Current first thunk array RVA. Points at current entry. */ 2792 2796 ULONG ulRVAOrgFirstThunk; /* Current original first thunk array RVA. Points at current entry. */ … … 2895 2899 } 2896 2900 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)); 2910 2911 2911 2912 /* initiate the import variables */ … … 2937 2938 if (rc == NO_ERROR) 2938 2939 { 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); 2941 2949 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'; 2952 2954 } 2953 else 2955 if (!hasCustomDll() || isCustomDllExcluded(pszModuleName)) 2956 { 2957 rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal)); 2958 szModuleName[0] = '\0'; 2959 pszModuleName = NULL; 2960 } 2954 2961 #endif 2955 rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));2956 2957 2962 free(psz); 2958 2963 } … … 2990 2995 && ((paObjects[iObj].Misc.offTIBFix + paObjects[iObj].ulRVA) & ~(PAGESIZE-1UL)) == ulRVAPage) 2991 2996 { 2997 PCSZ pszTmp = NULL; 2992 2998 #ifndef RING0 2993 if(hasCustomDll()) { 2999 if (hasCustomDll()) 3000 { 3001 pszTmp = "KERNEL32"; 2994 3002 rc = addModule(options.pszCustomDll, (PULONG)SSToDS(&ul)); 2995 ulCustomModOrdinal = ul;2996 3003 } 2997 3004 else … … 3004 3011 ul, 3005 3012 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); 3011 3014 } 3012 3015 if (rc != NO_ERROR) … … 3028 3031 if (Thunk.u1.Ordinal & (ULONG)IMAGE_ORDINAL_FLAG) 3029 3032 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); 3035 3034 else if (Thunk.u1.Ordinal > 0UL && Thunk.u1.Ordinal < pNtHdrs->OptionalHeader.SizeOfImage) 3036 3035 { … … 3040 3039 break; 3041 3040 rc = add32NameImportFixup((WORD)(ulRVAFirstThunk & (PAGESIZE-1)), 3042 ulModuleOrdinal, psz 3043 #ifndef RING0 3044 , szModuleName 3045 #endif 3046 ); 3041 ulModuleOrdinal, psz, pszModuleName); 3047 3042 free(psz); 3048 3043 } … … 3087 3082 if (rc == NO_ERROR) 3088 3083 { 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); 3091 3092 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'; 3101 3097 } 3102 else 3098 if (!hasCustomDll() || isCustomDllExcluded(pszModuleName)) 3099 { 3100 rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal)); 3101 szModuleName[0] = '\0'; 3102 pszModuleName = NULL; 3103 } 3103 3104 #endif 3104 rc = addModule(psz, (PULONG)SSToDS(&ulModuleOrdinal));3105 3105 free(psz); 3106 3106 } … … 3851 3851 * @param ulFunctionOrdinal Function ordinal. Number of the export which is to be imported from 3852 3852 * the module given by ulModuleOrdinal. 3853 * @param pszModuleName The name of the module or NULL. For custombuild only. 3853 3854 * @sketch IF not enough memory for the fixup THEN (try) allocate more memory 3854 3855 * Fill in fixup record. … … 3902 3903 * 3903 3904 */ 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 3905 ULONG Pe2Lx::add32OrdImportFixup(WORD offSource, ULONG ulModuleOrdinal, ULONG ulFunctionOrdinal, PCSZ pszModuleName) 3909 3906 { 3910 3907 struct r32_rlc *prlc; … … 3912 3909 3913 3910 #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); 3929 3927 return ERROR_MOD_NOT_FOUND; 3930 3928 } 3931 3929 } 3930 #else 3931 NOREF(pszModuleName); 3932 3932 #endif 3933 3933 … … 4000 4000 * @param ulModuleOrdinal Module ordinal in the import module name table (1 based!) 4001 4001 * @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. 4002 4003 * @sketch IF not enough memory for the fixup THEN (try) allocate more memory 4003 4004 * Add function name to the import procedure name table. … … 4052 4053 * 4053 4054 */ 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 4055 ULONG Pe2Lx::add32NameImportFixup(WORD offSource, ULONG ulModuleOrdinal, PCSZ pszFnName, PCSZ pszModuleName) 4059 4056 { 4060 4057 APIRET rc; … … 4064 4061 4065 4062 #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); 4083 4079 return ERROR_MOD_NOT_FOUND; 4084 4080 } 4085 4081 } 4082 #else 4083 NOREF(pszModuleName); 4086 4084 #endif 4087 4085 … … 5133 5131 PCSZ Pe2Lx::queryOdin32ModuleName(PCSZ pszWin32ModuleName) 5134 5132 { 5133 #ifndef RING0 5134 if (hasCustomDll() && !isCustomDllExcluded(pszWin32ModuleName)) 5135 return pszWin32ModuleName; 5136 #endif 5137 5135 5138 int i = 0; 5136 5137 #ifndef RING05138 if(hasCustomDll()) {5139 return pszWin32ModuleName;5140 }5141 #endif5142 5139 while (paLieList[i].pszWin32Name != NULL) 5143 5140 { … … 5149 5146 return pszWin32ModuleName; 5150 5147 } 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 */ 5157 BOOL 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 5151 5167 5152 5168
Note:
See TracChangeset
for help on using the changeset viewer.