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.
Found a solution here: http://tito.googlecode.com/svn-history/r2/trunk/draft/fakefs.py
It uses the ctypes package to load libc, then libc.ptrace with the POKEDATA option to write the bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With