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)
151 _Inout_
PVOID BufferToSaveMemory,
152 _In_ SIZE_T SizeToRead,
153 _In_ UINT64 PteVaAddress,
154 _In_ UINT64 MappingVa,
159 _In_ PHYSICAL_ADDRESS PaAddressToWrite,
160 _In_ SIZE_T SizeToWrite,
161 _Inout_ UINT64 PteVaAddress,
162 _Inout_ UINT64 MappingVa,
168 _In_ UINT64 AddressToRead,
169 _In_
UINT32 TargetProcessId);
174 _In_ UINT64 AddressToRead,
175 _Inout_ UINT64 BufferToSaveMemory,
176 _In_ SIZE_T SizeToRead,
177 _In_
UINT32 TargetProcessId);
181 _In_ UINT64 DestinationAddr,
183 _In_opt_
UINT32 TargetProcessId);
187 _Inout_ UINT64 DestinationAddr,
189 _In_ SIZE_T SizeToWrite,
191 _In_opt_
UINT32 TargetProcessId);
209 _In_
PVOID TargetProcessVirtualAddress,
210 _In_
CR3_TYPE TargetProcessKernelCr3);
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafeWrapper(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ TypeOfRead, UINT64 AddressToRead, UINT64 BufferToSaveMemory, SIZE_T SizeToRead, UINT32 TargetProcessId)
Wrapper to read the memory safely by mapping the buffer by physical address (It's a wrapper).
Definition MemoryMapper.c:989
_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_ UINT64 MemoryMapperReadMemorySafeByPhysicalAddressWrapperAddressMaker(MEMORY_MAPPER_WRAPPER_FOR_MEMORY_READ TypeOfRead, UINT64 AddressToRead, UINT32 TargetProcessId)
Wrapper to read the memory safely by mapping the buffer by physical address (It's a wrapper).
Definition MemoryMapper.c:931
_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:1257
_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_ 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:1321
_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_VIRTUAL_MEMORY_UNSAFE
Definition MemoryMapper.h:38
@ 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:47
@ MEMORY_MAPPER_WRAPPER_WRITE_VIRTUAL_MEMORY_SAFE
Definition MemoryMapper.h:49
@ MEMORY_MAPPER_WRAPPER_WRITE_PHYSICAL_MEMORY
Definition MemoryMapper.h:48
@ MEMORY_MAPPER_WRAPPER_WRITE_VIRTUAL_MEMORY_UNSAFE
Definition MemoryMapper.h:50
Memory mapper PTE and reserved virtual address.
Definition MemoryMapper.h:105
UINT64 PteVirtualAddressForRead
Definition MemoryMapper.h:106
UINT64 VirualAddressForRead
Definition MemoryMapper.h:107
UINT64 VirualAddressForWrite
Definition MemoryMapper.h:110
UINT64 PteVirtualAddressForWrite
Definition MemoryMapper.h:109
Page Entries.
Definition MemoryMapper.h:63
UINT64 Write
Definition MemoryMapper.h:82
UINT64 Dirty
Definition MemoryMapper.h:87
UINT64 LargePage
Definition MemoryMapper.h:88
UINT64 Ignored1
Definition MemoryMapper.h:90
UINT64 ExecuteDisable
Definition MemoryMapper.h:95
UINT64 Present
Definition MemoryMapper.h:81
UINT64 ProtectionKey
Definition MemoryMapper.h:94
UINT64 Global
Definition MemoryMapper.h:89
struct _PAGE_ENTRY::@376376202121063303120064260270315140365371076130::@103064255274005116234107103217043340214273361203 Fields
PDE_2MB_64 PdLarge
Definition MemoryMapper.h:71
PML4E_64 Pml4
Definition MemoryMapper.h:68
PDPTE_1GB_64 PdptLarge
Definition MemoryMapper.h:69
UINT64 PageLevelCacheDisable
Definition MemoryMapper.h:85
UINT64 PageFrameNumber
Definition MemoryMapper.h:91
PTE_64 Pt
Definition MemoryMapper.h:73
UINT64 PageLevelWriteThrough
Definition MemoryMapper.h:84
PDPTE_64 Pdpt
Definition MemoryMapper.h:70
UINT64 Supervisor
Definition MemoryMapper.h:83
UINT64 Flags
Definition MemoryMapper.h:66
PDE_64 Pd
Definition MemoryMapper.h:72
UINT64 Ignored2
Definition MemoryMapper.h:93
UINT64 Accessed
Definition MemoryMapper.h:86
UINT64 Reserved1
Definition MemoryMapper.h:92