HyperDbg Debugger
Loading...
Searching...
No Matches
Ept.h
Go to the documentation of this file.
1
12#pragma once
13
15// Constants //
17
22#define PAGE_ATTRIB_READ 0x2
23#define PAGE_ATTRIB_WRITE 0x4
24#define PAGE_ATTRIB_EXEC 0x8
25#define PAGE_ATTRIB_EXEC_HIDDEN_HOOK 0x10
26
31#define SIZE_2_MB ((SIZE_T)(512 * PAGE_SIZE))
32
37#define SIZE_1_GB ((SIZE_T)(512 * SIZE_2_MB))
38
43#define SIZE_512_GB ((SIZE_T)(512 * SIZE_1_GB))
44
49#define ADDRMASK_EPT_PML1_OFFSET(_VAR_) ((_VAR_) & 0xFFFULL)
50
55#define ADDRMASK_EPT_PML1_INDEX(_VAR_) (((_VAR_) & 0x1FF000ULL) >> 12)
56
61#define ADDRMASK_EPT_PML2_INDEX(_VAR_) (((_VAR_) & 0x3FE00000ULL) >> 21)
62
67#define ADDRMASK_EPT_PML3_INDEX(_VAR_) (((_VAR_) & 0x7FC0000000ULL) >> 30)
68
73#define ADDRMASK_EPT_PML4_INDEX(_VAR_) (((_VAR_) & 0xFF8000000000ULL) >> 39)
74
76// Structs Cont. //
78
90
103
108#define MAX_VARIABLE_RANGE_MTRRS 255
109
116#define NUM_FIXED_RANGE_MTRRS ((1 + 2 + 8) * RTL_NUMBER_OF_FIELD(IA32_MTRR_FIXED_RANGE_TYPE, s.Types)) // = 88
117
122#define NUM_MTRR_ENTRIES (MAX_VARIABLE_RANGE_MTRRS + NUM_FIXED_RANGE_MTRRS) // = 343
123
128typedef struct _EPT_STATE
129{
130 LIST_ENTRY HookedPagesList; // A list of the details about hooked pages
131 MTRR_RANGE_DESCRIPTOR MemoryRanges[NUM_MTRR_ENTRIES]; // Physical memory ranges described by the BIOS in the MTRRs. Used to build the EPT identity mapping.
132 UINT32 NumberOfEnabledMemoryRanges; // Number of memory ranges specified in MemoryRanges
135
166
168// Functions //
170
171// ----------------------------------------------------------------------------
172// Private Interfaces
173//
174
176EptSetupPML2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, PEPT_PML2_ENTRY NewEntry, SIZE_T PageFrameNumber);
177
180 _In_ VMX_EXIT_QUALIFICATION_EPT_VIOLATION ViolationQualification,
181 _In_ UINT64 GuestPhysicalAddr);
182
183// ----------------------------------------------------------------------------
184// Public Interfaces
185//
186
193EptCheckFeatures(VOID);
194
201EptBuildMtrrMap(VOID);
202
210
221 BOOLEAN UsePreAllocatedBuffer,
222 SIZE_T PhysicalAddress);
223
234EptGetPml2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress);
235
243
253
262EptGetPml1Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress);
263
274PVOID
275EptGetPml1OrPml2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress, BOOLEAN * IsLargePage);
276
282VOID
284
294VOID
296 _Out_ PEPT_PML1_ENTRY EntryAddress,
297 _In_ EPT_PML1_ENTRY EntryValue,
298 _In_ _Strict_type_match_ INVEPT_TYPE InvalidationType);
299
PEPT_PML2_ENTRY EptGetPml2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress)
Split 2MB (LargePage) into 4kb pages.
Definition Ept.c:450
VOID EptSetPML1AndInvalidateTLB(_Inout_ VIRTUAL_MACHINE_STATE *VCpu, _Out_ PEPT_PML1_ENTRY EntryAddress, _In_ EPT_PML1_ENTRY EntryValue, _In_ _Strict_type_match_ INVEPT_TYPE InvalidationType)
This function set the specific PML1 entry in a spinlock protected area then invalidate the TLB ,...
BOOLEAN EptLogicalProcessorInitialize(VOID)
Initialize EPT Table based on Processor Index.
Definition Ept.c:865
struct _VMM_EPT_DYNAMIC_SPLIT * PVMM_EPT_DYNAMIC_SPLIT
struct _MTRR_RANGE_DESCRIPTOR * PMTRR_RANGE_DESCRIPTOR
union _IA32_MTRR_FIXED_RANGE_TYPE IA32_MTRR_FIXED_RANGE_TYPE
Fixed range MTRR.
BOOLEAN EptSetupPML2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, PEPT_PML2_ENTRY NewEntry, SIZE_T PageFrameNumber)
Set up PML2 Entries.
Definition Ept.c:655
BOOLEAN EptHandlePageHookExit(_Inout_ VIRTUAL_MACHINE_STATE *VCpu, _In_ VMX_EXIT_QUALIFICATION_EPT_VIOLATION ViolationQualification, _In_ UINT64 GuestPhysicalAddr)
struct _EPT_STATE * PEPT_STATE
struct _MTRR_RANGE_DESCRIPTOR MTRR_RANGE_DESCRIPTOR
MTRR Descriptor.
BOOLEAN EptBuildMtrrMap(VOID)
Build MTRR Map.
Definition Ept.c:167
BOOLEAN EptCheckFeatures(VOID)
Check for EPT Features.
Definition Ept.c:22
PVMM_EPT_PAGE_TABLE EptAllocateAndCreateIdentityPageTable(VOID)
Allocates page maps and create identity page table.
Definition Ept.c:687
BOOLEAN EptCheckAndHandleBreakpoint(VIRTUAL_MACHINE_STATE *VCpu)
Check if the breakpoint vm-exit relates to EPT hook or not.
Definition Ept.c:1317
BOOLEAN EptHandleEptViolation(VIRTUAL_MACHINE_STATE *VCpu)
Handle EPT Violation.
Definition Ept.c:1108
PVOID EptGetPml1OrPml2Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress, BOOLEAN *IsLargePage)
Get the PML1 entry for this physical address if the large page is available then large page of Pml2 i...
Definition Ept.c:394
#define NUM_MTRR_ENTRIES
Total number of MTRR descriptors to store.
Definition Ept.h:122
PEPT_PML1_ENTRY EptGetPml1Entry(PVMM_EPT_PAGE_TABLE EptPageTable, SIZE_T PhysicalAddress)
Get the PML1 Entry of a special address.
Definition Ept.c:337
struct _EPT_STATE EPT_STATE
Main structure for saving the state of EPT among the project.
BOOLEAN EptSplitLargePage(PVMM_EPT_PAGE_TABLE EptPageTable, BOOLEAN UsePreAllocatedBuffer, SIZE_T PhysicalAddress)
Convert large pages to 4KB pages.
Definition Ept.c:481
struct _VMM_EPT_DYNAMIC_SPLIT VMM_EPT_DYNAMIC_SPLIT
Split 2MB granularity to 4 KB granularity.
VOID EptHandleMisconfiguration(VOID)
Handle Ept Misconfigurations.
Definition Ept.c:1152
UCHAR BOOLEAN
Definition BasicTypes.h:35
void * PVOID
Definition BasicTypes.h:56
unsigned char UCHAR
Definition BasicTypes.h:34
unsigned char UINT8
Definition BasicTypes.h:52
unsigned int UINT32
Definition BasicTypes.h:54
EPT_PTE * PEPT_PML1_ENTRY
Definition State.h:23
EPT_PDE_2MB * PEPT_PML2_ENTRY
Definition State.h:21
EPT_PTE EPT_PML1_ENTRY
Definition State.h:23
struct _VMM_EPT_PAGE_TABLE * PVMM_EPT_PAGE_TABLE
#define VMM_EPT_PML1E_COUNT
Then number of 4096 byte Page Table entries in the page table per 2MB PML2 entry when dynamically spl...
Definition State.h:99
struct _VIRTUAL_MACHINE_STATE VIRTUAL_MACHINE_STATE
The status of each core after and before VMX.
EPT_PDE * PEPT_PML2_POINTER
Definition State.h:22
#define PAGE_SIZE
Size of each page (4096 bytes).
Definition common.h:80
Main structure for saving the state of EPT among the project.
Definition Ept.h:129
UINT32 NumberOfEnabledMemoryRanges
Definition Ept.h:132
UINT8 DefaultMemoryType
Definition Ept.h:133
LIST_ENTRY HookedPagesList
Definition Ept.h:130
MTRR_RANGE_DESCRIPTOR MemoryRanges[NUM_MTRR_ENTRIES]
Definition Ept.h:131
MTRR Descriptor.
Definition Ept.h:84
UCHAR MemoryType
Definition Ept.h:87
BOOLEAN FixedRange
Definition Ept.h:88
SIZE_T PhysicalBaseAddress
Definition Ept.h:85
SIZE_T PhysicalEndAddress
Definition Ept.h:86
Split 2MB granularity to 4 KB granularity.
Definition Ept.h:141
LIST_ENTRY DynamicSplitList
Linked list entries for each dynamic split.
Definition Ept.h:163
PEPT_PML2_POINTER Pointer
Definition Ept.h:156
EPT_PML1_ENTRY PML1[VMM_EPT_PML1E_COUNT]
The 4096 byte page table entries that correspond to the split 2MB table entry.
Definition Ept.h:147
PEPT_PML2_ENTRY Entry
Definition Ept.h:155
union _VMM_EPT_DYNAMIC_SPLIT::@275337017054050120003261225167376117025061264241 Fields
The pointer to the 2MB entry in the page table which this split is servicing.
Fixed range MTRR.
Definition Ept.h:96
UINT8 Types[8]
Definition Ept.h:100
UINT64 AsUInt
Definition Ept.h:97
struct _IA32_MTRR_FIXED_RANGE_TYPE::@170207037044173377154145111113263372336161202124 s