This commit is contained in:
DavidXanatos 2024-07-21 14:52:35 +02:00
parent 29b0ac2154
commit a59698b0eb
2 changed files with 38 additions and 21 deletions

View File

@ -216,42 +216,59 @@ _FX NTSTATUS SysInfo_NtQuerySystemInformation(
PSYSTEM_FIRMWARE_TABLE_INFORMATION firmwareTableInfo = (PSYSTEM_FIRMWARE_TABLE_INFORMATION)Buffer;
if (firmwareTableInfo->ProviderSignature == FIRMWARE_TABLE_PROVIDER_SMBIOS && firmwareTableInfo->Action == SystemFirmwareTable_Get)
{
typedef LSTATUS(*ROK)(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
typedef LSTATUS(*RQVEW)(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
typedef LSTATUS(*RCK)(HKEY hKey);
ROK RegOpenKeyExW = (ROK)GetProcAddress(LoadLibraryW(DllName_advapi32), "RegOpenKeyExW");
RQVEW RegQueryValueExW = (RQVEW)GetProcAddress(LoadLibraryW(DllName_advapi32), "RegQueryValueExW");
RCK RegCloseKey = (RCK)GetProcAddress(LoadLibraryW(DllName_advapi32), "RegCloseKey");
if (firmwareTableInfo->ProviderSignature == FIRMWARE_TABLE_PROVIDER_SMBIOS && firmwareTableInfo->Action == SystemFirmwareTable_Get) {
typedef LSTATUS(*RegOpenKeyExW_t)(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult);
typedef LSTATUS(*RegQueryValueExW_t)(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
typedef LSTATUS(*RegCloseKey_t)(HKEY hKey);
HMODULE advapi32 = LoadLibraryW(DllName_advapi32);
if (!advapi32) return STATUS_UNSUCCESSFUL;
RegOpenKeyExW_t RegOpenKeyExW = (RegOpenKeyExW_t)GetProcAddress(advapi32, "RegOpenKeyExW");
RegQueryValueExW_t RegQueryValueExW = (RegQueryValueExW_t)GetProcAddress(advapi32, "RegQueryValueExW");
RegCloseKey_t RegCloseKey = (RegCloseKey_t)GetProcAddress(advapi32, "RegCloseKey");
if (!RegOpenKeyExW || !RegQueryValueExW || !RegCloseKey) {
FreeLibrary(advapi32);
return STATUS_UNSUCCESSFUL;
}
HKEY hKey = NULL;
DWORD dwLen = 0x10000;
PVOID lpData = Dll_AllocTemp(dwLen);
DWORD type;
if (!lpData)
if (!lpData) {
FreeLibrary(advapi32);
return STATUS_UNSUCCESSFUL;
}
DWORD type = 0;
// if not set we return no information, 0 length
if (RegOpenKeyExW && RegOpenKeyExW(HKEY_CURRENT_USER, L"System\\SbieCustom", 0, KEY_READ, &hKey) == 0) {
RegQueryValueExW(hKey, L"SMBiosTable", 0, &type, lpData, &dwLen);
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"System\\SbieCustom", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
if (RegQueryValueExW(hKey, L"SMBiosTable", NULL, &type, (LPBYTE)lpData, &dwLen) != ERROR_SUCCESS) {
dwLen = 0;
}
RegCloseKey(hKey);
}
*ReturnLength = dwLen;
if (dwLen > 0) {
if (dwLen + sizeof(PSYSTEM_FIRMWARE_TABLE_INFORMATION) > BufferLength)
return STATUS_BUFFER_TOO_SMALL;
if (dwLen + sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION) > BufferLength) {
status = STATUS_BUFFER_TOO_SMALL;
goto cleanup;
}
firmwareTableInfo->TableBufferLength = dwLen;
memcpy(firmwareTableInfo->TableBuffer, lpData, dwLen);
}
Dll_Free(lpData);
status = STATUS_SUCCESS;
return STATUS_SUCCESS;
cleanup:
Dll_Free(lpData);
FreeLibrary(advapi32);
return status;
}
}

View File

@ -1391,9 +1391,9 @@ retry:
{
HKEY hKey;
DWORD disposition;
if(RegCreateKeyExW(HKEY_CURRENT_USER, L"System\\SbieCustom", 0, 0, 0, KEY_WRITE, NULL, &hKey, &disposition) == 0)
if(RegCreateKeyExW(HKEY_CURRENT_USER, L"System\\SbieCustom", 0, 0, 0, KEY_WRITE, NULL, &hKey, &disposition) == ERROR_SUCCESS)
{
if(RegSetValueExW(hKey, L"SMBiosTable", 0, REG_BINARY, firmwareTableInfo->TableBuffer, firmwareTableInfo->TableBufferLength) == 0)
if(RegSetValueExW(hKey, L"SMBiosTable", 0, REG_BINARY, firmwareTableInfo->TableBuffer, firmwareTableInfo->TableBufferLength) == ERROR_SUCCESS)
CSandMan::ShowMessageBox(this, QMessageBox::Information, tr("Firmware table saved successfully to host registry: HKEY_CURRENT_USER\\System\\SbieCustom<br />you can copy it to the sandboxed registry to have a different value for each box."));
RegCloseKey(hKey);