Changeset 105786 in vbox
- Timestamp:
- Aug 21, 2024 5:27:35 PM (5 weeks ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
-
include/iprt/system.h (modified) (1 diff)
-
src/VBox/Runtime/Makefile.kmk (modified) (1 diff)
-
src/VBox/Runtime/r3/win/RTSystemFirmware-win.cpp (modified) (3 diffs)
-
src/VBox/Runtime/r3/win/RTSystemRegistry-win.cpp (added)
-
src/VBox/Runtime/r3/win/system-get-nt-xxx-win.cpp (modified) (2 diffs)
-
src/VBox/Runtime/testcase/tstRTSystemQueryOsInfo.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/system.h
r100307 r105786 399 399 RTDECL(uint8_t) RTSystemGetNtProductType(void); 400 400 401 /** 402 * Windows NT feature types. 403 */ 404 typedef enum RTSYSNTFEATURE 405 { 406 /** Invalid feature. */ 407 RTSYSNTFEATURE_INVALID = 0, 408 /** Memory integrity is a feature of the Core Isolation facility. 409 * Introduced in Windows 10. */ 410 RTSYSNTFEATURE_CORE_ISOLATION_MEMORY_INTEGRITY, 411 /** The usual 32-bit hack. */ 412 RTSYSNTFEATURE_32_BIT_HACK = 0x7fffffff 413 } RTSYSNTFEATURE; 414 /** Pointer to a Windows NT feature type. */ 415 typedef RTSYSNTFEATURE *PRTSYSNTFEATURE; 416 417 /** 418 * Queries whether an NT feature is enabled or not. 419 * 420 * @returns IPRT status code. 421 * @retval VERR_NOT_SUPPORTED if the feature is not supported on this platform. 422 * @param enmFeature Feature to query enabled status for. 423 * @param pfEnabled Where to return the enabled status on success. 424 */ 425 RTDECL(int) RTSystemQueryNtFeatureEnabled(RTSYSNTFEATURE enmFeature, bool *pfEnabled); 426 401 427 #endif /* RT_OS_WINDOWS */ 402 428 -
trunk/src/VBox/Runtime/Makefile.kmk
r105746 r105786 1071 1071 r3/win/RTSystemFirmware-win.cpp \ 1072 1072 r3/win/RTSystemQueryTotalRam-win.cpp \ 1073 r3/win/RTSystemRegistry-win.cpp \ 1073 1074 r3/win/RTTimeZoneGetCurrent-win.cpp \ 1074 1075 r3/win/RTMemProtect-win.cpp \ -
trunk/src/VBox/Runtime/r3/win/RTSystemFirmware-win.cpp
r105766 r105786 54 54 55 55 #include "internal-r3-win.h" 56 #include "internal-r3-registry-win.h" 56 57 57 58 … … 124 125 125 126 CloseHandle(hToken); 126 127 return rc;128 }129 130 131 /**132 * Queries a DWORD value from a Windows registry key, Unicode (wide char) version.133 *134 * @returns IPRT status code.135 * @retval VERR_FILE_NOT_FOUND if the value has not been found.136 * @param hKey Registry handle to use.137 * @param pwszKey Registry key to query \a pwszName in.138 * @param pwszName Name of the value to query.139 * @param pdwValue Where to return the actual value on success.140 */141 static int rtSystemWinRegistryGetDWORDW(HKEY hKey, LPCWSTR pwszKey, LPCWSTR pwszName, DWORD *pdwValue)142 {143 LONG lErr = RegOpenKeyExW(hKey, pwszKey, 0, KEY_QUERY_VALUE, &hKey);144 if (lErr != ERROR_SUCCESS)145 return RTErrConvertFromWin32(lErr);146 147 int rc = VINF_SUCCESS;148 149 DWORD cbType = sizeof(DWORD);150 DWORD dwType = 0;151 DWORD dwValue;152 lErr = RegQueryValueExW(hKey, pwszName, NULL, &dwType, (BYTE *)&dwValue, &cbType);153 if (lErr == ERROR_SUCCESS)154 {155 if (cbType == sizeof(DWORD))156 {157 if (dwType == REG_DWORD)158 {159 *pdwValue = dwValue;160 }161 else162 rc = VERR_WRONG_TYPE;163 }164 else165 rc = VERR_MISMATCH;166 }167 else168 rc = RTErrConvertFromWin32(lErr);169 170 RegCloseKey(hKey);171 172 return rc;173 }174 175 176 /**177 * Queries a DWORD value from a Windows registry key.178 *179 * @returns IPRT status code.180 * @retval VERR_FILE_NOT_FOUND if the value has not been found.181 * @param hKey Registry handle to use.182 * @param pszKey Registry key to query \a pszName in.183 * @param pszName Name of the value to query.184 * @param pdwValue Where to return the actual value on success.185 */186 static int rtSystemRegistryGetDWORDA(HKEY hKey, const char *pszKey, const char *pszName, DWORD *pdwValue)187 {188 PRTUTF16 pwszKey;189 int rc = RTStrToUtf16Ex(pszKey, RTSTR_MAX, &pwszKey, 0, NULL);190 if (RT_SUCCESS(rc))191 {192 PRTUTF16 pwszName;193 rc = RTStrToUtf16Ex(pszName, RTSTR_MAX, &pwszName, 0, NULL);194 if (RT_SUCCESS(rc))195 {196 rc = rtSystemWinRegistryGetDWORDW(hKey, pwszKey, pwszName, pdwValue);197 RTUtf16Free(pwszName);198 }199 RTUtf16Free(pwszKey);200 }201 127 202 128 return rc; … … 310 236 { 311 237 DWORD dwEnabled; 312 rc = rtSystemRegistryGetDWORDA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State",313 "UEFISecureBootEnabled", &dwEnabled);238 rc = RTSystemWinRegistryQueryDWORD(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SecureBoot\\State", 239 "UEFISecureBootEnabled", &dwEnabled); 314 240 if (RT_SUCCESS(rc)) 315 241 { -
trunk/src/VBox/Runtime/r3/win/system-get-nt-xxx-win.cpp
r98103 r105786 43 43 44 44 #include "internal-r3-win.h" 45 #include "internal-r3-registry-win.h" 45 46 #include <iprt/system.h> 46 47 #include <iprt/assert.h> 48 #include <iprt/err.h> 47 49 48 50 … … 67 69 } 68 70 71 72 RTDECL(int) RTSystemQueryNtFeatureEnabled(RTSYSNTFEATURE enmFeature, bool *pfEnabled) 73 { 74 AssertPtrReturn(pfEnabled, VERR_INVALID_POINTER); 75 76 int rc; 77 78 switch (enmFeature) 79 { 80 case RTSYSNTFEATURE_CORE_ISOLATION_MEMORY_INTEGRITY: /* aka Code Integrity */ 81 { 82 DWORD dwEnabled; 83 rc = RTSystemWinRegistryQueryDWORD(HKEY_LOCAL_MACHINE, 84 "SYSTEM\\CurrentControlSet\\Control\\DeviceGuard\\Scenarios\\HypervisorEnforcedCodeIntegrity", 85 "Enabled", &dwEnabled); 86 if (RT_SUCCESS(rc)) 87 *pfEnabled = RT_BOOL(dwEnabled); 88 else if (rc == VERR_FILE_NOT_FOUND) 89 rc = VERR_NOT_SUPPORTED; 90 break; 91 } 92 93 default: 94 rc = VERR_NOT_IMPLEMENTED; 95 break; 96 } 97 98 return rc; 99 } 100 -
trunk/src/VBox/Runtime/testcase/tstRTSystemQueryOsInfo.cpp
r98103 r105786 138 138 } 139 139 140 #if defined RT_OS_WINDOWS 141 RTTestISub("Windows Features"); 142 struct 143 { 144 const char *pszDesc; 145 RTSYSNTFEATURE enmFeature; 146 int rc; 147 } s_aNtFeatures[] = 148 { 149 { "Core Isolation (Memory Integrity)", RTSYSNTFEATURE_CORE_ISOLATION_MEMORY_INTEGRITY, VINF_SUCCESS } 150 }; 151 152 for (size_t i = 0; i < RT_ELEMENTS(s_aNtFeatures); i++) 153 { 154 RTTestIPrintf(RTTESTLVL_ALWAYS, "Testing '%s': ", s_aNtFeatures[i].pszDesc); 155 bool fEnabled = false; 156 int rcTst = RTSystemQueryNtFeatureEnabled(s_aNtFeatures[i].enmFeature, &fEnabled); 157 if (RT_SUCCESS(rcTst)) 158 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", fEnabled ? "ENABLED\n" : "DISABLED\n"); 159 else if (rc == VERR_NOT_SUPPORTED) /* Don't freak out on older (host) OSes which don't have this feature. */ 160 RTTestIPrintf(RTTESTLVL_ALWAYS, "SKIPPED (not supported)\n"); 161 else 162 RTTestIPrintf(RTTESTLVL_ALWAYS, "ERROR (%Rrc)\n", rcTst); 163 RTTESTI_CHECK_RC(rcTst, s_aNtFeatures[i].rc); 164 } 165 #endif 166 140 167 return RTTestSummaryAndDestroy(hTest); 141 168 }
Note:
See TracChangeset
for help on using the changeset viewer.

