Skip to content

Commit 075ca65

Browse files
ivonastojanovicgodlygeek
authored andcommitted
Write to process memory on Windows
1 parent 96798c3 commit 075ca65

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Python/remote_debugging.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,16 @@ static Py_ssize_t
610610
write_memory(proc_handle_t *handle, uintptr_t remote_address, size_t len, const void* src)
611611
{
612612
#ifdef MS_WINDOWS
613-
// TODO: Implement this function
614-
PyErr_SetString(PyExc_RuntimeError, "Memory writing is not supported on Windows");
613+
SIZE_T written = 0;
614+
SIZE_T result = 0;
615+
do {
616+
if (!WriteProcessMemory(handle->hProcess, (LPVOID)(remote_address + result), (const char*)src + result, len - result, &written)) {
617+
PyErr_SetFromWindowsErr(0);
615618
return -1;
619+
}
620+
result += written;
621+
} while (result < len);
622+
return (Py_ssize_t)result;
616623
#elif defined(__linux__) && HAVE_PROCESS_VM_READV
617624
struct iovec local[1];
618625
struct iovec remote[1];

0 commit comments

Comments
 (0)