diff --git a/src/driver/ept.cpp b/src/driver/ept.cpp index 6e8f25a..689632d 100644 --- a/src/driver/ept.cpp +++ b/src/driver/ept.cpp @@ -277,16 +277,6 @@ namespace vmx void ept::install_hook(PVOID TargetFunction, PVOID HookFunction, PVOID* OrigFunction) { - /* - ept_hook* NewHook; - EPT_PML1_ENTRY FakeEntry; - EPT_PML1_ENTRY OriginalEntry; - INVEPT_DESCRIPTOR Descriptor; - */ - /* Translate the page from a physical address to virtual so we can read its memory. - * This function will return NULL if the physical address was not already mapped in - * virtual memory. - */ const auto VirtualTarget = PAGE_ALIGN(TargetFunction); const auto PhysicalAddress = memory::get_physical_address(VirtualTarget); @@ -376,7 +366,7 @@ namespace vmx }*/ } - void ept::handle_violation(guest_context& guest_context) + void ept::handle_violation(guest_context& guest_context) const { vmx_exit_qualification_ept_violation violation_qualification{}; violation_qualification.flags = guest_context.exit_qualification; @@ -499,7 +489,12 @@ namespace vmx } const auto* pml2 = reinterpret_cast(pml2_entry); - const auto pml1 = static_cast(memory::get_virtual_address(pml2->page_frame_number * PAGE_SIZE)); + auto* pml1 = static_cast(memory::get_virtual_address(pml2->page_frame_number * PAGE_SIZE)); + if (!pml1) + { + pml1 = this->find_pml1_table(pml2->page_frame_number * PAGE_SIZE); + } + if (!pml1) { return nullptr; @@ -508,6 +503,22 @@ namespace vmx return &pml1[ADDRMASK_EPT_PML1_INDEX(physical_address)]; } + pml1* ept::find_pml1_table(const uint64_t physical_address) const + { + auto* split = this->ept_splits; + while (split) + { + if (memory::get_physical_address(&split->pml1[0]) == physical_address) + { + return split->pml1; + } + + split = split->next_split; + } + + return nullptr; + } + ept_split* ept::allocate_ept_split() { auto* split = memory::allocate_aligned_object(); diff --git a/src/driver/ept.hpp b/src/driver/ept.hpp index 7c71dfd..c130a15 100644 --- a/src/driver/ept.hpp +++ b/src/driver/ept.hpp @@ -55,7 +55,7 @@ namespace vmx void initialize(); void install_hook(PVOID TargetFunction, PVOID HookFunction, PVOID* OrigFunction); - void handle_violation(guest_context& guest_context); + void handle_violation(guest_context& guest_context) const; pml4* get_pml4(); const pml4* get_pml4() const; @@ -70,6 +70,7 @@ namespace vmx pml2* get_pml2_entry(uint64_t physical_address); pml1* get_pml1_entry(uint64_t physical_address); + pml1* find_pml1_table(uint64_t physical_address) const; ept_split* allocate_ept_split(); ept_hook* allocate_ept_hook();