HyperDbg Debugger
Loading...
Searching...
No Matches
Counters.h File Reference

The headers for functions for emulating counters. More...

Go to the source code of this file.

Functions

VOID CounterEmulateRdtsc (VIRTUAL_MACHINE_STATE *VCpu)
 Emulate RDTSC.
VOID CounterEmulateRdtscp (VIRTUAL_MACHINE_STATE *VCpu)
 Emulate RDTSCP.
VOID CounterEmulateRdpmc (VIRTUAL_MACHINE_STATE *VCpu)
 Emulate RDPMC.
VOID CounterSetPreemptionTimer (UINT32 TimerValue)
 Set the timer value for preemption timer.
VOID CounterClearPreemptionTimer ()
 Clears the preemption timer.

Detailed Description

The headers for functions for emulating counters.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-06-14

Function Documentation

◆ CounterClearPreemptionTimer()

VOID CounterClearPreemptionTimer ( )

Clears the preemption timer.

Returns
VOID
95{
96 //
97 // Set the time value to NULL
98 //
99 VmxVmwrite64(VMCS_GUEST_VMX_PREEMPTION_TIMER_VALUE, NULL64_ZERO);
100}
UCHAR VmxVmwrite64(size_t Field, UINT64 FieldValue)
VMX VMWRITE instruction (64-bit).
Definition PlatformIntrinsicsVmx.c:273
#define NULL64_ZERO
Definition BasicTypes.h:111

◆ CounterEmulateRdpmc()

VOID CounterEmulateRdpmc ( VIRTUAL_MACHINE_STATE * VCpu)

Emulate RDPMC.

Parameters
VCpuThe virtual processor's state
Returns
VOID
63{
64 UINT32 EcxReg = 0;
65 PGUEST_REGS GuestRegs = VCpu->Regs;
66
67 EcxReg = GuestRegs->rcx & 0xffffffff;
68 UINT64 Pmc = __readpmc(EcxReg);
69 GuestRegs->rax = 0x00000000ffffffff & Pmc;
70 GuestRegs->rdx = 0x00000000ffffffff & (Pmc >> 32);
71}
struct GUEST_REGS * PGUEST_REGS
unsigned int UINT32
Definition BasicTypes.h:54
GUEST_REGS * Regs
Definition State.h:326
UINT64 rax
Definition BasicTypes.h:141
UINT64 rcx
Definition BasicTypes.h:142
UINT64 rdx
Definition BasicTypes.h:143

◆ CounterEmulateRdtsc()

VOID CounterEmulateRdtsc ( VIRTUAL_MACHINE_STATE * VCpu)

Emulate RDTSC.

Parameters
VCpuThe virtual processor's state
Returns
VOID
22{
23 //
24 // I realized that if you log anything here (LogInfo) then
25 // the system-halts, currently don't have any idea of how
26 // to solve it, in the future we solve it using tsc offsetting
27 // or tsc scalling (The reason is because of that fucking patchguard :( )
28 //
29 UINT64 Tsc = CpuReadTsc();
30 PGUEST_REGS GuestRegs = VCpu->Regs;
31
32 GuestRegs->rax = 0x00000000ffffffff & Tsc;
33 GuestRegs->rdx = 0x00000000ffffffff & (Tsc >> 32);
34}
UINT64 CpuReadTsc(VOID)
Read Time-Stamp Counter.
Definition PlatformIntrinsics.c:295

◆ CounterEmulateRdtscp()

VOID CounterEmulateRdtscp ( VIRTUAL_MACHINE_STATE * VCpu)

Emulate RDTSCP.

Parameters
VCpuThe virtual processor's state
Returns
VOID
44{
45 UINT32 Aux = 0;
46 UINT64 Tsc = CpuReadTscp(&Aux);
47 PGUEST_REGS GuestRegs = VCpu->Regs;
48
49 GuestRegs->rax = 0x00000000ffffffff & Tsc;
50 GuestRegs->rdx = 0x00000000ffffffff & (Tsc >> 32);
51
52 GuestRegs->rcx = 0x00000000ffffffff & Aux;
53}
UINT64 CpuReadTscp(UINT32 *Aux)
Read Time-Stamp Counter and Processor ID.
Definition PlatformIntrinsics.c:315

◆ CounterSetPreemptionTimer()

VOID CounterSetPreemptionTimer ( UINT32 TimerValue)

Set the timer value for preemption timer.

Parameters
TimerValueValue of the timer
Returns
VOID
81{
82 //
83 // Set the time value
84 //
85 VmxVmwrite64(VMCS_GUEST_VMX_PREEMPTION_TIMER_VALUE, TimerValue);
86}