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

Function Catch_NtWriteVirtualMemory

RedEdrDll/dllmain.cpp:309–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

307 );
308t_NtWriteVirtualMemory Real_NtWriteVirtualMemory = NULL;
309NTSTATUS NTAPI Catch_NtWriteVirtualMemory(
310 HANDLE ProcessHandle,
311 PVOID BaseAddress,
312 PVOID Buffer,
313 ULONG NumberOfBytesToWrite,
314 PULONG NumberOfBytesWritten
315) {
316 int64_t time = get_time();
317 char buf[DATA_BUFFER_SIZE] = "";
318
319 if (HooksInitialized) { // dont log our own hooking
320 int offset = 0;
321 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "{");
322 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"type\":\"dll\",");
323 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"time\":%llu,", time);
324 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"pid\":%lu,", (DWORD)GetCurrentProcessId());
325 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"tid\":%lu,", (DWORD)GetCurrentThreadId());
326 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"func\":\"NtWriteVirtualMemory\",");
327 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"handle\":%lld,", (long long)ProcessHandle);
328 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"base_address\":%llu,", BaseAddress);
329 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"buffer\":%llu,", Buffer);
330 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "\"size\":%lu,", NumberOfBytesToWrite);
331 offset += LogMyStackTrace(&buf[offset], DATA_BUFFER_SIZE - offset);
332 offset += sprintf_s(buf + offset, DATA_BUFFER_SIZE - offset, "}");
333
334 SendDllPipe(buf);
335 }
336 return Real_NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten);
337}
338
339
340/******************* ReadVirtualMemory ************************/

Callers

nothing calls this directly

Calls 3

get_timeFunction · 0.85
LogMyStackTraceFunction · 0.85
SendDllPipeFunction · 0.85

Tested by

no test coverage detected