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

Header files for protected hypervisor resources. More...

Go to the source code of this file.

Functions

VOID ProtectedHvSetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Set exception bitmap in VMCS.
VOID ProtectedHvUnsetExceptionBitmap (VIRTUAL_MACHINE_STATE *VCpu, UINT32 IdtIndex)
 Unset exception bitmap in VMCS.
VOID ProtectedHvResetExceptionBitmapToClearEvents (VIRTUAL_MACHINE_STATE *VCpu)
 Reset exception bitmap in VMCS because of clearing !exception commands.
VOID ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Reset exception bitmap in VMCS because of clearing !exception commands.
VOID ProtectedHvSetExternalInterruptExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the External Interrupt Exiting.
VOID ProtectedHvExternalInterruptExitingForDisablingInterruptCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !interrupt.
VOID ProtectedHvSetRdtscExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set the RDTSC/P Exiting.
VOID ProtectedHvDisableRdtscExitingForDisablingTscCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !tsc.
VOID ProtectedHvSetMovDebugRegsExiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set MOV to HW Debug Regs Exiting.
VOID ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands (VIRTUAL_MACHINE_STATE *VCpu)
 Clear events of !dr.
VOID ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands (VIRTUAL_MACHINE_STATE *VCpu, UINT64 ControlRegister, UINT64 MaskRegister)
 Clear events of !crwrite.
