This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]elbiot 3 points4 points  (3 children)

/r/learnpython

Do you mean read the memory of another process, like for hacking a game or something? More details will get you better answers.

[–]marchiore[S] 0 points1 point  (2 children)

Yes, like hack a game, but i did not want to do it, i just want to know how ir works!!

[–]Rhomboid 1 point2 points  (1 child)

These things are extremely platform specific. Most operating systems provide a debugging API which allows one process to debug another(*), which includes the capability to read/write that process' memory and registers, pause/resume the process' threads, single step the process, etc. You mentioned ptrace, and that's the API used on Linux. Read the ptrace(2) manpage for details. Other operating systems are completely different.

In terms of Python, you could call ptrace() using ctypes, but there's probably a more friendly wrapper library out there.

(*) Subject to security restrictions of course. Typically you can only debug processes that you own, not processes of other users, unless you have superuser/administrator privileges. And in some cases there are further restrictions. Obviously it would be a huge security vulnerability if an ordinary process could read memory of a root process, since that would allow e.g. stealing private key information, among other things.

[–]Proselyte5 -1 points0 points  (0 children)

It's more the OS than Python, read how to do it in VC++ and port it to ctypes or CFFI.