constexpr aubool take_time() { constexprauto measure_time = 5; longlong __cpuid_time = 0; longlong __fyl2xp1_time = 0; LARGE_INTEGER frequency = {}; LARGE_INTEGER start = {}; LARGE_INTEGER end = {}; QueryPerformanceFrequency(&frequency); // count the average time it takes to execute a CPUID instruction for (std::size_t i = 0; i < measure_time; ++i) { QueryPerformanceCounter(&start); _cpuid_buffer_t cpuid_data; __cpuid(reinterpret_cast<int*>(&cpuid_data), 1); QueryPerformanceCounter(&end); auto delta = end.QuadPart - start.QuadPart; delta *= 1000000000; delta /= frequency.QuadPart; __cpuid_time += delta; } // count the average time it takes to execute a FYL2XP1 instruction for (std::size_t i = 0; i < measure_time; ++i) { QueryPerformanceCounter(&start); #ifdef _WIN64 _asm_fyl2xp1(); #else _asm FYL2XP1 #endif QueryPerformanceCounter(&end); auto delta = end.QuadPart - start.QuadPart; delta *= 1000000000; delta /= frequency.QuadPart; __fyl2xp1_time += delta; } return __fyl2xp1_time <= __cpuid_time; } booltake_time_cpuid_against_fyl2xp1() { constexprauto measure_times = 5; auto positives = 0; auto negatives = 0; // run the internal VM check multiple times to get an average result for (auto i = measure_times; i != 0; --i) take_time() ? ++positives : ++negatives; // if there are more positive results than negative results, the // process is likely running inside a VM constbool decision = (positives >= negatives); return decision; }to measure_time = 5; longlong __cpuid_time = 0; longlong __fyl2xp1_time = 0; LARGE_INTEGER frequency = {}; LARGE_INTEGER start = {}; LARGE_INTEGER end = {}; QueryPerformanceFrequency(&frequency); // count the average time it takes to execute a CPUID instruction for (std::size_t i = 0; i < measure_time; ++i) { QueryPerformanceCounter(&start); _cpuid_buffer_t cpuid_data; __cpuid(reinterpret_cast<int*>(&cpuid_data), 1); QueryPerformanceCounter(&end); auto delta = end.QuadPart - start.QuadPart; delta *= 1000000000; delta /= frequency.QuadPart; __cpuid_time += delta; } // count the average time it takes to execute a FYL2XP1 instruction for (std::size_t i = 0; i < measure_time; ++i) { QueryPerformanceCounter(&start); #ifdef _WIN64 _asm_fyl2xp1(); #else _asm FYL2XP1 #endif QueryPerformanceCounter(&end); auto delta = end.QuadPart - start.QuadPart; delta *= 1000000000; delta /= frequency.QuadPart; __fyl2xp1_time += delta; } return __fyl2xp1_time <= __cpuid_time;