Changeset 52176 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 24, 2014 6:48:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
r52173 r52176 1464 1464 1465 1465 1466 /** 1467 * Check if the zero terminated NT unicode string is the path to the given 1468 * system32 DLL. 1469 * 1470 * @returns true if it is, false if not. 1471 * @param pUniStr The zero terminated NT unicode string path. 1472 * @param pszName The name of the system32 DLL. 1473 */ 1474 static bool supR3HardNtIsNamedSystem32Dll(PUNICODE_STRING pUniStr, const char *pszName) 1475 { 1476 if (pUniStr->Length > g_System32NtPath.UniStr.Length) 1477 { 1478 if (memcmp(pUniStr->Buffer, g_System32NtPath.UniStr.Buffer, g_System32NtPath.UniStr.Length) == 0) 1479 { 1480 if (pUniStr->Buffer[g_System32NtPath.UniStr.Length / sizeof(WCHAR)] == '\\') 1481 { 1482 if (RTUtf16ICmpAscii(&pUniStr->Buffer[g_System32NtPath.UniStr.Length / sizeof(WCHAR) + 1], pszName) == 0) 1483 return true; 1484 } 1485 } 1486 } 1487 1488 return false; 1489 } 1490 1491 1466 1492 1467 1493 /* … … 1840 1866 if (NT_SUCCESS(rcNt)) 1841 1867 { 1842 PIMAGE_NT_HEADERS pNtProc = (PIMAGE_NT_HEADERS)&abProc[(uint8_t *)pNtFile - &abFile[0]]; 1843 pNtFile->OptionalHeader.ImageBase = pNtProc->OptionalHeader.ImageBase; 1844 1845 size_t cbCompare = RT_MIN(pNtFile->OptionalHeader.SizeOfHeaders, sizeof(abProc)); 1846 if (cbCompare < sizeof(abFile)) 1847 RT_BZERO(&abFile[cbCompare], sizeof(abFile) - cbCompare); 1848 if (!memcmp(abFile, abProc, cbCompare)) 1849 rc = VINF_SUCCESS; 1868 /* 1869 * Watch out for apisetschema.dll, it only has section #1 1870 * mapped into the process. 1871 */ 1872 if ( g_uNtVerCombined < SUP_NT_VER_W70 1873 || pThis->Peb.Diff3.W7.ApiSetMap != pMemInfo->BaseAddress 1874 || !supR3HardNtIsNamedSystem32Dll(&uBuf.UniStr, "apisetschema.dll")) 1875 { 1876 PIMAGE_NT_HEADERS pNtProc = supR3HardNtPuChFindNtHeaders(abProc, sizeof(abProc)); 1877 if ((uintptr_t)pNtProc - (uintptr_t)abProc == (uintptr_t)pNtFile - (uintptr_t)abFile) 1878 { 1879 pNtFile->OptionalHeader.ImageBase = pNtProc->OptionalHeader.ImageBase; 1880 1881 size_t cbCompare = RT_MIN(pNtFile->OptionalHeader.SizeOfHeaders, sizeof(abProc)); 1882 if (cbCompare < sizeof(abFile)) 1883 RT_BZERO(&abFile[cbCompare], sizeof(abFile) - cbCompare); 1884 if (!memcmp(abFile, abProc, cbCompare)) 1885 rc = VINF_SUCCESS; 1886 else 1887 { 1888 SUP_DPRINTF(("supR3HardNtPuChSanitizeImage: Header diff @%#x in ('%ls')\n", 1889 supR3HardNtPuChFindFirstDiff(abFile, abProc, sizeof(abProc)), uBuf.UniStr.Buffer)); 1890 rc = supR3HardNtPuChRestoreImageBits(pThis, pMemInfo->BaseAddress, abFile, cbCompare, PAGE_READONLY); 1891 } 1892 } 1893 else 1894 rc = RTErrInfoSetF(pThis->pErrInfo, VERR_GENERAL_FAILURE, 1895 "PE header offset differs between file and memory: offProc=%p offFile=%p '%ls'\n", 1896 (uintptr_t)pNtProc - (uintptr_t)abProc, (uintptr_t)pNtFile - (uintptr_t)abFile, 1897 uBuf.UniStr.Buffer); 1898 } 1850 1899 else 1851 1900 { 1852 SUP_DPRINTF(("supR3HardNtPuChSanitizeImage: Header diff @%#x in ('%ls')\n",1853 supR3HardNtPuChFindFirstDiff(abFile, abProc, sizeof(abProc)), uBuf.UniStr.Buffer));1854 rc = supR3HardNtPuChRestoreImageBits(pThis, pMemInfo->BaseAddress, abFile, cbCompare, PAGE_READONLY);1901 /* 1902 * Validate the API set map. 1903 */ 1855 1904 } 1856 1905 } … … 2036 2085 { 2037 2086 uBuf.UniStr.Buffer[uBuf.UniStr.Length / sizeof(WCHAR)] = '\0'; 2038 if ( uBuf.UniStr.Length > g_System32NtPath.UniStr.Length 2039 && memcmp(uBuf.UniStr.Buffer, g_System32NtPath.UniStr.Buffer, g_System32NtPath.UniStr.Length) == 0 2040 && uBuf.UniStr.Buffer[g_System32NtPath.UniStr.Length / sizeof(WCHAR)] == '\\') 2087 if (supR3HardNtIsNamedSystem32Dll(&uBuf.UniStr, "ntdll.dll")) 2041 2088 { 2042 if (RTUtf16ICmpAscii(&uBuf.UniStr.Buffer[g_System32NtPath.UniStr.Length / sizeof(WCHAR) + 1], 2043 "ntdll.dll") == 0) 2044 { 2045 pThis->uNtDllAddr = (uintptr_t)MemInfo.AllocationBase; 2046 SUP_DPRINTF(("supR3HardNtPuChFindNtdll: uNtDllParentAddr=%p uNtDllChildAddr=%p\n", 2047 pThis->uNtDllParentAddr, pThis->uNtDllAddr)); 2048 return; 2049 } 2089 pThis->uNtDllAddr = (uintptr_t)MemInfo.AllocationBase; 2090 SUP_DPRINTF(("supR3HardNtPuChFindNtdll: uNtDllParentAddr=%p uNtDllChildAddr=%p\n", 2091 pThis->uNtDllParentAddr, pThis->uNtDllAddr)); 2092 return; 2050 2093 } 2051 2094 } … … 2403 2446 2404 2447 NtClose(hProcWait); 2405 SUP_DPRINTF(("supR3HardenedWinDoReSpawn(%d): Quitting: ExitCode=%#x rcNt=%#x\n", BasicInfo.ExitStatus, rcNt));2448 SUP_DPRINTF(("supR3HardenedWinDoReSpawn(%d): Quitting: ExitCode=%#x rcNt=%#x\n", iWhich, BasicInfo.ExitStatus, rcNt)); 2406 2449 suplibHardenedExit((RTEXITCODE)BasicInfo.ExitStatus); 2407 2450 }
Note:
See TracChangeset
for help on using the changeset viewer.