Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <intrin.h>
  4. #include <stdio.h>
  5. #include <tchar.h>
  6. #include <conio.h>
  7. #include <locale.h>
  8. #include <Windows.h>
  9.  
  10. #pragma optimize( "", off )
  11. static inline unsigned long long rdtsc_diff_vmexit() {
  12. int cpuid[4];
  13. auto t0 = __rdtsc();
  14. __cpuid(cpuid, 0);
  15. __cpuid(cpuid, 0);
  16. __cpuid(cpuid, 0);
  17. __cpuid(cpuid, 0);
  18. __cpuid(cpuid, 0);
  19. auto t1 = __rdtsc();
  20. printf("%llx %llx ",t0,t1);
  21. return t1 - t0;
  22. }
  23. #pragma optimize( "", on )
  24.  
  25. int cpu_rdtsc_force_vmexit() {
  26. int i;
  27. unsigned long long avg = 0;
  28.  
  29. unsigned long long tsc_diff;
  30.  
  31. for (i = 0; i < 10; i++) {
  32. tsc_diff = rdtsc_diff_vmexit();
  33.  
  34. printf("[%i] %llu\n", i, tsc_diff);
  35.  
  36. avg = avg + tsc_diff;
  37. Sleep(500);
  38. }
  39. avg = avg / 10;
  40.  
  41. return (avg < 1000 && avg > 0) ? FALSE : TRUE;
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47.  
  48. if (cpu_rdtsc_force_vmexit())
  49. printf("detected");
  50. else
  51. printf("not detected");
  52.  
  53. _getch();
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement