MCPcopy Create free account
hub / github.com/Astronaut00/DoubleDataPointer / ReadProcessMemory

Function ReadProcessMemory

Driver/core.cpp:167–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165
166 //
167 NTSTATUS ReadProcessMemory(int pid, uint64_t Address, uint64_t AllocatedBuffer, SIZE_T size, SIZE_T* read)
168 {
169 PEPROCESS pProcess = NULL;
170 if (pid == 0) return STATUS_UNSUCCESSFUL;
171
172 NTSTATUS NtRet = PsLookupProcessByProcessId((HANDLE)pid, &pProcess);
173 if (NtRet != STATUS_SUCCESS) return NtRet;
174
175 ULONG_PTR process_dirbase = GetProcessCr3(pProcess);
176 ObDereferenceObject(pProcess);
177
178 SIZE_T CurOffset = 0;
179 SIZE_T TotalSize = size;
180 while (TotalSize)
181 {
182
183 uint64_t CurPhysAddr = TranslateLinearAddress(process_dirbase, (ULONG64)Address + CurOffset);
184 if (!CurPhysAddr) return STATUS_UNSUCCESSFUL;
185
186 ULONG64 ReadSize = min(PAGE_SIZE - (CurPhysAddr & 0xFFF), TotalSize);
187 SIZE_T BytesRead = 0;
188 NtRet = ReadPhysicalAddress(CurPhysAddr, (PVOID)((ULONG64)AllocatedBuffer + CurOffset), ReadSize, &BytesRead);
189 TotalSize -= BytesRead;
190 CurOffset += BytesRead;
191 if (NtRet != STATUS_SUCCESS) break;
192 if (BytesRead == 0) break;
193 }
194
195 *read = CurOffset;
196 return NtRet;
197 }
198
199 NTSTATUS WriteProcessMemory(int pid, uint64_t Address, uint64_t AllocatedBuffer, SIZE_T size, SIZE_T* written)
200 {

Calls 3

GetProcessCr3Function · 0.85
TranslateLinearAddressFunction · 0.85
ReadPhysicalAddressFunction · 0.85

Tested by

no test coverage detected