44 * ██║ ██║██╔████╔██║███████║██║ █╗ ██║███████║██████╔╝█████╗
55 * ╚██╗ ██╔╝██║╚██╔╝██║██╔══██║██║███╗██║██╔══██║██╔══██╗██╔══╝
66 * ╚████╔╝ ██║ ╚═╝ ██║██║ ██║╚███╔███╔╝██║ ██║██║ ██║███████╗
7- * ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ 1.4 (May 2024)
7+ * ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ 1.5 (June 2024)
88 *
99 * C++ VM detection library
1010 *
4343 *
4444 *
4545 * ================================ SECTIONS ==================================
46- * - enums for publicly accessible techniques => line 293
47- * - struct for internal cpu operations => line 485
48- * - struct for internal memoization => line 857
49- * - struct for internal utility functions => line 941
50- * - struct for internal core components => line 6916
51- * - start of internal VM detection techniques => line 1686
52- * - start of public VM detection functions => line 7265
53- * - start of externally defined variables => line 7602
46+ * - enums for publicly accessible techniques => line 314
47+ * - struct for internal cpu operations => line 506
48+ * - struct for internal memoization => line 878
49+ * - struct for internal utility functions => line 962
50+ * - struct for internal core components => line 6929
51+ * - start of internal VM detection techniques => line 1740
52+ * - start of public VM detection functions => line 7281
53+ * - start of externally defined variables => line 7618
5454 *
5555 *
5656 * ================================ EXAMPLE ==================================
@@ -1636,6 +1636,33 @@ struct VM {
16361636 return (tmp && isWow64);
16371637 }
16381638
1639+ // backup function in case the main get_windows_version function fails
1640+ [[nodiscard]] static u8 get_windows_version_backup () {
1641+ u8 ret = 0 ;
1642+ NTSTATUS (WINAPI * RtlGetVersion)(LPOSVERSIONINFOEXW) = nullptr ;
1643+ OSVERSIONINFOEXW osInfo{};
1644+
1645+ HMODULE ntdllModule = GetModuleHandleA (" ntdll" );
1646+
1647+ if (ntdllModule == nullptr ) {
1648+ return false ;
1649+ }
1650+
1651+ *(FARPROC*)&RtlGetVersion = GetProcAddress (ntdllModule, " RtlGetVersion" );
1652+
1653+ if (RtlGetVersion == nullptr ) {
1654+ return false ;
1655+ }
1656+
1657+ if (RtlGetVersion != nullptr ) {
1658+ osInfo.dwOSVersionInfoSize = sizeof (osInfo);
1659+ RtlGetVersion (&osInfo);
1660+ ret = static_cast <u8 >(osInfo.dwMajorVersion );
1661+ }
1662+
1663+ return ret;
1664+ }
1665+
16391666 // credits to @Requiem for the code, thanks man :)
16401667 [[nodiscard]] static u8 get_windows_version () {
16411668 typedef NTSTATUS (WINAPI* RtlGetVersionFunc)(PRTL_OSVERSIONINFOW);
@@ -1666,19 +1693,19 @@ struct VM {
16661693
16671694 HMODULE ntdll = LoadLibraryW (L" ntdll.dll" );
16681695 if (!ntdll) {
1669- return 0 ;
1696+ return util::get_windows_version_backup () ;
16701697 }
16711698
16721699 RtlGetVersionFunc pRtlGetVersion = (RtlGetVersionFunc)GetProcAddress (ntdll, " RtlGetVersion" );
16731700 if (!pRtlGetVersion) {
1674- return 0 ;
1701+ return util::get_windows_version_backup () ;
16751702 }
16761703
16771704 RTL_OSVERSIONINFOW osvi;
16781705 osvi.dwOSVersionInfoSize = sizeof (osvi);
16791706
16801707 if (pRtlGetVersion (&osvi) != 0 ) {
1681- return 0 ;
1708+ return util::get_windows_version_backup () ;
16821709 }
16831710
16841711 u8 major_version = 0 ;
@@ -1689,8 +1716,14 @@ struct VM {
16891716
16901717 FreeLibrary (ntdll);
16911718
1719+ if (major_version == 0 ) {
1720+ return util::get_windows_version_backup ();
1721+ }
1722+
16921723 return major_version;
16931724 }
1725+
1726+
16941727#endif
16951728 };
16961729
@@ -6424,47 +6457,6 @@ struct VM {
64246457 }
64256458
64266459
6427- /* *
6428- * @brief Check for AMD CPUs that don't match their thread count
6429- * @category All, x86
6430- * @link https://en.wikipedia.org/wiki/List_of_AMD_Ryzen_processors
6431- */
6432- /*
6433- [[nodiscard]] static bool amd_thread_mismatch() try {
6434- #if (!x86)
6435- return false;
6436- #else
6437- if (!cpu::is_amd()) {
6438- return false;
6439- }
6440-
6441- if (cpu::has_hyperthreading()) {
6442- return false;
6443- }
6444-
6445- const cpu::model_struct model = cpu::get_model();
6446-
6447- if (!model.found) {
6448- return false;
6449- }
6450-
6451- if (!model.is_ryzen) {
6452- return false;
6453- }
6454-
6455- debug("AMD_THREAD_MISMATCH: CPU model = ", model.string);
6456- #endif
6457- }
6458- catch (...) {
6459- debug("AMD_THREAD_MISMATCH: catched error, returned false");
6460- return false;
6461- }
6462- */
6463-
6464-
6465-
6466-
6467-
64686460 struct core {
64696461 MSVC_DISABLE_WARNING (PADDING)
64706462 struct technique {
@@ -6618,15 +6610,18 @@ struct VM {
66186610 return false ;
66196611#else
66206612 if (core::enabled (flags, VM::DISCARD_HYPERV_DEFAULT)) {
6613+ debug (" HYPERV_CHECK: returned false through flag check" );
66216614 return false ;
66226615 }
66236616
66246617 const u8 version = util::get_windows_version ();
66256618
6626- if (
6627- (version == 0 ) ||
6628- (version < 10 )
6629- ) {
6619+ if (version == 0 ) {
6620+ return true ;
6621+ }
6622+
6623+ if (version < 10 ) {
6624+ debug (" HYPERV_CHECK: returned false through insufficient windows version (version " , static_cast <u32 >(version), " )" );
66306625 return false ;
66316626 }
66326627
@@ -6644,7 +6639,7 @@ struct VM {
66446639 tmp_brand == " Microsoft Virtual PC/Hyper-V"
66456640 );
66466641
6647- debug (" is Hyper-V brand check = " , result);
6642+ debug (" HYPERV_CHECK: is Hyper-V brand check = " , result);
66486643
66496644 return result;
66506645#endif
0 commit comments