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}
#define NULL64_ZERO
Definition BasicTypes.h:52
UCHAR VmxVmwrite64(size_t Field, UINT64 FieldValue)
VMX VMWRITE instruction (64-bit)
Definition Vmx.c:122

◆ 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}
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
GUEST_REGS * Regs
Definition State.h:305
Definition BasicTypes.h:70
UINT64 rax
Definition BasicTypes.h:75
UINT64 rcx
Definition BasicTypes.h:76
UINT64 rdx
Definition BasicTypes.h:77

◆ 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 = __rdtsc();
30 PGUEST_REGS GuestRegs = VCpu->Regs;
31
32 GuestRegs->rax = 0x00000000ffffffff & Tsc;
33 GuestRegs->rdx = 0x00000000ffffffff & (Tsc >> 32);
34}

◆ 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 = __rdtscp(&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}

◆ 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}