-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCheck-Inter-VT.cpp
More file actions
65 lines (53 loc) · 1.74 KB
/
Check-Inter-VT.cpp
File metadata and controls
65 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
#include <intrin.h>
#include <Windows.h>
bool detect_vt_x_amd_v() {
int cpu_info[4] = { -1 };
__cpuid(cpu_info, 1);
// Check Intel VT-x or AMD-V support
return (cpu_info[2] & (1 << 5)) || (cpu_info[2] & (1 << 2));
}
bool detect_vmware() {
const char* vmware_str = "VMwareVMware";
const size_t vmware_str_len = strlen(vmware_str);
unsigned char mem[64] = { 0 };
for (size_t i = 0; i < sizeof(mem) - vmware_str_len; ++i) {
if (memcmp(mem + i, vmware_str, vmware_str_len) == 0) {
return true;
}
}
return false;
}
bool detect_virtualbox() {
HKEY h_key;
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, &h_key) != ERROR_SUCCESS) {
return false;
}
char value[256] = { 0 };
DWORD value_size = sizeof(value);
if (RegQueryValueExA(h_key, "SystemBiosVersion", NULL, NULL, (LPBYTE)value, &value_size) != ERROR_SUCCESS) {
RegCloseKey(h_key);
return false;
}
RegCloseKey(h_key);
return strstr(value, "VBOX") != nullptr;
}
int main() {
if (detect_vt_x_amd_v()) {
std::cout << "Intel VT-x or AMD-V virtualization technology detected." << std::endl;
} else {
std::cout << "Intel VT-x or AMD-V virtualization technology not detected." << std::endl;
}
if (detect_vmware()) {
std::cout << "VMware detected." << std::endl;
} else {
std::cout << "VMware not detected." << std::endl;
}
if (detect_virtualbox()) {
std::cout << "VirtualBox detected." << std::endl;
} else {
std::cout << "VirtualBox not detected." << std::endl;
}
return 0;
}