MCPcopy Create free account
hub / github.com/dobin/RedEdr / Catch_NtReadVirtualMemory

Function Catch_NtReadVirtualMemory

RedEdrDll/dllmain.cpp:351–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349 );
350pNtReadVirtualMemory Real_NtReadVirtualMemory = NULL;
351NTSTATUS NTAPI Catch_NtReadVirtualMemory(
352 HANDLE ProcessHandle,
353 PVOID BaseAddress,
354 PVOID Buffer,
355 ULONG NumberOfBytesToRead,
356 PULONG NumberOfBytesRead
357) {
358 int64_t time = get_time();
359 char buf[DATA_BUFFER_SIZE] = "";
360
361 if (HooksInitialized) { // dont log our own hooking
362 if (!skip_self_readprocess || ProcessHandle != (HANDLE)-1) {
363 int offset = 0;
364 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "{");
365 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"type\":\"dll\",");
366 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"time\"k:%llu,", time);
367 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"pid\":%lu,", (DWORD)GetCurrentProcessId());
368 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"tid\":%lu,", (DWORD)GetCurrentThreadId());
369 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"func\":\"NtReadVirtualMemory\",");
370 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"handle\":%lld,", (long long)ProcessHandle);
371 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"base_address\":%llu,", BaseAddress);
372 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"buffer\":%llu,", Buffer);
373 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"size\":%lu", NumberOfBytesToRead);
374 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "}");
375 SendDllPipe(buf);
376 }
377
378 // Currently makes notepad.exe crash on save dialog open on win11.
379 // And its a lot of data
380 //offset += LogMyStackTrace(&buf[ret], DATA_BUFFER_SIZE - ret);
381 }
382
383 return Real_NtReadVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToRead, NumberOfBytesRead);
384}
385
386
387/******************* NtSetContextThread ************************/

Callers

nothing calls this directly

Calls 2

get_timeFunction · 0.85
SendDllPipeFunction · 0.85

Tested by

no test coverage detected