Functions for address checks.
More...
#include "pch.h"
Functions for address checks.
Functions for memory conversions.
- Author
- Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
- Version
- 0.2
- Date
- 2023-04-27
- Copyright
- This project is released under the GNU Public License v3.
◆ PhysicalAddressToVirtualAddress()
_Use_decl_annotations_ UINT64 PhysicalAddressToVirtualAddress |
( |
UINT64 | PhysicalAddress | ) |
|
Converts Physical Address to Virtual Address.
- Parameters
-
PhysicalAddress | The target physical address |
- Returns
- UINT64 Returns the virtual address
23{
24 PHYSICAL_ADDRESS PhysicalAddr;
25 PhysicalAddr.QuadPart = PhysicalAddress;
26
27 return (
UINT64)MmGetVirtualForPhysical(PhysicalAddr);
28}
unsigned __int64 UINT64
Definition BasicTypes.h:21
◆ PhysicalAddressToVirtualAddressByCr3()
_Use_decl_annotations_ UINT64 PhysicalAddressToVirtualAddressByCr3 |
( |
PVOID | PhysicalAddress, |
|
|
CR3_TYPE | TargetCr3 ) |
Converts Physical Address to Virtual Address based on a specific process's kernel cr3.
this function should NOT be called from vmx-root mode
- Parameters
-
PhysicalAddress | The target physical address |
TargetCr3 | The target's process cr3 |
- Returns
- UINT64 Returns the virtual address
91{
94 PHYSICAL_ADDRESS PhysicalAddr;
95
96
97
98
100
101
102
103
105 {
106
107
108
110 }
111
112
113
114
115 PhysicalAddr.QuadPart = (LONGLONG)PhysicalAddress;
116 VirtualAddress = (
UINT64)MmGetVirtualForPhysical(PhysicalAddr);
117
118
119
120
122
123 return VirtualAddress;
124}
#define NULL64_ZERO
Definition BasicTypes.h:52
_Use_decl_annotations_ VOID SwitchToPreviousProcess(CR3_TYPE PreviousProcess)
Switch to previous process's cr3.
Definition SwitchLayout.c:125
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayoutByCr3(CR3_TYPE TargetCr3)
Switch to another process's cr3.
Definition SwitchLayout.c:99
CR3 Structure.
Definition BasicTypes.h:130
UINT64 Flags
Definition BasicTypes.h:133
◆ PhysicalAddressToVirtualAddressByProcessId()
_Use_decl_annotations_ UINT64 PhysicalAddressToVirtualAddressByProcessId |
( |
PVOID | PhysicalAddress, |
|
|
UINT32 | ProcessId ) |
Converts Physical Address to Virtual Address based on a specific process id.
this function should NOT be called from vmx-root mode
- Parameters
-
PhysicalAddress | The target physical address |
ProcessId | The target's process id |
- Returns
- UINT64 Returns the virtual address
43{
46 PHYSICAL_ADDRESS PhysicalAddr;
47
48
49
50
52
53
54
55
57 {
58
59
60
62 }
63
64
65
66
67 PhysicalAddr.QuadPart = (LONGLONG)PhysicalAddress;
68 VirtualAddress = (
UINT64)MmGetVirtualForPhysical(PhysicalAddr);
69
70
71
72
74
75 return VirtualAddress;
76}
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayout(UINT32 ProcessId)
Switch to another process's cr3.
Definition SwitchLayout.c:25
◆ PhysicalAddressToVirtualAddressOnTargetProcess()
_Use_decl_annotations_ UINT64 PhysicalAddressToVirtualAddressOnTargetProcess |
( |
PVOID | PhysicalAddress | ) |
|
Converts Physical Address to Virtual Address based on current process's kernel cr3.
this function should NOT be called from vmx-root mode
- Parameters
-
PhysicalAddress | The target physical address |
- Returns
- UINT64 Returns the virtual address
138{
140
142
144}
_Use_decl_annotations_ UINT64 PhysicalAddressToVirtualAddressByCr3(PVOID PhysicalAddress, CR3_TYPE TargetCr3)
Converts Physical Address to Virtual Address based on a specific process's kernel cr3.
Definition Conversion.c:90
CR3_TYPE LayoutGetCurrentProcessCr3()
Get cr3 of the target running process.
Definition Layout.c:55
◆ VirtualAddressToPhysicalAddress()
_Use_decl_annotations_ UINT64 VirtualAddressToPhysicalAddress |
( |
_In_ PVOID | VirtualAddress | ) |
|
Converts Virtual Address to Physical Address.
- Parameters
-
VirtualAddress | The target virtual address |
- Returns
- UINT64 Returns the physical address
155{
156 return MmGetPhysicalAddress(VirtualAddress).QuadPart;
157}
◆ VirtualAddressToPhysicalAddressByProcessCr3()
_Use_decl_annotations_ UINT64 VirtualAddressToPhysicalAddressByProcessCr3 |
( |
PVOID | VirtualAddress, |
|
|
CR3_TYPE | TargetCr3 ) |
Converts Virtual Address to Physical Address based on a specific process's kernel cr3.
- Parameters
-
VirtualAddress | The target virtual address |
TargetCr3 | The target's process cr3 |
- Returns
- UINT64 Returns the physical address
216{
219
220
221
222
224
225
226
227
229 {
230
231
232
234 }
235
236
237
238
239 PhysicalAddress = MmGetPhysicalAddress(VirtualAddress).QuadPart;
240
241
242
243
245
246 return PhysicalAddress;
247}
◆ VirtualAddressToPhysicalAddressByProcessId()
_Use_decl_annotations_ UINT64 VirtualAddressToPhysicalAddressByProcessId |
( |
PVOID | VirtualAddress, |
|
|
UINT32 | ProcessId ) |
Converts Virtual Address to Physical Address based on a specific process id's kernel cr3.
this function should NOT be called from vmx-root mode
- Parameters
-
VirtualAddress | The target virtual address |
ProcessId | The target's process id |
- Returns
- UINT64 Returns the physical address
172{
175
176
177
178
180
181
182
183
185 {
186
187
188
190 }
191
192
193
194
195 PhysicalAddress = MmGetPhysicalAddress(VirtualAddress).QuadPart;
196
197
198
199
201
202 return PhysicalAddress;
203}
◆ VirtualAddressToPhysicalAddressOnTargetProcess()
_Use_decl_annotations_ UINT64 VirtualAddressToPhysicalAddressOnTargetProcess |
( |
PVOID | VirtualAddress | ) |
|
Converts Virtual Address to Physical Address based on the current process's kernel cr3.
- Parameters
-
VirtualAddress | The target virtual address |
- Returns
- UINT64 Returns the physical address
259{
263
265
266
267
268
270
271
272
273
275 {
276
277
278
280 }
281
282
283
284
285 PhysicalAddress = MmGetPhysicalAddress(VirtualAddress).QuadPart;
286
287
288
289
291
292 return PhysicalAddress;
293}