Read and write target process memory via /proc/PID/mem.
- Opens
/proc/<pid>/memas a regular file - Uses
pread()/pwrite()with the virtual address as the offset - The kernel allows writes to read-only pages (like
.text) when ptrace-attached
PTRACE_PEEKDATA reads one machine word at a time (4 or 8 bytes per syscall). /proc/PID/mem lets us read/write arbitrary-length buffers in a single syscall, which is critical when writing multi-byte shellcode into code caves.
Requires the target process to be ptrace-attached (see ptrace-core/).