ntdll: - `NtQuerySystemInformation` `SystemBootEnvironmentInformation` - `NtQuerySystemEnvironmentValueEx`
kernel32: - `GetFirmwareType` - `GetFirmwareEnvironmentVariableExA` - `GetFirmwareEnvironmentVariableExW` - `GetFirmwareEnvironmentVariableA` - `GetFirmwareEnvironmentVariableW`.
The code is needed to check SecureBoot status, security systems and for example to check the licenses of software that can use efi variables. The behavior matches the behavior of Windows 11. And the output is no different on wine and Windows 11.
Example:
```C #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #include <winnt.h> #include <winternl.h> #include <winbase.h> #include <shlwapi.h> #include <securitybaseapi.h>
/* x86_64-w64-mingw32-gcc -O2 firmware.c -o firmware.exe -Wl,--subsystem,console -lole32 */ #define SystemBootEnvironmentInformation 90
#define GUID_FORMAT "%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX" #define GUID_ARG(guid) \ (guid).Data1, (guid).Data2, (guid).Data3, (guid).Data4[0], (guid).Data4[1], (guid).Data4[2], (guid).Data4[3], \ (guid).Data4[4], (guid).Data4[5], (guid).Data4[6], (guid).Data4[7]
typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION { GUID BootIdentifier; FIRMWARE_TYPE FirmwareType; union { ULONGLONG BootFlags; struct { ULONGLONG DbgMenuOsSelection : 1; ULONGLONG DbgHiberBoot : 1; ULONGLONG DbgSoftBoot : 1; ULONGLONG DbgMeasuredLaunch : 1; ULONGLONG DbgMeasuredLaunchCapable : 1; ULONGLONG DbgSystemHiveReplace : 1; ULONGLONG DbgMeasuredLaunchSmmProtections : 1; ULONGLONG DbgMeasuredLaunchSmmLevel : 7; }; }; } SYSTEM_BOOT_ENVIRONMENT_INFORMATION, *PSYSTEM_BOOT_ENVIRONMENT_INFORMATION;
typedef NTSTATUS(NTAPI *LPFNZwInitUnicodeString)(IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString);
typedef NTSTATUS(NTAPI *LPFNZwQuerySystemInformation)( IN SYSTEM_INFORMATION_CLASS SystemInformationClass, IN OUT PVOID SystemInformation, IN ULONG SystemInformationLength, OUT PULONG ReturnLength );
typedef NTSTATUS(NTAPI *LPFNZwQuerySystemEnvironmentValueEx)( IN PUNICODE_STRING VariableName, IN LPGUID VendorGuid, IN PVOID Value, IN OUT PULONG ReturnLength, OUT PULONG Attributes );
BOOL EnableTokenPrivilege(HANDLE hToken, LPCTSTR pszPrivilegesName, BOOL bEnabled) { LUID luid; TOKEN_PRIVILEGES tp;
if (!LookupPrivilegeValue(NULL, pszPrivilegesName, &luid)) { return FALSE; }
tp.PrivilegeCount = 1; tp.Privileges[0].Luid = luid; tp.Privileges[0].Attributes = bEnabled ? SE_PRIVILEGE_ENABLED : 0;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) { return FALSE; }
return TRUE; }
int main(int argc, char **argv) { DWORD ret; ULONG ret_size; HANDLE hToken; HANDLE hProcess; HINSTANCE hNTdll; DWORD attributes; BOOLEAN secureboot = 0; FIRMWARE_TYPE type = FirmwareTypeUnknown;
UNICODE_STRING asus_name; char asus_license[2048] = {0};
UNICODE_STRING secureboot_name;
GUID asus_guid; GUID secureboot_guid;
SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0};
LPFNZwInitUnicodeString ZwInitUnicodeString; LPFNZwQuerySystemInformation ZwQuerySystemInformation; LPFNZwQuerySystemEnvironmentValueEx ZwQuerySystemEnvironmentValueEx;
if (CLSIDFromString(L"{02076249-a52b-420e-bd53-aed044349379}", &asus_guid) != NOERROR) { printf("CLSIDFromString error: %d!\n", GetLastError()); return -1; }
if (CLSIDFromString(L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot_guid) != NOERROR) { printf("CLSIDFromString error: %d!\n", GetLastError()); return -1; }
hNTdll = LoadLibraryW(L"Ntdll.dll");
if (!hNTdll) { printf("Can't load ntdll liabrary!\n"); return -1; }
ZwInitUnicodeString = (LPFNZwInitUnicodeString) GetProcAddress(hNTdll, "RtlInitUnicodeString"); if (!ZwInitUnicodeString) { printf("Can't get GetProcAddress RtlInitUnicodeString error: %d!\n", GetLastError()); return -1; }
ZwInitUnicodeString(&secureboot_name, L"SecureBoot"); ZwInitUnicodeString(&asus_name, L"AsusOnboardToolLicense");
ZwQuerySystemInformation = (LPFNZwQuerySystemInformation) GetProcAddress(hNTdll, "ZwQuerySystemInformation"); if (!ZwQuerySystemInformation) { printf("Can't get GetProcAddress ZwQuerySystemInformation error: %d!\n", GetLastError()); return -1; }
ZwQuerySystemEnvironmentValueEx = (LPFNZwQuerySystemEnvironmentValueEx) GetProcAddress(hNTdll, "ZwQuerySystemEnvironmentValueEx"); if (!ZwQuerySystemEnvironmentValueEx) { printf("Can't get GetProcAddress ZwQuerySystemEnvironmentValueEx error: %d!\n", GetLastError()); return -1; }
hProcess = GetCurrentProcess(); if (!hProcess) { printf("GetCurrentProcessToken error: %d!\n", GetLastError()); return -1; }
if (!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { printf("OpenProcessToken error: %d!\n", GetLastError()); return -1; }
if (!EnableTokenPrivilege(hToken, SE_SYSTEM_ENVIRONMENT_NAME, TRUE)) { printf("EnableTokenPrivilege error: %d!\n", GetLastError()); return -1; }
if (GetFirmwareType(&type)) printf("GetFirmwareType: %s\n\n", type == FirmwareTypeUefi ? "UEFI" : "BIOS");
ret = GetFirmwareEnvironmentVariableA( "SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN) ); if (!ret) { printf("GetFirmwareEnvironmentVariableA error: % d!\n\n", GetLastError()); return -1; } printf("GetFirmwareEnvironmentVariableA\nBytes: %d\nSecureBoot: %s\n\n", ret, secureboot ? "enabled" : "disabled");
secureboot = 0; ret = GetFirmwareEnvironmentVariableW( L"SecureBoot", L"{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN) ); if (!ret) { printf("GetFirmwareEnvironmentVariableW error: % d!\n\n", GetLastError()); return -1; } printf("GetFirmwareEnvironmentVariableW\nBytes: %d\nSecureBoot: %s\n\n", ret, secureboot ? "enabled" : "disabled");
attributes = 0; secureboot = 0; ret = GetFirmwareEnvironmentVariableExA( "SecureBoot", "{8be4df61-93ca-11d2-aa0d-00e098032b8c}", &secureboot, sizeof(BOOLEAN), &attributes ); if (!ret) { printf("GetFirmwareEnvironmentVariableExA error: % d!\n\n", GetLastError()); return -1; } printf( "GetFirmwareEnvironmentVariableExA\nBytes: %d\nAttributes: 0x%08x\nSecureBoot: %s\n\n", ret, attributes, secureboot ? "enabled" : "disabled" );
attributes = 0; ret = GetFirmwareEnvironmentVariableExW( L"AsusOnboardToolLicense", L"{02076249-a52b-420e-bd53-aed044349379}", asus_license, sizeof(asus_license), &attributes ); if (!ret) { printf("GetFirmwareEnvironmentVariableExW error: % d!\n\n", GetLastError()); return -1; } printf( "GetFirmwareEnvironmentVariableExW\nBytes: %d\nAttributes: 0x%08x\nAsus License: \n%s\n\n", ret, attributes, asus_license );
ret_size = sizeof(secureboot); attributes = 0; secureboot = 0; if (ZwQuerySystemEnvironmentValueEx(&secureboot_name, &secureboot_guid, &secureboot, &ret_size, &attributes) != NOERROR) { printf("ZwQuerySystemEnvironmentValueEx error: % d!\n\n", GetLastError()); FreeLibrary(hNTdll); return -1; } printf( "NtQuerySystemEnvironmentValueEx\nBytes: %d\nAttributes: 0x%08x\nSecureBoot: %s\n\n", ret_size, attributes, secureboot ? "enabled" : "disabled" );
ret_size = sizeof(asus_license); attributes = 0; for (size_t i = 0; i < ret_size; i++) { asus_license[i] = '\0'; } if (ZwQuerySystemEnvironmentValueEx(&asus_name, &asus_guid, asus_license, &ret_size, &attributes) != NOERROR) { printf("ZwQuerySystemEnvironmentValueEx error: % d!\n\n", GetLastError()); FreeLibrary(hNTdll); return -1; } printf( "NtQuerySystemEnvironmentValueEx\nBytes: %d\nAttributes: 0x%08x\nAsus License: \n%s\n\n", ret_size, attributes, asus_license );
if (ZwQuerySystemInformation( (SYSTEM_INFORMATION_CLASS) SystemBootEnvironmentInformation, &boot_info, sizeof(boot_info), &ret_size ) != NOERROR) { printf("ZwQuerySystemInformation error: % d!\n\n", GetLastError()); FreeLibrary(hNTdll); return -1; }
printf("SystemBootEnvironmentInformation:\nBootIdentifier: {" GUID_FORMAT "}", GUID_ARG(boot_info.BootIdentifier)); printf( "\nFirmwareType: %s\nBootFlags: 0x%llX\n\n", (boot_info.FirmwareType == FirmwareTypeUefi ? "UEFI" : "BIOS"), boot_info.BootFlags );
FreeLibrary(hNTdll);
return 0; } ```
Output: ``` GetFirmwareType: UEFI
GetFirmwareEnvironmentVariableA Bytes: 1 SecureBoot: enabled
GetFirmwareEnvironmentVariableW Bytes: 1 SecureBoot: enabled
GetFirmwareEnvironmentVariableExA Bytes: 1 Attributes: 0x00000006 SecureBoot: enabled
GetFirmwareEnvironmentVariableExW Bytes: 1570 Attributes: 0x00000006 Asus License: BASE64_BIG_LICENSE_TEXT== [LicenseID]:FED7A1 [Model]:Dummy-BaseBoard-Id [Tools]:WAsusDmiS,LogoFlashS,ASUSFwConfigS,AsusEventLogS,AsusNvLockS [Customer]:DummyLic [Expire]:2022-11-24
NtQuerySystemEnvironmentValueEx Bytes: 1 Attributes: 0x00000006 SecureBoot: enabled
NtQuerySystemEnvironmentValueEx Bytes: 1570 Attributes: 0x00000006 Asus License: BASE64_BIG_LICENSE_TEXT== [LicenseID]:FED7A1 [Model]:Dummy-BaseBoard-Id [Tools]:WAsusDmiS,LogoFlashS,ASUSFwConfigS,AsusEventLogS,AsusNvLockS [Customer]:DummyLic [Expire]:2022-11-24
SystemBootEnvironmentInformation: BootIdentifier: {8522FFCA-6A31-11EF-952A-966164983DCB} FirmwareType: UEFI BootFlags: 0x0 ```
-- v17: kernel32: Implement GetFirmwareEnvironmentVariableExA, GetFirmwareEnvironmentVariableExW, GetFirmwareEnvironmentVariableA, GetFirmwareEnvironmentVariableW. kernel32: Implement GetFirmwareType. ntdll: Implement NtQuerySystemInformation SystemBootEnvironmentInformation. ntdll: Implement NtQuerySystemEnvironmentValueEx.
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/ntdll/unix/system.c | 71 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index f47925018b8..5e5c76229eb 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> @@ -3682,9 +3683,75 @@ NTSTATUS WINAPI NtQuerySystemEnvironmentValue( UNICODE_STRING *name, WCHAR *buff NTSTATUS WINAPI NtQuerySystemEnvironmentValueEx( UNICODE_STRING *name, GUID *vendor, void *buffer, ULONG *retlen, ULONG *attrib ) { - FIXME( "(%s, %s, %p, %p, %p), stub\n", debugstr_us(name), - debugstr_guid(vendor), buffer, retlen, attrib ); +#if defined(__linux__) || defined(__gnu_linux__) + int fd, rc; + size_t bytes, pos = 0; + ssize_t ssz; + char filename[PATH_MAX + 1]; + char *cname; + struct stat stat_info = {0}; + + if(!name || !vendor || !attrib) + { + return ERROR_INVALID_PARAMETER; + } + + cname = (char *) malloc(wcslen(name->Buffer) * 3 + 1); + if(!cname) + return ERROR_NOT_ENOUGH_MEMORY; + + rc = ntdll_wcstoumbs(name->Buffer, wcslen(name->Buffer) + 1, cname, wcslen(name->Buffer) * 3 + 1, TRUE); + if(rc <= 0) { + free(cname); + return STATUS_SOME_NOT_MAPPED; + } + + snprintf(filename, sizeof(filename), + "/sys/firmware/efi/efivars/%s-%08lx-%04hx-%04hx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", + cname, (unsigned long)vendor->Data1, vendor->Data2, vendor->Data3, + vendor->Data4[0], vendor->Data4[1], vendor->Data4[2], vendor->Data4[3], + vendor->Data4[4], vendor->Data4[5], vendor->Data4[6], vendor->Data4[7]); + + fd = open(filename, O_RDONLY); + if (fd == -1) + goto done; + + rc = fstat(fd, &stat_info); + if (rc < 0 || stat_info.st_size == 0) + goto done; + +try_read_attributes: + ssz = read(fd, attrib, 4); + if (ssz < 0) goto done; + + if(buffer && retlen) + { + if (stat_info.st_size - 4 < *retlen) + bytes = stat_info.st_size - 4; + else + bytes = *retlen; + while (pos < bytes) + { + ssz = read(fd, (char *) buffer + pos, bytes - pos); + if (ssz < 0) goto done; + pos += ssz; + } + *retlen = ssz & 0xFFFFFFFF; + } + + close(fd); + return STATUS_SUCCESS; + +done: + free(cname); + if (fd >= 0) + close(fd); + return STATUS_UNSUCCESSFUL; +#else + FIXME("(%s, %s, %p, %p, %p), stub\n", debugstr_us(name), debugstr_guid(vendor), buffer, retlen, + attrib); return STATUS_NOT_IMPLEMENTED; +#endif }
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/ntdll/unix/system.c | 136 +++++++++++++++++++++++++++++++++++++++ dlls/wow64/system.c | 3 + include/winternl.h | 22 +++++++ 3 files changed, 161 insertions(+)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 5e5c76229eb..61b395a7c60 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -2763,6 +2763,65 @@ C_ASSERT( sizeof(struct process_info) <= sizeof(SYSTEM_PROCESS_INFORMATION) ); return ret; }
+/****************************************************************************** + * __wine_hexstr32_to_guid (NTDLL.@) + */ +static inline BOOL __wine_hexstr32_to_guid(const char *s, GUID *id) +{ + int i; + if (!s) { + memset(id, 0, sizeof(*id)); + return FALSE; + } + + id->Data1 = 0; + for (i = 0; i < 8; ++i) { + if (!(((s[i] >= '0') && (s[i] <= '9')) + || ((s[i] >= 'a') && (s[i] <= 'f')) + || ((s[i] >= 'A') && (s[i] <= 'F')))) + return FALSE; + id->Data1 = (id->Data1 << 4) + | ((s[i] & 0xF) + (s[i] >> 6)) + | ((s[i] >> 3) & 0x8); + } + + id->Data2 = 0; + for (i = 8; i < 12; ++i) { + if (!(((s[i] >= '0') && (s[i] <= '9')) + || ((s[i] >= 'a') && (s[i] <= 'f')) + || ((s[i] >= 'A') && (s[i] <= 'F')))) + return FALSE; + id->Data2 = (id->Data2 << 4) + | ((s[i] & 0xF) + (s[i] >> 6)) + | ((s[i] >> 3) & 0x8); + } + + id->Data3 = 0; + for (i = 12; i < 16; ++i) { + if (!(((s[i] >= '0') && (s[i] <= '9')) + || ((s[i] >= 'a') && (s[i] <= 'f')) + || ((s[i] >= 'A') && (s[i] <= 'F')))) + return FALSE; + id->Data3 = (id->Data3 << 4) + | ((s[i] & 0xF) + (s[i] >> 6)) + | ((s[i] >> 3) & 0x8); + } + + for (i = 16; i < 32; i += 2) { + if (!(((s[i] >= '0') && (s[i] <= '9')) + || ((s[i] >= 'a') && (s[i] <= 'f')) + || ((s[i] >= 'A') && (s[i] <= 'F')) + || ((s[i + 1] >= '0') && (s[i + 1] <= '9')) + || ((s[i + 1] >= 'a') && (s[i + 1] <= 'f')) + || ((s[i + 1] >= 'A') && (s[i + 1] <= 'F')))) + return FALSE; + id->Data4[(i - 16) / 2] = ((((s[i] & 0xF) + (s[i] >> 6)) | ((s[i] >> 3) & 0x8)) << 4) + | (((s[i + 1] & 0xF) + (s[i + 1] >> 6)) | ((s[i + 1] >> 3) & 0x8)); + } + + return TRUE; +} + /****************************************************************************** * NtQuerySystemInformation (NTDLL.@) */ @@ -2794,6 +2853,83 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class, break; }
+ case SystemBootEnvironmentInformation: /* 90 */ + { + static SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0}; + struct stat stat_info = {0}; + ssize_t ssz; + len = sizeof(boot_info); + if (size == len) + { +#if defined(__linux__) || defined(__gnu_linux__) + int fd; + char buffer[32]; + + if (boot_info.FirmwareType == FirmwareTypeUnknown) + { + if (!stat("/sys/firmware/efi", &stat_info)) + boot_info.FirmwareType = FirmwareTypeUefi; + else + boot_info.FirmwareType = FirmwareTypeBios; + } +#else + boot_info.FirmwareType = FirmwareTypeBios; +#endif + if (boot_info.BootIdentifier.Data1 == 0) + { +#if defined(__linux__) || defined(__gnu_linux__) + if (!stat("/etc/machine-id", &stat_info) && stat_info.st_size >= 32) + { + fd = open("/etc/machine-id", O_RDONLY); + if (fd == -1) + goto try_read_hostid; + ssz = read(fd, &buffer, 32); + if (ssz < 0) + goto try_read_hostid; + close(fd); + if (!__wine_hexstr32_to_guid(buffer, &boot_info.BootIdentifier)) + goto try_read_hostid; + } + else + { + try_read_hostid: +#endif +#ifdef __APPLE__ + if (!stat("/Users", &stat_info) || !stat("/System", &stat_info)) +#else + if (!stat("/home", &stat_info) || !stat("/usr", &stat_info)) +#endif + { + boot_info.BootIdentifier.Data1 = gethostid() & 0xFFFFFFFF; + boot_info.BootIdentifier.Data2 = stat_info.st_dev & 0xFFFF; + boot_info.BootIdentifier.Data3 = stat_info.st_ino & 0xFFFF; + boot_info.BootIdentifier.Data4[0] = 'W' ^ (boot_info.BootIdentifier.Data1 & 0xFF); + boot_info.BootIdentifier.Data4[1] = 'I' ^ ((boot_info.BootIdentifier.Data1 >> 4) & 0xFF); + boot_info.BootIdentifier.Data4[2] = 'N' ^ ((boot_info.BootIdentifier.Data1 >> 8) & 0xFF); + boot_info.BootIdentifier.Data4[3] = 'E' ^ ((boot_info.BootIdentifier.Data1 >> 12) & 0xFF); + boot_info.BootIdentifier.Data4[4] = 'B' ^ ((boot_info.BootIdentifier.Data1 >> 16) & 0xFF); + boot_info.BootIdentifier.Data4[5] = 'O' ^ ((boot_info.BootIdentifier.Data1 >> 20) & 0xFF); + boot_info.BootIdentifier.Data4[6] = 'O' ^ ((boot_info.BootIdentifier.Data1 >> 24) & 0xFF); + boot_info.BootIdentifier.Data4[7] = 'T' ^ ((boot_info.BootIdentifier.Data1 >> 28) & 0xFF); + } +#if defined(__linux__) || defined(__gnu_linux__) + } +#endif + boot_info.BootIdentifier.Data3 &= 0x0fff; + boot_info.BootIdentifier.Data3 |= (4 << 12); + /* Set the topmost bits of Data4 (clock_seq_hi_and_reserved) as + * specified in RFC 4122, section 4.4. + */ + boot_info.BootIdentifier.Data4[0] &= 0x3f; + boot_info.BootIdentifier.Data4[0] |= 0x80; + } + memcpy(info, &boot_info, len); + } + else ret = STATUS_INFO_LENGTH_MISMATCH; + if (ret_size) *ret_size = len; + break; + } + case SystemCpuInformation: /* 1 */ if (size >= (len = sizeof(cpu_info))) memcpy(info, &cpu_info, len); else ret = STATUS_INFO_LENGTH_MISMATCH; diff --git a/dlls/wow64/system.c b/dlls/wow64/system.c index 5f3056a4179..402b53e1eda 100644 --- a/dlls/wow64/system.c +++ b/dlls/wow64/system.c @@ -356,6 +356,9 @@ NTSTATUS WINAPI wow64_NtQuerySystemInformation( UINT *args ) if (retlen) *retlen = sizeof(SYSTEM_BASIC_INFORMATION32); return status;
+ case SystemBootEnvironmentInformation: /* SYSTEM_BOOT_ENVIRONMENT_INFORMATION */ + return NtQuerySystemInformation(class, ptr, len, retlen); + case SystemProcessInformation: /* SYSTEM_PROCESS_INFORMATION */ case SystemExtendedProcessInformation: /* SYSTEM_PROCESS_INFORMATION */ { diff --git a/include/winternl.h b/include/winternl.h index 828fbc6e915..510bba09042 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2724,6 +2724,28 @@ typedef struct _SYSTEM_BASIC_INFORMATION { #endif } SYSTEM_BASIC_INFORMATION, *PSYSTEM_BASIC_INFORMATION;
+/* System Information Class 0x90 */ +typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION +{ + GUID BootIdentifier; + FIRMWARE_TYPE FirmwareType; + union + { + ULONGLONG BootFlags; + struct + { + ULONGLONG DbgMenuOsSelection : 1; + ULONGLONG DbgHiberBoot : 1; + ULONGLONG DbgSoftBoot : 1; + ULONGLONG DbgMeasuredLaunch : 1; + ULONGLONG DbgMeasuredLaunchCapable : 1; + ULONGLONG DbgSystemHiveReplace : 1; + ULONGLONG DbgMeasuredLaunchSmmProtections : 1; + ULONGLONG DbgMeasuredLaunchSmmLevel : 7; + }; + }; +} SYSTEM_BOOT_ENVIRONMENT_INFORMATION, *PSYSTEM_BOOT_ENVIRONMENT_INFORMATION; + /* System Information Class 0x01 */
typedef struct _SYSTEM_CPU_INFORMATION {
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/kernel32/process.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 2a4ddc68f02..54c5e58b37d 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -763,10 +763,17 @@ BOOL WINAPI SetFirmwareEnvironmentVariableW(const WCHAR *name, const WCHAR *guid */ BOOL WINAPI GetFirmwareType(FIRMWARE_TYPE *type) { + SYSTEM_BOOT_ENVIRONMENT_INFORMATION boot_info = {0}; + if (!type) return FALSE;
- *type = FirmwareTypeUnknown; + if(!set_ntstatus(NtQuerySystemInformation(SystemBootEnvironmentInformation, + &boot_info, sizeof(boot_info), NULL))) + return FALSE; + + *type = boot_info.FirmwareType; + return TRUE; }
From: Grigory Vasilyev h0tc0d3@gmail.com
--- dlls/kernel32/kernel32.spec | 2 + dlls/kernel32/process.c | 96 ++++++++++++++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index 7ed8048f5d0..5d3556a2078 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -695,7 +695,9 @@ @ stdcall -import GetFileType(long) @ stdcall -import GetFinalPathNameByHandleA(long ptr long long) @ stdcall -import GetFinalPathNameByHandleW(long ptr long long) +@ stdcall GetFirmwareEnvironmentVariableExA(str str ptr long ptr) @ stdcall GetFirmwareEnvironmentVariableA(str str ptr long) +@ stdcall GetFirmwareEnvironmentVariableExW(wstr wstr ptr long ptr) @ stdcall GetFirmwareEnvironmentVariableW(wstr wstr ptr long) @ stdcall GetFirmwareType(ptr) @ stdcall -import GetFullPathNameA(str long ptr ptr) diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 54c5e58b37d..a0e739b0660 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -718,14 +718,99 @@ WORD WINAPI GetMaximumProcessorGroupCount(void) return groups; }
+/*********************************************************************** + * GetFirmwareEnvironmentVariableExA (KERNEL32.@) + */ +DWORD WINAPI GetFirmwareEnvironmentVariableExA(LPCSTR name, LPCSTR guid, PVOID buffer, DWORD size, PDWORD attributes) +{ + int nsize; + GUID vendor = {0}; + LPWSTR wname; + LPWSTR wguid; + UNICODE_STRING uname; + UNICODE_STRING uguid; + DWORD ret_size = size; + + if(!name || !guid || !attributes) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + nsize = MultiByteToWideChar(CP_ACP, 0, guid, -1, NULL, 0); + + if (!(wguid = HeapAlloc(GetProcessHeap(), 0, nsize * sizeof(wguid)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + MultiByteToWideChar(CP_ACP, 0, guid, -1, wguid, nsize); + + RtlInitUnicodeString(&uguid, wguid); + + if (!set_ntstatus(RtlGUIDFromString(&uguid, &vendor))) + return 0; + + nsize = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0); + + if (!(wname = HeapAlloc(GetProcessHeap(), 0, nsize * sizeof(wname)))) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + MultiByteToWideChar(CP_ACP, 0, name, -1, wname, nsize); + + RtlInitUnicodeString(&uname, wname); + + if (!set_ntstatus(NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer, + &ret_size, attributes))) + ret_size = 0; + + HeapFree(GetProcessHeap(), 0, wname); + HeapFree(GetProcessHeap(), 0, wguid); + + return ret_size; +} + /*********************************************************************** * GetFirmwareEnvironmentVariableA (KERNEL32.@) */ DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR name, LPCSTR guid, PVOID buffer, DWORD size) { - FIXME("stub: %s %s %p %lu\n", debugstr_a(name), debugstr_a(guid), buffer, size); - SetLastError(ERROR_INVALID_FUNCTION); - return 0; + DWORD attributes; + return GetFirmwareEnvironmentVariableExA(name, guid, buffer, size, &attributes); +} + +/*********************************************************************** + * GetFirmwareEnvironmentVariableExW (KERNEL32.@) + */ +DWORD WINAPI GetFirmwareEnvironmentVariableExW(LPCWSTR name, LPCWSTR guid, PVOID buffer, DWORD size, PDWORD attributes) +{ + GUID vendor = {0}; + UNICODE_STRING uname; + UNICODE_STRING uguid; + DWORD ret_size = size; + + if(!name || !guid || !attributes) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + RtlInitUnicodeString(&uguid, guid); + + if (!set_ntstatus(RtlGUIDFromString(&uguid, &vendor))) + return 0; + + RtlInitUnicodeString(&uname, name); + + if (!set_ntstatus(NtQuerySystemEnvironmentValueEx(&uname, &vendor, buffer, + &ret_size, attributes))) + return 0; + + return ret_size; }
/*********************************************************************** @@ -733,9 +818,8 @@ DWORD WINAPI GetFirmwareEnvironmentVariableA(LPCSTR name, LPCSTR guid, PVOID buf */ DWORD WINAPI GetFirmwareEnvironmentVariableW(LPCWSTR name, LPCWSTR guid, PVOID buffer, DWORD size) { - FIXME("stub: %s %s %p %lu\n", debugstr_w(name), debugstr_w(guid), buffer, size); - SetLastError(ERROR_INVALID_FUNCTION); - return 0; + DWORD attributes; + return GetFirmwareEnvironmentVariableExW(name, guid, buffer, size, &attributes); }
/***********************************************************************
On Fri Sep 6 17:20:15 2024 +0000, Grigory Vasilyev wrote:
changed this line in [version 17 of the diff](/wine/wine/-/merge_requests/6423/diffs?diff_id=130637&start_sha=873cd5455f02c1eccce64b20e43fb9b25a88be80#ab0e96cab0eba5d12a1176c358d39434c6919313_814_740)
Done.
On Fri Sep 6 17:20:15 2024 +0000, Grigory Vasilyev wrote:
changed this line in [version 17 of the diff](/wine/wine/-/merge_requests/6423/diffs?diff_id=130637&start_sha=873cd5455f02c1eccce64b20e43fb9b25a88be80#d5bcbaed4ae76fff7d2641017921e07798a7da0e_3839_3835)
Done.
On Fri Sep 6 17:20:15 2024 +0000, Grigory Vasilyev wrote:
changed this line in [version 17 of the diff](/wine/wine/-/merge_requests/6423/diffs?diff_id=130637&start_sha=873cd5455f02c1eccce64b20e43fb9b25a88be80#d5bcbaed4ae76fff7d2641017921e07798a7da0e_3848_3851)
Done.
On Fri Sep 6 17:20:16 2024 +0000, Grigory Vasilyev wrote:
changed this line in [version 17 of the diff](/wine/wine/-/merge_requests/6423/diffs?diff_id=130637&start_sha=873cd5455f02c1eccce64b20e43fb9b25a88be80#d5bcbaed4ae76fff7d2641017921e07798a7da0e_3862_3861)
Done.
On Fri Sep 6 17:22:47 2024 +0000, Grigory Vasilyev wrote:
@nsivov yes, it can be done, I didn't notice, thanks. I did it automatically because NtQuerySystemEnvironmentValueEx in Windows requires specifying ret_size, otherwise it will return nothing and it works as IN - buffer size and OUT - return data size.
Done.