Reputation: 91
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.
Upvotes: 6
Views: 1547
Reputation: 91
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.
Upvotes: 3