mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-21 04:33:56 +00:00
feat: spoof rdtsc timings
Previously, RDTSC in the VM always returned a constant value, which broke any non deterministic timing-based operations, or caused detections in heuristics of malware and ANTI-VM tools. This patch introduces a spoofed rdtsc_fake counter that tracks and adjusts timing deltas to simulate realistic TSC increments. Can be extended to simulate rdtsc timings based on CPU clock speed.
This commit is contained in:
@@ -448,9 +448,25 @@ void windows_emulator::setup_hooks()
|
||||
});
|
||||
|
||||
this->emu().hook_instruction(x64_hookable_instructions::rdtsc, [&] {
|
||||
const auto instructions = this->executed_instructions_;
|
||||
this->emu().reg(x64_register::rax, instructions & 0xFFFFFFFF);
|
||||
this->emu().reg(x64_register::rdx, (instructions >> 32) & 0xFFFFFFFF);
|
||||
uint64_t ticks = this->clock_.get()->timestamp_counter();
|
||||
static uint64_t fake_ticks = ticks;
|
||||
static uint64_t prev_ticks = 0;
|
||||
|
||||
if (prev_ticks != 0)
|
||||
{
|
||||
if (ticks > prev_ticks)
|
||||
{
|
||||
fake_ticks += (ticks - prev_ticks);
|
||||
}
|
||||
}
|
||||
if (fake_ticks > ticks)
|
||||
{
|
||||
fake_ticks = ticks;
|
||||
}
|
||||
prev_ticks = ticks;
|
||||
|
||||
this->emu().reg(x64_register::rax, fake_ticks & 0xFFFFFFFF);
|
||||
this->emu().reg(x64_register::rdx, (fake_ticks >> 32) & 0xFFFFFFFF);
|
||||
return instruction_hook_continuation::skip_instruction;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user