Skip to content

Commit a0852dc

Browse files
committed
hyperv test 3
1 parent a643440 commit a0852dc

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

src/vmaware.hpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,33 @@ struct VM {
16251625
return (tmp && isWow64);
16261626
}
16271627

1628+
// backup function in case the main get_windows_version function fails
1629+
[[nodiscard]] static u8 get_windows_version_backup() {
1630+
u8 ret = 0;
1631+
NTSTATUS(WINAPI * RtlGetVersion)(LPOSVERSIONINFOEXW) = nullptr;
1632+
OSVERSIONINFOEXW osInfo{};
1633+
1634+
HMODULE ntdllModule = GetModuleHandleA("ntdll");
1635+
1636+
if (ntdllModule == nullptr) {
1637+
return false;
1638+
}
1639+
1640+
*(FARPROC*)&RtlGetVersion = GetProcAddress(ntdllModule, "RtlGetVersion");
1641+
1642+
if (RtlGetVersion == nullptr) {
1643+
return false;
1644+
}
1645+
1646+
if (RtlGetVersion != nullptr) {
1647+
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
1648+
RtlGetVersion(&osInfo);
1649+
ret = static_cast<u8>(osInfo.dwMajorVersion);
1650+
}
1651+
1652+
return ret;
1653+
}
1654+
16281655
// credits to @Requiem for the code, thanks man :)
16291656
[[nodiscard]] static u8 get_windows_version() {
16301657
typedef NTSTATUS(WINAPI* RtlGetVersionFunc)(PRTL_OSVERSIONINFOW);
@@ -1655,19 +1682,19 @@ struct VM {
16551682

16561683
HMODULE ntdll = LoadLibraryW(L"ntdll.dll");
16571684
if (!ntdll) {
1658-
return 0;
1685+
return util::get_windows_version_backup();
16591686
}
16601687

16611688
RtlGetVersionFunc pRtlGetVersion = (RtlGetVersionFunc)GetProcAddress(ntdll, "RtlGetVersion");
16621689
if (!pRtlGetVersion) {
1663-
return 0;
1690+
return util::get_windows_version_backup();
16641691
}
16651692

16661693
RTL_OSVERSIONINFOW osvi;
16671694
osvi.dwOSVersionInfoSize = sizeof(osvi);
16681695

16691696
if (pRtlGetVersion(&osvi) != 0) {
1670-
return 0;
1697+
return util::get_windows_version_backup();
16711698
}
16721699

16731700
u8 major_version = 0;
@@ -1678,8 +1705,14 @@ struct VM {
16781705

16791706
FreeLibrary(ntdll);
16801707

1708+
if (major_version == 0) {
1709+
return util::get_windows_version_backup();
1710+
}
1711+
16811712
return major_version;
16821713
}
1714+
1715+
16831716
#endif
16841717
};
16851718

0 commit comments

Comments
 (0)