Read process memory.
92{
93 PEPROCESS SourceProcess;
94 MM_COPY_ADDRESS CopyAddress = {0};
95 KAPC_STATE State = {0};
96 PHYSICAL_ADDRESS TempPhysicalAddress = {0};
97
98
99
100
101
102
103
104
105
106
108 {
109
110
111
112
113 if (PsLookupProcessByProcessId(PID, &SourceProcess) != STATUS_SUCCESS)
114 {
115
116
117
119 }
120 __try
121 {
122 KeStackAttachProcess(SourceProcess, &State);
123
124
125
126
127 TempPhysicalAddress = MmGetPhysicalAddress(Address);
128
129 KeUnstackDetachProcess(&State);
130
131
132
133
134 CopyAddress.PhysicalAddress.QuadPart = TempPhysicalAddress.QuadPart;
135 MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_PHYSICAL, ReturnSize);
136
137 ObDereferenceObject(SourceProcess);
138
140 }
141 __except (EXCEPTION_EXECUTE_HANDLER)
142 {
143 KeUnstackDetachProcess(&State);
144
145 ObDereferenceObject(SourceProcess);
146
148 }
149 }
150 else
151 {
152
153
154
155 __try
156 {
158 {
159 CopyAddress.VirtualAddress = Address;
160 MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_VIRTUAL, ReturnSize);
161 }
163 {
164
165
166
168 {
170 }
171
172 CopyAddress.PhysicalAddress.QuadPart = (LONGLONG)Address;
173
174 if (MmCopyMemory(UserBuffer, CopyAddress, Size, MM_COPY_MEMORY_PHYSICAL, ReturnSize) != STATUS_SUCCESS && *ReturnSize == 0)
175 {
176
177
178
179
180
181
182
184 {
185 *ReturnSize = Size;
187 }
188 else
189 {
190
191
192
193 *ReturnSize = 0;
195 }
196 }
197 }
198 else
199 {
200
201
202
204 }
205
206
207
208
209
210
212 }
213 __except (EXCEPTION_EXECUTE_HANDLER)
214 {
216 }
217 }
218}
NTSTATUS AsmVmxVmcall(UINT64 VmcallNumber, UINT64 OptionalParam1, UINT64 OptionalParam2, UINT64 OptionalParam3)
Request Vmcall.
#define VMCALL_READ_PHYSICAL_MEMORY
VMCALL to read physical memory.
Definition Vmcall.h:315
IMPORT_EXPORT_VMM BOOLEAN CheckAddressPhysical(UINT64 PAddr)
Checks if the physical address is correct or not based on physical address width.
Definition AddressCheck.c:120