21#define PAGE_4KB_OFFSET ((UINT64)(1 << 12) - 1)
22#define PAGE_2MB_OFFSET ((UINT64)(1 << 21) - 1)
23#define PAGE_4MB_OFFSET ((UINT64)(1 << 22) - 1)
24#define PAGE_1GB_OFFSET ((UINT64)(1 << 30) - 1)
149 _Inout_ PVOID BufferToSaveMemory,
150 _In_ SIZE_T SizeToRead,
157 _In_ PHYSICAL_ADDRESS PaAddressToWrite,
158 _In_ SIZE_T SizeToWrite,
159 _Inout_
UINT64 PteVaAddress,
166 _In_
UINT64 AddressToRead);
171 _In_
UINT64 AddressToRead,
172 _Inout_
UINT64 BufferToSaveMemory,
173 _In_ SIZE_T SizeToRead);
177 _In_
UINT64 DestinationAddr,
179 _In_opt_
UINT32 TargetProcessId);
183 _Inout_
UINT64 DestinationAddr,
185 _In_ SIZE_T SizeToWrite,
187 _In_opt_
UINT32 TargetProcessId);
205 _In_ PVOID TargetProcessVirtualAddress,
206 _In_
CR3_TYPE TargetProcessKernelCr3);
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define VOID
Definition BasicTypes.h:33
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned __int64 * PUINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
enum _PAGING_LEVEL PAGING_LEVEL
Different levels of paging.
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafeByPte(PHYSICAL_ADDRESS PaAddressToRead, PVOID BufferToSaveMemory, SIZE_T SizeToRead, UINT64 PteVaAddress, UINT64 MappingVa, BOOLEAN InvalidateVpids)
Read memory safely by mapping the buffer using PTE.
Definition MemoryMapper.c:761
_Use_decl_annotations_ UINT64 MemoryMapperGetIndex(PAGING_LEVEL Level, UINT64 Va)
Get Index of VA on PMLx.
Definition MemoryMapper.c:25
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafeByPhysicalAddressWrapper(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ TypeOfRead, UINT64 AddressToRead, UINT64 BufferToSaveMemory, SIZE_T SizeToRead)
Wrapper to read the memory safely by mapping the buffer by physical address (It's a wrapper)
Definition MemoryMapper.c:971
_Use_decl_annotations_ UINT64 MemoryMapperWriteMemorySafeWrapperAddressMaker(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_WRITE TypeOfWrite, UINT64 DestinationAddr, PCR3_TYPE TargetProcessCr3, UINT32 TargetProcessId)
Decides about making the address and converting the address to physical address based on the passed p...
Definition MemoryMapper.c:1212
_Use_decl_annotations_ PVOID MemoryMapperMapPageAndGetPte(PUINT64 PteAddress)
This function MAPs one resreved page (4096) and returns its virtual adrresss and also PTE virtual add...
Definition MemoryMapper.c:633
_Use_decl_annotations_ UINT64 MemoryMapperReadMemorySafeByPhysicalAddressWrapperAddressMaker(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ TypeOfRead, UINT64 AddressToRead)
Wrapper to read the memory safely by mapping the buffer by physical address (It's a wrapper)
Definition MemoryMapper.c:929
_Use_decl_annotations_ BOOLEAN MemoryMapperCheckIfPageIsNxBitSetByCr3(PVOID Va, CR3_TYPE TargetCr3)
This function checks if the page has NX bit or not.
Definition MemoryMapper.c:446
_Use_decl_annotations_ PVOID MemoryMapperGetPte(PVOID VirtualAddress)
This function gets virtual address and returns its PTE (Pml4e) virtual address.
Definition MemoryMapper.c:604
_Use_decl_annotations_ PVOID MemoryMapperGetPteByCr3(PVOID VirtualAddress, CR3_TYPE TargetCr3)
This function gets virtual address and returns its PTE (Pml4e) virtual address based on a specific Cr...
Definition MemoryMapper.c:619
_Use_decl_annotations_ VOID MemoryMapperUnmapReservedPageRange(PVOID VirtualAddress)
This function frees the memory that was previously allocated from system range (without physically al...
Definition MemoryMapper.c:591
_Use_decl_annotations_ PVOID MemoryMapperMapReservedPageRange(SIZE_T Size)
This function reserve memory from system range (without physically allocating them)
Definition MemoryMapper.c:573
_Use_decl_annotations_ BOOLEAN MemoryMapperWriteMemorySafeByPte(PVOID SourceVA, PHYSICAL_ADDRESS PaAddressToWrite, SIZE_T SizeToWrite, UINT64 PteVaAddress, UINT64 MappingVa, BOOLEAN InvalidateVpids)
Write memory safely by mapping the buffer using PTE.
Definition MemoryMapper.c:848
_Use_decl_annotations_ BOOLEAN MemoryMapperWriteMemorySafeWrapper(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_WRITE TypeOfWrite, UINT64 DestinationAddr, UINT64 Source, SIZE_T SizeToWrite, PCR3_TYPE TargetProcessCr3, UINT32 TargetProcessId)
Write memory safely by mapping the buffer (It's a wrapper)
Definition MemoryMapper.c:1276
_Use_decl_annotations_ UINT32 MemoryMapperGetOffset(PAGING_LEVEL Level, UINT64 Va)
Get page offset.
Definition MemoryMapper.c:42
enum _MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ
Memory wrapper for reading safe from the memory.
struct _MEMORY_MAPPER_ADDRESSES * PMEMORY_MAPPER_ADDRESSES
VOID MemoryMapperMapPhysicalAddressToPte(_In_ PHYSICAL_ADDRESS PhysicalAddress, _In_ PVOID TargetProcessVirtualAddress, _In_ CR3_TYPE TargetProcessKernelCr3)
VOID MemoryMapperUninitialize()
uninitialize the Memory Mapper
Definition MemoryMapper.c:716
VOID MemoryMapperInitialize()
Initialize the Memory Mapper.
Definition MemoryMapper.c:661
_MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ
Memory wrapper for reading safe from the memory.
Definition MemoryMapper.h:35
@ MEMORY_MAPPER_WRAPPER_READ_VIRTUAL_MEMORY
Definition MemoryMapper.h:37
@ MEMORY_MAPPER_WRAPPER_READ_PHYSICAL_MEMORY
Definition MemoryMapper.h:36
struct _PAGE_ENTRY PAGE_ENTRY
Page Entries.
struct _MEMORY_MAPPER_ADDRESSES MEMORY_MAPPER_ADDRESSES
Memory mapper PTE and reserved virtual address.
struct _PAGE_ENTRY * PPAGE_ENTRY
enum _MEMORY_MAPPER_WRAPPER_FOR_MEMORY_WRITE MEMORY_MAPPER_WRAPPER_FOR_MEMORY_WRITE
Memory wrapper for writing safe into the memory.
BOOLEAN MemoryMapperCheckIfPageIsPresentByCr3(_In_ PVOID Va, _In_ CR3_TYPE TargetCr3)
_MEMORY_MAPPER_WRAPPER_FOR_MEMORY_WRITE
Memory wrapper for writing safe into the memory.
Definition MemoryMapper.h:45
@ MEMORY_MAPPER_WRAPPER_WRITE_VIRTUAL_MEMORY_SAFE
Definition MemoryMapper.h:47
@ MEMORY_MAPPER_WRAPPER_WRITE_PHYSICAL_MEMORY
Definition MemoryMapper.h:46
@ MEMORY_MAPPER_WRAPPER_WRITE_VIRTUAL_MEMORY_UNSAFE
Definition MemoryMapper.h:48
CR3 Structure.
Definition BasicTypes.h:130
Memory mapper PTE and reserved virtual address.
Definition MemoryMapper.h:103
UINT64 PteVirtualAddressForRead
Definition MemoryMapper.h:104
UINT64 VirualAddressForRead
Definition MemoryMapper.h:105
UINT64 VirualAddressForWrite
Definition MemoryMapper.h:108
UINT64 PteVirtualAddressForWrite
Definition MemoryMapper.h:107
Page Entries.
Definition MemoryMapper.h:61
UINT64 Write
Definition MemoryMapper.h:80
UINT64 Dirty
Definition MemoryMapper.h:85
UINT64 LargePage
Definition MemoryMapper.h:86
struct _PAGE_ENTRY::@2::@4 Fields
UINT64 Ignored1
Definition MemoryMapper.h:88
UINT64 ExecuteDisable
Definition MemoryMapper.h:93
UINT64 Present
Definition MemoryMapper.h:79
UINT64 ProtectionKey
Definition MemoryMapper.h:92
UINT64 Global
Definition MemoryMapper.h:87
PDE_2MB_64 PdLarge
Definition MemoryMapper.h:69
PML4E_64 Pml4
Definition MemoryMapper.h:66
PDPTE_1GB_64 PdptLarge
Definition MemoryMapper.h:67
UINT64 PageLevelCacheDisable
Definition MemoryMapper.h:83
UINT64 PageFrameNumber
Definition MemoryMapper.h:89
PTE_64 Pt
Definition MemoryMapper.h:71
UINT64 PageLevelWriteThrough
Definition MemoryMapper.h:82
PDPTE_64 Pdpt
Definition MemoryMapper.h:68
UINT64 Supervisor
Definition MemoryMapper.h:81
UINT64 Flags
Definition MemoryMapper.h:64
PDE_64 Pd
Definition MemoryMapper.h:70
UINT64 Ignored2
Definition MemoryMapper.h:91
UINT64 Accessed
Definition MemoryMapper.h:84
UINT64 Reserved1
Definition MemoryMapper.h:90