VOID ProtectedHvSetMov2CrExiting (BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
 Set MOV to CR0/4 Exiting.
VOID ProtectedHvSetMov2Cr3Exiting (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set MOV to CR3 Exiting.
VOID ProtectedHvSetSaveDebugControls (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set LOAD DEBUG CONTROLS on VM-entry controls.
VOID ProtectedHvSetLoadDebugControls (VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set)
 Set SAVE DEBUG CONTROLS on VM-exit controls.

Detailed Description

Header files for protected hypervisor resources.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)

Protected Hypervisor Routines are those resource that are used in different parts of the debugger or hypervisor, these resources need extra checks to avoid integrity problems

Version
0.1
Date
2021-10-04

Function Documentation

◆ ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands()

VOID ProtectedHvDisableMovControlRegsExitingForDisablingCrCommands ( VIRTUAL_MACHINE_STATE * VCpu,
UINT64 ControlRegister,
UINT64 MaskRegister )

Clear events of !crwrite.

Parameters
VCpuThe virtual processor's state
ControlRegister
MaskRegister
Returns
VOID
723{
725}
VOID ProtectedHvSetMovControlRegsVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver, UINT64 ControlRegister, UINT64 MaskRegister)
Set vm-exit for mov to control registers.
Definition ProtectedHv.c:438
#define FALSE
Definition BasicTypes.h:113
@ PASSING_OVER_MOV_TO_CONTROL_REGS_EVENTS
Definition Events.h:321

◆ ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands()

VOID ProtectedHvDisableMovDebugRegsExitingForDisablingDrCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !dr.

Parameters
VCpuThe virtual processor's state
Returns
VOID
709{
711}
VOID ProtectedHvSetMovDebugRegsVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for mov to debug registers.
Definition ProtectedHv.c:341
@ PASSING_OVER_MOV_TO_HW_DEBUG_REGS_EVENTS
Definition Events.h:316

◆ ProtectedHvDisableRdtscExitingForDisablingTscCommands()

VOID ProtectedHvDisableRdtscExitingForDisablingTscCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !tsc.

Parameters
VCpuThe virtual processor's state
Returns
VOID
684{
686}
VOID ProtectedHvSetTscVmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for tsc instructions (rdtsc/rdtscp).
Definition ProtectedHv.c:287
@ PASSING_OVER_TSC_EVENTS
Definition Events.h:311

◆ ProtectedHvExternalInterruptExitingForDisablingInterruptCommands()

VOID ProtectedHvExternalInterruptExitingForDisablingInterruptCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Clear events of !interrupt.

Returns
VOID
271{
273}
VOID ProtectedHvApplySetExternalInterruptExiting(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set the External Interrupt Exiting.
Definition ProtectedHv.c:192
@ PASSING_OVER_INTERRUPT_EVENTS
Definition Events.h:306

◆ ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands()

VOID ProtectedHvRemoveUndefinedInstructionForDisablingSyscallSysretCommands ( VIRTUAL_MACHINE_STATE * VCpu)

Reset exception bitmap in VMCS because of clearing !exception commands.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
Returns
VOID
162{
163 UINT32 ExceptionBitmap = 0;
164
165 //
166 // Read the current bitmap
167 //
168 ExceptionBitmap = HvReadExceptionBitmap();
169
170 //
171 // Unset exception bitmap for #UD
172 //
173 ExceptionBitmap &= ~(1 << EXCEPTION_VECTOR_UNDEFINED_OPCODE);
174
175 //
176 // Set the new value
177 //
179}
UINT32 HvReadExceptionBitmap()
Read exception bitmap in VMCS.
Definition Hv.c:631
VOID ProtectedHvChangeExceptionBitmapWithIntegrityCheck(VIRTUAL_MACHINE_STATE *VCpu, UINT32 CurrentMask, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Add extra mask to this resource and write it.
Definition ProtectedHv.c:31
unsigned int UINT32
Definition BasicTypes.h:54
@ PASSING_OVER_UD_EXCEPTIONS_FOR_SYSCALL_SYSRET_HOOK
Definition Events.h:300
@ EXCEPTION_VECTOR_UNDEFINED_OPCODE
Definition Events.h:30

◆ ProtectedHvResetExceptionBitmapToClearEvents()

VOID ProtectedHvResetExceptionBitmapToClearEvents ( VIRTUAL_MACHINE_STATE * VCpu)

Reset exception bitmap in VMCS because of clearing !exception commands.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
Returns
VOID
143{
144 UINT32 ExceptionBitmap = 0;
145
146 //
147 // Set the new value
148 //
150}
@ PASSING_OVER_EXCEPTION_EVENTS
Definition Events.h:301

◆ ProtectedHvSetExceptionBitmap()

VOID ProtectedHvSetExceptionBitmap ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 IdtIndex )

Set exception bitmap in VMCS.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
IdtIndexInterrupt Descriptor Table index of exception
Returns
VOID
77{
78 UINT32 ExceptionBitmap = 0;
79
80 //
81 // Read the current bitmap
82 //
83 ExceptionBitmap = HvReadExceptionBitmap();
84
86 {
87 ExceptionBitmap = 0xffffffff;
88 }
89 else
90 {
91 ExceptionBitmap |= 1 << IdtIndex;
92 }
93
94 //
95 // Set the new value
96 //
98}
#define DEBUGGER_EVENT_EXCEPTIONS_ALL_FIRST_32_ENTRIES
Apply to all first 32 exceptions.
Definition Constants.h:757
@ PASSING_OVER_NONE
Definition Events.h:299

◆ ProtectedHvSetExternalInterruptExiting()

VOID ProtectedHvSetExternalInterruptExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set the External Interrupt Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the External Interrupt Exiting
Returns
VOID

◆ ProtectedHvSetLoadDebugControls()

VOID ProtectedHvSetLoadDebugControls ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set SAVE DEBUG CONTROLS on VM-exit controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
659{
661}
VOID ProtectedHvSetLoadDebugControlsIntegrityCheck(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set LOAD DEBUG CONTROLS on Vm-entry controls.
Definition ProtectedHv.c:539

◆ ProtectedHvSetMov2Cr3Exiting()

VOID ProtectedHvSetMov2Cr3Exiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set MOV to CR3 Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the MOV to CR3 Exiting
Returns
VOID
736{
738}
VOID ProtectedHvSetMovToCr3Vmexit(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set vm-exit for mov to cr3 register.
Definition ProtectedHv.c:474

◆ ProtectedHvSetMov2CrExiting()

VOID ProtectedHvSetMov2CrExiting ( BOOLEAN Set,
UINT64 ControlRegister,
UINT64 MaskRegister )

Set MOV to CR0/4 Exiting.

Parameters
Setor unset the MOV to CR0/4 Exiting
ControlRegister
MaskRegister
Returns
VOID
750{
751 ProtectedHvSetMovToCrVmexit(Set, ControlRegister, MaskRegister);
752}
VOID ProtectedHvSetMovToCrVmexit(BOOLEAN Set, UINT64 ControlRegister, UINT64 MaskRegister)
Set vm-exit for mov to cr0 / cr4 register.
Definition ProtectedHv.c:395

◆ ProtectedHvSetMovDebugRegsExiting()

VOID ProtectedHvSetMovDebugRegsExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set MOV to HW Debug Regs Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the MOV to HW Debug Regs Exiting
Returns
VOID

◆ ProtectedHvSetRdtscExiting()

VOID ProtectedHvSetRdtscExiting ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set the RDTSC/P Exiting.

Parameters
VCpuThe virtual processor's state
SetSet or unset the RDTSC/P Exiting
Returns
VOID
672{
674}

◆ ProtectedHvSetSaveDebugControls()

VOID ProtectedHvSetSaveDebugControls ( VIRTUAL_MACHINE_STATE * VCpu,
BOOLEAN Set )

Set LOAD DEBUG CONTROLS on VM-entry controls.

Parameters
VCpu
SetSet or unset
Returns
VOID
645{
647}
VOID ProtectedHvSetSaveDebugControlsIntegrityCheck(VIRTUAL_MACHINE_STATE *VCpu, BOOLEAN Set, PROTECTED_HV_RESOURCES_PASSING_OVERS PassOver)
Set SAVE DEBUG CONTROLS on Vm-exit controls.
Definition ProtectedHv.c:592

◆ ProtectedHvUnsetExceptionBitmap()

VOID ProtectedHvUnsetExceptionBitmap ( VIRTUAL_MACHINE_STATE * VCpu,
UINT32 IdtIndex )

Unset exception bitmap in VMCS.

Should be called in vmx-root

Parameters
VCpuThe virtual processor's state
IdtIndexInterrupt Descriptor Table index of exception
Returns
VOID
110{
111 UINT32 ExceptionBitmap = 0;
112
113 //
114 // Read the current bitmap
115 //
116 ExceptionBitmap = HvReadExceptionBitmap();
117
119 {
120 ExceptionBitmap = 0x0;
121 }
122 else
123 {
124 ExceptionBitmap &= ~(1 << IdtIndex);
125 }
126
127 //
128 // Set the new value
129 //
131}