VirtualBox

Changeset 105786 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Aug 21, 2024 5:27:35 PM (5 months ago)
Author:
vboxsync
Message:

IPRT: Added RTSystemQueryNtFeatureEnabled() API to query Windows (NT) features + testcase. Also includes internal code for querying Windows registry values. bugref:10753

Location:
trunk/src/VBox/Runtime/r3/win
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/RTSystemFirmware-win.cpp

    r105766 r105786  
    5454
    5555#include "internal-r3-win.h"
     56#include "internal-r3-registry-win.h"
    5657
    5758
     
    124125
    125126    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             else
    162                 rc = VERR_WRONG_TYPE;
    163         }
    164         else
    165             rc = VERR_MISMATCH;
    166     }
    167     else
    168         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     }
    201127
    202128    return rc;
     
    310236        {
    311237            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);
    314240            if (RT_SUCCESS(rc))
    315241            {
  • trunk/src/VBox/Runtime/r3/win/system-get-nt-xxx-win.cpp

    r98103 r105786  
    4343
    4444#include "internal-r3-win.h"
     45#include "internal-r3-registry-win.h"
    4546#include <iprt/system.h>
    4647#include <iprt/assert.h>
     48#include <iprt/err.h>
    4749
    4850
     
    6769}
    6870
     71
     72RTDECL(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
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette