fork download
  1. /**
  2.  * ██╗ ██╗███╗ ███╗ █████╗ ██╗ ██╗ █████╗ ██████╗ ███████╗
  3.  * ██║ ██║████╗ ████║██╔══██╗██║ ██║██╔══██╗██╔══██╗██╔════╝
  4.  * ██║ ██║██╔████╔██║███████║██║ █╗ ██║███████║██████╔╝█████╗
  5.  * ╚██╗ ██╔╝██║╚██╔╝██║██╔══██║██║███╗██║██╔══██║██╔══██╗██╔══╝
  6.  * ╚████╔╝ ██║ ╚═╝ ██║██║ ██║╚███╔███╔╝██║ ██║██║ ██║███████╗
  7.  * ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
  8.  *
  9.  * C++ VM detection library
  10.  *
  11.  * ===============================================================
  12.  *
  13.  * This program will scan for IDT values based on the execution
  14.  * of multiple threads, which allows us to collect IDT information
  15.  * that could be potentially used for VM detections.
  16.  *
  17.  * ===============================================================
  18.  *
  19.  * - Made by: @Requiem (https://g...content-available-to-author-only...b.com/NotRequiem)
  20.  * - Repository: https://g...content-available-to-author-only...b.com/kernelwernel/VMAware
  21.  * - License: GPL 3.0
  22.  */
  23.  
  24. #include <iostream>
  25. #include <thread>
  26. #include <vector>
  27. #include <pthread.h>
  28. #include <sched.h>
  29. #include <unistd.h>
  30.  
  31. #ifdef _MSC_VER
  32. #include <intrin.h>
  33. #else
  34. #include <x86intrin.h>
  35. #endif
  36.  
  37. #pragma pack(push, 1)
  38. struct IDTR {
  39. uint16_t limit;
  40. uint64_t base;
  41. };
  42. #pragma pack(pop)
  43.  
  44. void print_idt_base() {
  45. IDTR idtr;
  46.  
  47. #ifdef _MSC_VER
  48. __sidt(&idtr);
  49. #else
  50. asm volatile ("sidt %0" : "=m" (idtr));
  51. #endif
  52.  
  53. uint64_t idt_base = idtr.base;
  54. std::cout << "Thread ID: " << std::this_thread::get_id() << " | IDT base address: 0x" << std::hex << idt_base << "\n";
  55. }
  56.  
  57. // Function to bind a thread to a specific core on Linux
  58. void set_thread_affinity(unsigned int core_id) {
  59. cpu_set_t cpuset;
  60. CPU_ZERO(&cpuset); // Clear the CPU set
  61. CPU_SET(core_id, &cpuset); // Set the desired core
  62.  
  63. // Get the current thread
  64. pthread_t current_thread = pthread_self();
  65.  
  66. // Set thread affinity to the specific core
  67. if (pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset) != 0) {
  68. std::cerr << "Error setting thread affinity\n";
  69. }
  70. }
  71.  
  72. // Function to run code on multiple cores
  73. void run_on_multiple_cores(int times) {
  74. unsigned int num_threads = std::thread::hardware_concurrency();
  75. std::cout << "Running on " << num_threads << " threads (multiple cores)...\n";
  76.  
  77. for (int i = 0; i < times; ++i) {
  78. std::vector<std::thread> threads;
  79. for (unsigned int j = 0; j < num_threads; ++j) {
  80. threads.emplace_back([j]() {
  81. set_thread_affinity(j); // Bind thread to core j
  82. print_idt_base();
  83. });
  84. }
  85.  
  86. for (auto& thread : threads) {
  87. thread.join();
  88. }
  89. }
  90. }
  91.  
  92. // Function to run code on a single core
  93. void run_on_single_core(int times) {
  94. std::cout << "Running on a single core...\n";
  95. set_thread_affinity(0); // Bind thread to core 0
  96.  
  97. for (int i = 0; i < times; ++i) {
  98. print_idt_base();
  99. }
  100. }
  101.  
  102. int main() {
  103. int iterations = 5;
  104. run_on_multiple_cores(iterations);
  105. run_on_single_core(iterations);
  106.  
  107. return 0;
  108. }
Success #stdin #stdout 0.01s 5284KB
stdin
stdout
Running on 8 threads (multiple cores)...
Thread ID: 22787082082048 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987cec700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9882ef700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9886f1700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9880ee700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9888f2700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af3700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9884f0700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9888f2700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af3700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9884f0700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9880ee700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9886f1700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987eed700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987cec700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9882ef700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987eed700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9886f1700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9888f2700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af3700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9882ef700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9880ee700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987cec700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9884f0700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9888f2700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9880ee700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987eed700 | IDT base address: 0xfffffe0000000000
Thread ID: Thread ID: 14b9884f0700 | IDT base address: 0xfffffe000000000014b987cec700
 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9886f1700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9882ef700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af3700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987eed700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9886f1700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9888f2700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af3700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9882ef700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9880ee700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b9884f0700 | IDT base address: 0xfffffe0000000000
Thread ID: 14b987cec700 | IDT base address: 0xfffffe0000000000
Running on a single core...
Thread ID: 14b988af4740 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af4740 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af4740 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af4740 | IDT base address: 0xfffffe0000000000
Thread ID: 14b988af4740 | IDT base address: 0xfffffe0000000000