Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 65 additions & 58 deletions src/vmaware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
#elif __cplusplus == 202002L
#define CPP 20
#ifdef __VMAWARE_DEBUG__
#pragma message("using C++20")

Check warning on line 227 in src/vmaware.hpp

View workflow job for this annotation

GitHub Actions / Analyze (cpp, gcc-14, Ninja Multi-Config, Debug, ON)

using C++20 [-W#pragma-messages]
#endif
#elif __cplusplus == 201703L
#define CPP 17
Expand Down Expand Up @@ -8915,12 +8915,20 @@
SystemFirmwareTableInformation = 76
} SYSTEM_INFORMATION_CLASS;

typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION {
typedef enum _SYSTEM_FIRMWARE_TABLE_ACTION
{
SystemFirmwareTableEnumerate,
SystemFirmwareTableGet,
SystemFirmwareTableMax
} SYSTEM_FIRMWARE_TABLE_ACTION;

typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION
{
ULONG ProviderSignature;
ULONG Action;
SYSTEM_FIRMWARE_TABLE_ACTION Action;
ULONG TableID;
ULONG TableBufferLength;
UCHAR TableBuffer[1];
_Field_size_bytes_(TableBufferLength) UCHAR TableBuffer[1];
} SYSTEM_FIRMWARE_TABLE_INFORMATION, * PSYSTEM_FIRMWARE_TABLE_INFORMATION;
#pragma warning (default : 4459)

Expand Down Expand Up @@ -8963,13 +8971,13 @@
return true;
};

auto query_table = [&](DWORD provider, ULONG tableID, bool rawEnum, PULONG outDataSize) -> PSYSTEM_FIRMWARE_TABLE_INFORMATION {
auto query_table = [&](DWORD provider, DWORD tableID, PULONG outDataSize) -> PSYSTEM_FIRMWARE_TABLE_INFORMATION {
const ULONG header = sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION);
if (!ensure_buffer(header)) return nullptr;

auto hdr = reinterpret_cast<PSYSTEM_FIRMWARE_TABLE_INFORMATION>(qsiBuffer);
hdr->ProviderSignature = provider;
hdr->Action = rawEnum ? 0 : 1;
hdr->Action = SystemFirmwareTableEnumerate;
hdr->TableID = _byteswap_ulong(tableID);
hdr->TableBufferLength = 0;

Expand All @@ -8982,7 +8990,7 @@

hdr = reinterpret_cast<PSYSTEM_FIRMWARE_TABLE_INFORMATION>(qsiBuffer);
hdr->ProviderSignature = provider;
hdr->Action = rawEnum ? 0 : 1;
hdr->Action = SystemFirmwareTableEnumerate;
hdr->TableID = _byteswap_ulong(tableID);
hdr->TableBufferLength = fullSize - header;

Expand All @@ -8993,9 +9001,9 @@
return hdr;
};

auto check_firmware_table = [&](DWORD signature, ULONG tableID) -> bool {
auto check_firmware_table = [&](DWORD signature, DWORD tableID) -> bool {
ULONG gotSize = 0;
auto info = query_table(signature, tableID, true, &gotSize);
auto info = query_table(signature, tableID, &gotSize);
if (!info) return false;

const UCHAR* buf = info->TableBuffer;
Expand Down Expand Up @@ -9038,7 +9046,7 @@

// ACPI enumeration
ULONG totalLen = 0;
auto listInfo = query_table(ACPI_SIG, 0UL, true, &totalLen);
auto listInfo = query_table(ACPI_SIG, 0UL, &totalLen);
if (!listInfo) {
free(qsiBuffer);
return false;
Expand All @@ -9053,7 +9061,7 @@
}

// count SSDT
const DWORD ssdtSig = 'TDSS';
constexpr DWORD ssdtSig = 'TDSS';
ULONG ssdtCount = 0;
for (ULONG i = 0; i < tableCount; ++i) {
if (tables[i] == ssdtSig)
Expand All @@ -9066,14 +9074,13 @@
return true;
}

// iterate all ACPI tables
constexpr DWORD dsdtSig = 'TDSD';
constexpr DWORD facpSig = 'PCAF';
for (ULONG i = 0; i < tableCount; ++i) {
DWORD sig = tables[i];
ULONG sig = tables[i];

if (sig == facpSig) {
ULONG fSize = 0;
auto fadt = query_table(ACPI_SIG, sig, false, &fSize);
auto fadt = query_table(ACPI_SIG, sig, &fSize);
if (!fadt) continue;
BYTE* buf = reinterpret_cast<BYTE*>(fadt->TableBuffer);
// https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#preferred-pm-profile-system-types
Expand All @@ -9082,56 +9089,56 @@
return true;
}
}
if (sig == dsdtSig) {
ULONG dsdtSize = 0;
auto dsdt = query_table(ACPI_SIG, sig, false, &dsdtSize);
if (dsdt) {
const char* tb = reinterpret_cast<const char*>(dsdt->TableBuffer);
bool foundCPU = false;

for (ULONG j = 0; j + 8 <= dsdtSize; ++j) {
if (memcmp(tb + j, "ACPI0007", 8) == 0) { // idea by dmfrpro
foundCPU = true;
break;
}
}
if (check_firmware_table(ACPI_SIG, sig)) {
free(qsiBuffer);
return true;
}
}

if (!foundCPU) {
free(qsiBuffer);
return true;
}
constexpr DWORD dsdtSig = 'DSDT';
ULONG dsdtSize = 0;
auto dsdt = query_table(ACPI_SIG, dsdtSig, &dsdtSize);
if (dsdt) {
const char* tb = reinterpret_cast<const char*>(dsdt->TableBuffer);
bool foundCPU = false;

constexpr const char* osi_targets[] = {
"Windows 95", "Windows 98",
"Windows 2000", "Windows 2000.1",
"Windows ME: Millennium Edition",
"Windows ME: Millennium Edition", // some firmwares omit space
"Windows XP", "Windows 2001",
"Windows 2006", "Windows 2009",
"Windows 2012", "Windows 2015",
"Windows 2020", "Windows 2022",
};
constexpr size_t n_osi = sizeof(osi_targets) / sizeof(osi_targets[0]);

bool foundOSI = false;
for (size_t t = 0; t < n_osi && !foundOSI; ++t) {
const char* s = osi_targets[t];
size_t len = strlen(s);
for (ULONG j = 0; j + len <= dsdtSize; ++j) {
if (memcmp(tb + j, s, len) == 0) {
foundOSI = true;
break;
}
}
}
for (ULONG j = 0; j + 8 <= dsdtSize; ++j) {
if (memcmp(tb + j, "ACPI0007", 8) == 0) { // idea by dmfrpro
foundCPU = true;
break;
}
}

if (!foundOSI) {
free(qsiBuffer);
return true;
if (!foundCPU) {
free(qsiBuffer);
return true;
}

constexpr const char* osi_targets[] = {
"Windows 95", "Windows 98",
"Windows 2000", "Windows 2000.1",
"Windows ME: Millennium Edition",
"Windows ME: Millennium Edition", // some firmwares omit space
"Windows XP", "Windows 2001",
"Windows 2006", "Windows 2009",
"Windows 2012", "Windows 2015",
"Windows 2020", "Windows 2022",
};
constexpr size_t n_osi = sizeof(osi_targets) / sizeof(osi_targets[0]);

bool foundOSI = false;
for (size_t t = 0; t < n_osi && !foundOSI; ++t) {
const char* s = osi_targets[t];
size_t len = strlen(s);
for (ULONG j = 0; j + len <= dsdtSize; ++j) {
if (memcmp(tb + j, s, len) == 0) {
foundOSI = true;
break;
}
}
}
if (check_firmware_table(ACPI_SIG, sig)) {

if (!foundOSI) {
free(qsiBuffer);
return true;
}
Expand Down
Loading