Skip to content

Commit d0b9000

Browse files
author
igor korkin
committed
Fix Windows license check: use WMI to get the detailed status, avoid false positives
1 parent f27424d commit d0b9000

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

al-khaser/AntiVM/Generic.cpp

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,26 +1759,69 @@ Checks whether the specified application is a genuine Windows installation.
17591759
17601760
*/
17611761

1762-
#define WINDOWS_SLID \
1763-
{ 0x55c92734, \
1764-
0xd682, \
1765-
0x4d71, \
1766-
{ 0x98, 0x3e, 0xd6, 0xec, 0x3f, 0x16, 0x05, 0x9f } }
1762+
enum LicenseStatus {
1763+
UNLICENSED = 0, // Unlicensed
1764+
LICENSED = 1, // Licensed
1765+
OOB_GRACE = 2, // OOBGrace
1766+
OOT_GRACE = 3, // OOTGrace
1767+
NON_GENUINE_GRACE = 4, // NonGenuineGrace
1768+
NOTIFICATION = 5, // Notification
1769+
EXTENDED_GRACE = 6 // ExtendedGrace
1770+
};
17671771

17681772
BOOL pirated_windows()
17691773
{
1770-
CONST SLID AppId = WINDOWS_SLID;
1771-
SL_GENUINE_STATE GenuineState;
1772-
HRESULT hResult;
1774+
IWbemServices *pSvc = NULL;
1775+
IWbemLocator *pLoc = NULL;
1776+
IEnumWbemClassObject *pEnumerator = NULL;
1777+
BOOL bStatus = FALSE;
1778+
HRESULT hRes;
1779+
BOOL bFound = FALSE;
17731780

1774-
hResult = SLIsGenuineLocal(&AppId, &GenuineState, NULL);
1781+
// Init WMI
1782+
bStatus = InitWMI(&pSvc, &pLoc, _T("ROOT\\CIMV2"));
1783+
if (bStatus) {
1784+
// If success, execute the desired query
1785+
bStatus = ExecWMIQuery(
1786+
&pSvc, &pLoc, &pEnumerator,
1787+
_T("SELECT LicenseStatus FROM SoftwareLicensingProduct WHERE ")
1788+
_T("ApplicationId = '55c92734-d682-4d71-983e-d6ec3f16059f' AND ")
1789+
_T("PartialProductKey IS NOT NULL"));
1790+
if (bStatus) {
1791+
// Get the data from the query
1792+
IWbemClassObject *pclsObj = NULL;
1793+
ULONG uReturn = 0;
1794+
VARIANT vtProp;
17751795

1776-
if (hResult == S_OK) {
1777-
if (GenuineState != SL_GEN_STATE_IS_GENUINE) {
1778-
return TRUE;
1796+
if (pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn) ==
1797+
S_OK &&
1798+
uReturn) {
1799+
VARIANT vtProp{};
1800+
::VariantInit(&vtProp);
1801+
1802+
// Get the value of the Name property
1803+
if (SUCCEEDED(pclsObj->Get(L"LicenseStatus", 0, &vtProp,
1804+
nullptr, nullptr)) &&
1805+
vtProp.vt == VT_I4) {
1806+
1807+
// Do our comparison
1808+
if (vtProp.lVal == LicenseStatus::UNLICENSED) {
1809+
bFound = TRUE;
1810+
}
1811+
}
1812+
::VariantClear(&vtProp);
1813+
pclsObj->Release();
1814+
}
1815+
1816+
// Cleanup
1817+
pEnumerator->Release();
1818+
pSvc->Release();
1819+
pLoc->Release();
1820+
CoUninitialize();
17791821
}
17801822
}
1781-
return FALSE;
1823+
1824+
return bFound;
17821825
}
17831826

17841827
/* Check HKLM\System\CurrentControlSet\Services\Disk\Enum for values related

0 commit comments

Comments
 (0)