Skip to content

Commit ad2c73b

Browse files
author
Requiem
committed
chore: made VM::HYPERVISOR_QUERY x64 only
1 parent a857a07 commit ad2c73b

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

src/cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ static void general() {
809809
checker(VM::POWER_CAPABILITIES, "power capabilities");
810810
checker(VM::QEMU_FW_CFG, "QEMU fw_cfg device");
811811
checker(VM::VIRTUAL_PROCESSORS, "virtual processors");
812-
checker(VM::HYPERV_QUERY, "hypervisor query");
812+
checker(VM::HYPERVISOR_QUERY, "hypervisor query");
813813
checker(VM::AMD_SEV, "AMD-SEV MSR");
814814
checker(VM::VIRTUAL_REGISTRY, "registry emulation");
815815
checker(VM::FIRMWARE, "firmware");

src/vmaware.hpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ struct VM {
545545
DRIVERS,
546546
DEVICE_HANDLES,
547547
VIRTUAL_PROCESSORS,
548-
HYPERV_QUERY,
548+
HYPERVISOR_QUERY,
549549
AUDIO,
550550
DISPLAY,
551551
DLL,
@@ -4175,7 +4175,7 @@ struct VM {
41754175
debug("TIMER: Running inside a binary translation layer");
41764176
return false;
41774177
}
4178-
u16 cycleThreshold = 1500;
4178+
u16 cycleThreshold = 1200;
41794179
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
41804180
cycleThreshold = 15000; // if we're running under Hyper-V, attempt to detect nested virtualization only
41814181
}
@@ -4215,18 +4215,18 @@ struct VM {
42154215
const u64 t1 = __rdtsc();
42164216

42174217
u32 a, b, c, d;
4218-
cpu::cpuid(a, b, c, d, 0);
4218+
cpu::cpuid(a, b, c, d, 0); // sometimes not intercepted in compat mode under some hvs
42194219

42204220
const u64 t2 = __rdtscp(&aux);
42214221

42224222
return t2 - t1;
42234223
};
42244224

4225-
constexpr int N = 100;
4225+
constexpr u8 N = 100;
42264226

42274227
auto sample_avg = [&]() -> u64 {
42284228
u64 sum = 0;
4229-
for (int i = 0; i < N; ++i) {
4229+
for (u8 i = 0; i < N; ++i) {
42304230
sum += cpuid();
42314231
}
42324232
return (sum + N / 2) / N;
@@ -7956,10 +7956,13 @@ struct VM {
79567956

79577957
/**
79587958
* @brief Check if a call to NtQuerySystemInformation with the 0x9f leaf fills a _SYSTEM_HYPERVISOR_DETAIL_INFORMATION structure
7959-
* @category Windows
7960-
* @implements VM::HYPERV_QUERY
7959+
* @category Windows, x86_64
7960+
* @implements VM::HYPERVISOR_QUERY
79617961
*/
7962-
[[nodiscard]] static bool hyperv_query() {
7962+
[[nodiscard]] static bool hypervisor_query() {
7963+
#if (x86_32)
7964+
return false;
7965+
#else
79637966
if (util::hyper_x() == HYPERV_ARTIFACT_VM) {
79647967
return false;
79657968
}
@@ -8006,7 +8009,7 @@ struct VM {
80068009
return true;
80078010
}
80088011
}
8009-
8012+
#endif
80108013
return false;
80118014
}
80128015

@@ -8474,7 +8477,7 @@ struct VM {
84748477

84758478
pNtFlushInstructionCache(hCurrentProcess, execMem, trampSize);
84768479

8477-
int hitCount = 0;
8480+
u8 hitCount = 0;
84788481

84798482
CONTEXT origCtx{};
84808483
origCtx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
@@ -8499,7 +8502,7 @@ struct VM {
84998502
return false;
85008503
}
85018504

8502-
auto vetExceptions = [&](u32 code, EXCEPTION_POINTERS* info) -> int {
8505+
auto vetExceptions = [&](u32 code, EXCEPTION_POINTERS* info) -> u8 {
85038506
// if not single-step, hypervisor likely swatted our trap
85048507
if (code != static_cast<DWORD>(0x80000004L)) {
85058508
hypervisorCaught = true;
@@ -9269,9 +9272,9 @@ struct VM {
92699272
const u16 word = static_cast<u16>((edid[8] << 8) | edid[9]);
92709273

92719274
char m[4] = { 0, 0, 0, 0 };
9272-
const int c1 = (word >> 10) & 0x1F;
9273-
const int c2 = (word >> 5) & 0x1F;
9274-
const int c3 = (word >> 0) & 0x1F;
9275+
const u8 c1 = static_cast<u8>((word >> 10) & 0x1F);
9276+
const u8 c2 = static_cast<u8>((word >> 5) & 0x1F);
9277+
const u8 c3 = static_cast<u8>((word >> 0) & 0x1F);
92759278

92769279
if (c1 >= 1 && c1 <= 26) m[0] = static_cast<char>('A' + c1 - 1); else m[0] = '?';
92779280
if (c2 >= 1 && c2 <= 26) m[1] = static_cast<char>('A' + c2 - 1); else m[1] = '?';
@@ -9546,7 +9549,7 @@ struct VM {
95469549

95479550
const std::uintptr_t paddr = reinterpret_cast<std::uintptr_t>(amd_target_mem); // to avoid sign-extension, 32-bit compatible
95489551
const u64 addr = static_cast<u64>(paddr);
9549-
for (int i = 0; i < 8; ++i) {
9552+
for (u8 i = 0; i < 8; ++i) {
95509553
amd_bytes[2 + i] = static_cast<u8>((addr >> (i * 8)) & 0xFF);
95519554
}
95529555
bytes = amd_bytes;
@@ -9571,8 +9574,8 @@ struct VM {
95719574
pNtFlushInstructionCache(hCurrentProcess, exec_mem, codeSize);
95729575

95739576
using CodeFunc = void(*)();
9574-
using RunnerFn = int(*)(CodeFunc);
9575-
RunnerFn runner = +[](CodeFunc func) -> int {
9577+
using RunnerFn = u8(*)(CodeFunc);
9578+
RunnerFn runner = +[](CodeFunc func) -> u8 {
95769579
__try {
95779580
func();
95789581
return 0;
@@ -9582,7 +9585,7 @@ struct VM {
95829585
}
95839586
};
95849587

9585-
const int runner_rc = runner(reinterpret_cast<CodeFunc>(exec_mem));
9588+
const u8 runner_rc = runner(reinterpret_cast<CodeFunc>(exec_mem));
95869589

95879590
// check if the target buffer was written to zero by CLZERO
95889591
bool memory_all_zero = false;
@@ -10793,7 +10796,7 @@ struct VM {
1079310796
case DEVICE_HANDLES: return "DEVICE_HANDLES";
1079410797
case QEMU_FW_CFG: return "QEMU_FW_CFG";
1079510798
case VIRTUAL_PROCESSORS: return "VIRTUAL_PROCESSORS";
10796-
case HYPERV_QUERY: return "HYPERV_QUERY";
10799+
case HYPERVISOR_QUERY: return "HYPERVISOR_QUERY";
1079710800
case AMD_SEV: return "AMD_SEV";
1079810801
case VIRTUAL_REGISTRY: return "VIRTUAL_REGISTRY";
1079910802
case FIRMWARE: return "FIRMWARE";
@@ -11365,7 +11368,7 @@ std::pair<VM::enum_flags, VM::core::technique> VM::core::technique_list[] = {
1136511368
std::make_pair(VM::DEVICE_HANDLES, VM::core::technique(100, VM::device_handles)),
1136611369
std::make_pair(VM::VIRTUAL_PROCESSORS, VM::core::technique(100, VM::virtual_processors)),
1136711370
std::make_pair(VM::OBJECTS, VM::core::technique(100, VM::objects)),
11368-
std::make_pair(VM::HYPERV_QUERY, VM::core::technique(100, VM::hyperv_query)),
11371+
std::make_pair(VM::HYPERVISOR_QUERY, VM::core::technique(100, VM::hypervisor_query)),
1136911372
std::make_pair(VM::AUDIO, VM::core::technique(25, VM::audio)),
1137011373
std::make_pair(VM::DISPLAY, VM::core::technique(35, VM::display)),
1137111374
std::make_pair(VM::WINE, VM::core::technique(100, VM::wine)),

0 commit comments

Comments
 (0)