Skip to content

Commit cb9b60d

Browse files
authored
Merge pull request #311 from kernelwernel/dev
Fixed issues in Hyper-X algorithm
2 parents ddd0225 + b774c98 commit cb9b60d

2 files changed

Lines changed: 36 additions & 54 deletions

File tree

src/vmaware.hpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
*
2626
*
2727
* ============================== SECTIONS ==================================
28-
* - enums for publicly accessible techniques => line 551
29-
* - struct for internal cpu operations => line 744
30-
* - struct for internal memoization => line 1198
31-
* - struct for internal utility functions => line 1323
32-
* - struct for internal core components => line 10063
33-
* - start of VM detection technique list => line 2528
34-
* - start of public VM detection functions => line 10727
35-
* - start of externally defined variables => line 11650
28+
* - enums for publicly accessible techniques => line 553
29+
* - struct for internal cpu operations => line 746
30+
* - struct for internal memoization => line 1200
31+
* - struct for internal utility functions => line 1325
32+
* - struct for internal core components => line 10055
33+
* - start of VM detection technique list => line 2521
34+
* - start of public VM detection functions => line 10719
35+
* - start of externally defined variables => line 11642
3636
*
3737
*
3838
* ============================== EXAMPLE ===================================
@@ -184,6 +184,7 @@
184184
#pragma once
185185

186186
#if defined(_WIN32) || defined(_WIN64)
187+
#define WIN32_LEAN_AND_MEAN
187188
#define WINDOWS 1
188189
#define LINUX 0
189190
#define APPLE 0
@@ -1931,9 +1932,6 @@ struct VM {
19311932
* These child partitions have limited privileges and access to hypervisor resources,
19321933
* which is reflected in the maximum input value for hypervisor CPUID information as 11.
19331934
* Essentially, it indicates that the hypervisor is managing the VM and that the VM is not running directly on hardware but rather in a virtualized environment.
1934-
*
1935-
* On the other hand, in bare-metal systems running Hyper-V, the EAX value is 12.
1936-
* This higher value corresponds to the root partition, which has more privileges and control over virtualization resources compared to child partitions.
19371935
*/
19381936
auto eax = []() -> u32 {
19391937
char out[sizeof(int32_t) * 4 + 1] = { 0 };
@@ -1959,24 +1957,18 @@ struct VM {
19591957
}
19601958
}
19611959
else {
1962-
if (eax() == 12) {
1963-
const std::string brand_str = cpu::cpu_manufacturer(0x40000001);
1960+
const std::string brand_str = cpu::cpu_manufacturer(0x40000001);
19641961

1965-
if (util::find(brand_str, "KVM")) {
1966-
core_debug("HYPER_X: added Hyper-V Enlightenments");
1967-
core::add(brands::QEMU_KVM_HYPERV);
1968-
state = HYPERV_ENLIGHTENMENT;
1969-
}
1970-
else {
1971-
// Windows machine running under Hyper-V type 1
1972-
core_debug("HYPER_X: added Hyper-V artifact VM");
1973-
core::add(brands::HYPERV_ARTIFACT);
1974-
state = HYPERV_ARTIFACT_VM;
1975-
}
1962+
if (util::find(brand_str, "KVM")) {
1963+
core_debug("HYPER_X: added Hyper-V Enlightenments");
1964+
core::add(brands::QEMU_KVM_HYPERV);
1965+
state = HYPERV_ENLIGHTENMENT;
19761966
}
19771967
else {
1978-
core_debug("HYPER_X: none found");
1979-
state = HYPERV_UNKNOWN_VM;
1968+
// Windows machine running under Hyper-V type 1
1969+
core_debug("HYPER_X: added Hyper-V artifact VM");
1970+
core::add(brands::HYPERV_ARTIFACT);
1971+
state = HYPERV_ARTIFACT_VM;
19801972
}
19811973
}
19821974

@@ -2632,7 +2624,6 @@ struct VM {
26322624
#if (!x86)
26332625
return false;
26342626
#else
2635-
26362627
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
26372628
return false;
26382629
}

src/vmaware_MIT.hpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@
4747
*
4848
*
4949
* ============================== SECTIONS ==================================
50-
* - enums for publicly accessible techniques => line 573
51-
* - struct for internal cpu operations => line 759
52-
* - struct for internal memoization => line 1214
53-
* - struct for internal utility functions => line 1340
54-
* - struct for internal core components => line 9869
55-
* - start of VM detection technique list => line 2547
56-
* - start of public VM detection functions => line 10544
57-
* - start of externally defined variables => line 11469
50+
* - enums for publicly accessible techniques => line 575
51+
* - struct for internal cpu operations => line 761
52+
* - struct for internal memoization => line 1216
53+
* - struct for internal utility functions => line 1342
54+
* - struct for internal core components => line 9861
55+
* - start of VM detection technique list => line 2540
56+
* - start of public VM detection functions => line 10536
57+
* - start of externally defined variables => line 11461
5858
*
5959
*
6060
* ============================== EXAMPLE ===================================
@@ -206,6 +206,7 @@
206206
#pragma once
207207

208208
#if defined(_WIN32) || defined(_WIN64)
209+
#define WIN32_LEAN_AND_MEAN
209210
#define WINDOWS 1
210211
#define LINUX 0
211212
#define APPLE 0
@@ -1950,9 +1951,6 @@ struct VM {
19501951
* These child partitions have limited privileges and access to hypervisor resources,
19511952
* which is reflected in the maximum input value for hypervisor CPUID information as 11.
19521953
* Essentially, it indicates that the hypervisor is managing the VM and that the VM is not running directly on hardware but rather in a virtualized environment.
1953-
*
1954-
* On the other hand, in bare-metal systems running Hyper-V, the EAX value is 12.
1955-
* This higher value corresponds to the root partition, which has more privileges and control over virtualization resources compared to child partitions.
19561954
*/
19571955
auto eax = []() -> u32 {
19581956
char out[sizeof(int32_t) * 4 + 1] = { 0 };
@@ -1978,24 +1976,18 @@ struct VM {
19781976
}
19791977
}
19801978
else {
1981-
if (eax() == 12) {
1982-
const std::string brand_str = cpu::cpu_manufacturer(0x40000001);
1979+
const std::string brand_str = cpu::cpu_manufacturer(0x40000001);
19831980

1984-
if (util::find(brand_str, "KVM")) {
1985-
core_debug("HYPER_X: added Hyper-V Enlightenments");
1986-
core::add(brands::QEMU_KVM_HYPERV);
1987-
state = HYPERV_ENLIGHTENMENT;
1988-
}
1989-
else {
1990-
// Windows machine running under Hyper-V type 1
1991-
core_debug("HYPER_X: added Hyper-V artifact VM");
1992-
core::add(brands::HYPERV_ARTIFACT);
1993-
state = HYPERV_ARTIFACT_VM;
1994-
}
1981+
if (util::find(brand_str, "KVM")) {
1982+
core_debug("HYPER_X: added Hyper-V Enlightenments");
1983+
core::add(brands::QEMU_KVM_HYPERV);
1984+
state = HYPERV_ENLIGHTENMENT;
19951985
}
19961986
else {
1997-
core_debug("HYPER_X: none found");
1998-
state = HYPERV_UNKNOWN_VM;
1987+
// Windows machine running under Hyper-V type 1
1988+
core_debug("HYPER_X: added Hyper-V artifact VM");
1989+
core::add(brands::HYPERV_ARTIFACT);
1990+
state = HYPERV_ARTIFACT_VM;
19991991
}
20001992
}
20011993

@@ -2651,7 +2643,6 @@ struct VM {
26512643
#if (!x86)
26522644
return false;
26532645
#else
2654-
26552646
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
26562647
return false;
26572648
}

0 commit comments

Comments
 (0)