Using Python to return pointer to already existing memory address


On Python, using ctypes if applicable, how can I return the value a memory address is pointing to?

For instance- when I boot up my x86 PC, let's say the address 0xfffff800 points to a memory address of 0xffffffff

Using Python, how do I extract the value 0xfffff800 is pointing to (0xffffffff) and save it into a variable? Is this even possible? I have tried using id but I believe that is only used for local instances (if I created a variable, assigned it a value, and returned that value via id)


asked on Stack Overflow Feb 1, 2020 by JoeRob7

1 Answer


From your reference to memory contents at boot time, and the idea implicit in the question that there is only one value at any given address, I take you to be talking about physical memory. In that case, no, what you ask is not possible. Only the operating system kernel (or some other program running directly on the hardware) can access physical memory in any system that presently supports Python, and to the best of my knowledge, there is no Python implementation that runs on bare metal.

Instead, the operating system affords each running process its own virtual memory space in which to run, whose contents at any given time might reside more or less anywhere in physical memory or on swap devices (disk files and / or partitions). The system takes great care to isolate processes from each other and from the underlying physical storage, so no, Python cannot access it.

Moreover, processes running on an OS cannot generally access arbitrary virtual addresses, either, regardless of the programming language in which they are written. They can access only those portions of their address spaces that the OS has mapped for them. ctypes therefore does not help you.

answered on Stack Overflow Feb 1, 2020 by John Bollinger

User contributions licensed under CC BY-SA 3.0