Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <intrin.h>
- #include <stdio.h>
- #include <tchar.h>
- #include <conio.h>
- #include <locale.h>
- #include <Windows.h>
- #pragma optimize( "", off )
- static inline unsigned long long rdtsc_diff_vmexit() {
- int cpuid[4];
- auto t0 = __rdtsc();
- __cpuid(cpuid, 0);
- __cpuid(cpuid, 0);
- __cpuid(cpuid, 0);
- __cpuid(cpuid, 0);
- __cpuid(cpuid, 0);
- auto t1 = __rdtsc();
- printf("%llx %llx ",t0,t1);
- return t1 - t0;
- }
- #pragma optimize( "", on )
- int cpu_rdtsc_force_vmexit() {
- int i;
- unsigned long long avg = 0;
- unsigned long long tsc_diff;
- for (i = 0; i < 10; i++) {
- tsc_diff = rdtsc_diff_vmexit();
- printf("[%i] %llu\n", i, tsc_diff);
- avg = avg + tsc_diff;
- Sleep(500);
- }
- avg = avg / 10;
- return (avg < 1000 && avg > 0) ? FALSE : TRUE;
- }
- int main()
- {
- if (cpu_rdtsc_force_vmexit())
- printf("detected");
- else
- printf("not detected");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement