Changeset 75282 in vbox for trunk/src/VBox/HostDrivers/Support/win
- Timestamp:
- Nov 6, 2018 12:57:54 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp
r75049 r75282 2083 2083 } 2084 2084 2085 2085 2086 void VBOXCALL supdrvOSLdrNotifyUnloaded(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage) 2086 2087 { … … 2088 2089 } 2089 2090 2090 /* 2091 * Note! Similar code in rtR0DbgKrnlNtParseModule. 2092 */ 2093 int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, 2094 const uint8_t *pbImageBits, const char *pszSymbol) 2095 { 2096 #if 1 2097 RT_NOREF(pDevExt, pbImageBits); 2091 2092 /** 2093 * Common worker for supdrvOSLdrQuerySymbol and supdrvOSLdrValidatePointer. 2094 * 2095 * @note Similar code in rtR0DbgKrnlNtParseModule. 2096 */ 2097 static int supdrvOSLdrValidatePointerOrQuerySymbol(PSUPDRVLDRIMAGE pImage, void *pv, const char *pszSymbol, 2098 size_t cchSymbol, void **ppvSymbol) 2099 { 2098 2100 AssertReturn(pImage->pvNtSectionObj, VERR_INVALID_STATE); 2101 Assert(pszSymbol || !ppvSymbol); 2099 2102 2100 2103 /* … … 2104 2107 uint32_t const cbMapping = pImage->cbImageBits; 2105 2108 uint32_t const uRvaToValidate = (uint32_t)((uintptr_t)pv - (uintptr_t)pbMapping); 2106 AssertReturn(uRvaToValidate < cbMapping , VERR_INTERNAL_ERROR_3);2109 AssertReturn(uRvaToValidate < cbMapping || ppvSymbol, VERR_INTERNAL_ERROR_3); 2107 2110 2108 2111 uint32_t const offNtHdrs = *(uint16_t *)pbMapping == IMAGE_DOS_SIGNATURE … … 2128 2131 { 2129 2132 SUPR0Printf("SUPDrv: No exports in %s!\n", pImage->szName); 2130 return VERR_NOT_FOUND;2133 return ppvSymbol ? VERR_SYMBOL_NOT_FOUND : VERR_NOT_FOUND; 2131 2134 } 2132 2135 AssertReturn( ExpDir.Size >= sizeof(IMAGE_EXPORT_DIRECTORY) … … 2143 2146 { 2144 2147 SUPR0Printf("SUPDrv: No exports in %s!\n", pImage->szName); 2145 return VERR_NOT_FOUND;2148 return ppvSymbol ? VERR_SYMBOL_NOT_FOUND : VERR_NOT_FOUND; 2146 2149 } 2147 2150 … … 2170 2173 */ 2171 2174 uint32_t iExportOrdinal = UINT32_MAX; 2172 for (uint32_t i = 0; i < cExports; i++) 2173 if (paoffExports[i] == uRvaToValidate) 2174 { 2175 iExportOrdinal = i; 2176 break; 2177 } 2178 if (iExportOrdinal == UINT32_MAX) 2179 { 2180 SUPR0Printf("SUPDrv: No export with rva %#x (%s) in %s!\n", uRvaToValidate, pszSymbol, pImage->szName); 2181 return VERR_NOT_FOUND; 2182 } 2183 2184 /* 2185 * Can we validate the symbol name too? If so, just do a linear search. 2186 */ 2187 if (pszSymbol && RT_C_IS_UPPER(*pszSymbol)) 2188 { 2189 size_t const cchSymbol = strlen(pszSymbol); 2175 if (!ppvSymbol) 2176 { 2177 for (uint32_t i = 0; i < cExports; i++) 2178 if (paoffExports[i] == uRvaToValidate) 2179 { 2180 iExportOrdinal = i; 2181 break; 2182 } 2183 if (iExportOrdinal == UINT32_MAX) 2184 { 2185 SUPR0Printf("SUPDrv: No export with rva %#x (%s) in %s!\n", uRvaToValidate, pszSymbol, pImage->szName); 2186 return VERR_NOT_FOUND; 2187 } 2188 } 2189 2190 /* 2191 * Can we validate the symbol name too or should we find a name? 2192 * If so, just do a linear search. 2193 */ 2194 if (pszSymbol && (RT_C_IS_UPPER(*pszSymbol) || ppvSymbol)) 2195 { 2190 2196 for (uint32_t i = 0; i < cNamedExports; i++) 2191 2197 { … … 2193 2199 AssertReturn(offName < cbMapping, VERR_BAD_EXE_FORMAT); 2194 2200 uint32_t const cchMaxName = cbMapping - offName; 2195 const char * const pszName = (const char *)&pb ImageBits[offName];2201 const char * const pszName = (const char *)&pbMapping[offName]; 2196 2202 const char * const pszEnd = (const char *)memchr(pszName, '\0', cchMaxName); 2197 2203 AssertReturn(pszEnd, VERR_BAD_EXE_FORMAT); … … 2200 2206 && memcmp(pszName, pszSymbol, cchSymbol) == 0) 2201 2207 { 2202 if (pau16NameOrdinals[i] == iExportOrdinal) 2208 if (ppvSymbol) 2209 { 2210 iExportOrdinal = pau16NameOrdinals[i]; 2211 if ( iExportOrdinal < cExports 2212 && paoffExports[iExportOrdinal] < cbMapping) 2213 { 2214 *ppvSymbol = (void *)(paoffExports[iExportOrdinal] + pbMapping); 2215 return VINF_SUCCESS; 2216 } 2217 } 2218 else if (pau16NameOrdinals[i] == iExportOrdinal) 2203 2219 return VINF_SUCCESS; 2204 SUPR0Printf("SUPDrv: Different exports found for %s and rva %#x in %s: %#x vs %#x\n", 2205 pszSymbol, uRvaToValidate, pImage->szName, pau16NameOrdinals[i], iExportOrdinal); 2220 else 2221 SUPR0Printf("SUPDrv: Different exports found for %s and rva %#x in %s: %#x vs %#x\n", 2222 pszSymbol, uRvaToValidate, pImage->szName, pau16NameOrdinals[i], iExportOrdinal); 2206 2223 return VERR_LDR_BAD_FIXUP; 2207 2224 } 2208 2225 } 2209 SUPR0Printf("SUPDrv: No export named %s (%#x) in %s!\n", pszSymbol, uRvaToValidate, pImage->szName); 2226 if (!ppvSymbol) 2227 SUPR0Printf("SUPDrv: No export named %s (%#x) in %s!\n", pszSymbol, uRvaToValidate, pImage->szName); 2210 2228 return VERR_SYMBOL_NOT_FOUND; 2211 2229 } 2212 2230 return VINF_SUCCESS; 2213 2214 #else 2215 NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits); NOREF(pszSymbol); 2216 return VERR_NOT_SUPPORTED; 2217 #endif 2231 } 2232 2233 2234 int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, 2235 const uint8_t *pbImageBits, const char *pszSymbol) 2236 { 2237 RT_NOREF(pDevExt, pbImageBits); 2238 return supdrvOSLdrValidatePointerOrQuerySymbol(pImage, pv, pszSymbol, pszSymbol ? strlen(pszSymbol) : 0, NULL); 2239 } 2240 2241 2242 int VBOXCALL supdrvOSLdrQuerySymbol(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, 2243 const char *pszSymbol, size_t cchSymbol, void **ppvSymbol) 2244 { 2245 RT_NOREF(pDevExt); 2246 AssertReturn(ppvSymbol, VERR_INVALID_PARAMETER); 2247 AssertReturn(pszSymbol, VERR_INVALID_PARAMETER); 2248 return supdrvOSLdrValidatePointerOrQuerySymbol(pImage, NULL, pszSymbol, cchSymbol, ppvSymbol); 2218 2249 } 2219 2250
Note:
See TracChangeset
for help on using the changeset viewer.