How to write to another process's address space using python under Ubuntu Linux? My attempts:
1) Using the virtual file /proc/$PID/mem and seeking to the address. I have successfully used it to read memory, but attempting to write causes an IOError:
fd=open("/proc/"+pid+"/mem","r+")
fd.seek(address,0)
fd.write("ABC")
Output:
IOError: [Errno 22] Invalid argument
2) Attempting to use the python-ptrace library as suggested in other threads. However, I cannot find good documentation or example code.
Note: this is not a permissions issue, running as root produces the same behaviour.
rw
is not a valid mode value foropen()
. To open a file for both reading and writing you'd have to user+
instead. – DeccaOSError: [Errno 22] Invalid argument
– Vasilikivasilis