Functions for switching memory layouts.
More...
#include "pch.h"
Functions for switching memory layouts.
- 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.
◆ SwitchToCurrentProcessMemoryLayout()
CR3_TYPE SwitchToCurrentProcessMemoryLayout |
( |
| ) |
|
Switch to guest's running process's cr3.
this function can be called from vmx-root mode
- Returns
- CR3_TYPE The cr3 of current process which can be used by SwitchToPreviousProcess function
71{
74
76
77
78
79
80 CurrentProcessCr3.
Flags = __readcr3();
81
82
83
84
85 __writecr3(GuestCr3.
Flags);
86
87 return CurrentProcessCr3;
88}
CR3_TYPE LayoutGetCurrentProcessCr3()
Get cr3 of the target running process.
Definition Layout.c:55
CR3 Structure.
Definition BasicTypes.h:130
UINT64 Flags
Definition BasicTypes.h:133
◆ SwitchToPreviousProcess()
_Use_decl_annotations_ VOID SwitchToPreviousProcess |
( |
CR3_TYPE | PreviousProcess | ) |
|
Switch to previous process's cr3.
- Parameters
-
PreviousProcess | Cr3 of previous process which is returned by SwitchToProcessMemoryLayout |
- Returns
- VOID
126{
127
128
129
130 __writecr3(PreviousProcess.
Flags);
131}
◆ SwitchToProcessMemoryLayout()
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayout |
( |
UINT32 | ProcessId | ) |
|
Switch to another process's cr3.
this function should NOT be called from vmx-root mode
- Parameters
-
ProcessId | ProcessId to switch |
- Returns
- CR3_TYPE The cr3 of current process which can be used by SwitchToPreviousProcess function
26{
28 PEPROCESS TargetEprocess;
30
31 if (PsLookupProcessByProcessId((HANDLE)ProcessId, &TargetEprocess) != STATUS_SUCCESS)
32 {
33
34
35
36 return CurrentProcessCr3;
37 }
38
39
40
41
42
45
46
47
48
49 CurrentProcessCr3.
Flags = __readcr3();
50
51
52
53
54 __writecr3(GuestCr3);
55
56 ObDereferenceObject(TargetEprocess);
57
58 return CurrentProcessCr3;
59}
unsigned __int64 UINT64
Definition BasicTypes.h:21
KPROCESS Brief structure.
Definition Common.h:265
ULONG_PTR DirectoryTableBase
Definition Common.h:268
◆ SwitchToProcessMemoryLayoutByCr3()
_Use_decl_annotations_ CR3_TYPE SwitchToProcessMemoryLayoutByCr3 |
( |
CR3_TYPE | TargetCr3 | ) |
|
Switch to another process's cr3.
- Parameters
-
- Returns
- CR3_TYPE The cr3 of current process which can be used by SwitchToPreviousProcess function
100{
102
103
104
105
106 CurrentProcessCr3.
Flags = __readcr3();
107
108
109
110
111 __writecr3(TargetCr3.
Flags);
112
113 return CurrentProcessCr3;
114}