1
0
mirror of https://github.com/momo5502/hypervisor.git synced 2025-07-04 10:11:51 +00:00

Prepare ept hooking

This commit is contained in:
momo5502
2022-04-12 20:05:51 +02:00
parent c7e29af2b5
commit dfa1172f34
9 changed files with 84 additions and 13 deletions

View File

@ -1,4 +1,5 @@
#pragma once
#include "type_traits.hpp"
namespace memory
{
@ -12,12 +13,6 @@ namespace memory
_Must_inspect_result_
_IRQL_requires_max_(DISPATCH_LEVEL)
template <typename T>
T* allocate_aligned_object()
{
return static_cast<T*>(allocate_aligned_memory(sizeof(T)));
}
uint64_t get_physical_address(void* address);
void* get_virtual_address(uint64_t address);
@ -29,4 +24,26 @@ namespace memory
void free_non_paged_memory(void* memory);
uint64_t query_process_physical_page(uint32_t process_id, void* address, uint8_t buffer[PAGE_SIZE]);
template <typename T, typename... Args>
T* allocate_aligned_object(Args ... args)
{
auto* object = static_cast<T*>(allocate_aligned_memory(sizeof(T)));
if (object)
{
new(object) T(std::forward<Args>(args)...);
}
return object;
}
template <typename T>
void free_aligned_object(T* object)
{
if (object)
{
object->~T();
free_aligned_memory(object);
}
}
}