How to read memory address over ram size in python

0

I want to read some register from /dev/mem, and here is the sample code

import os, sys
fd = os.open("/dev/mem",os.O_RDWR)

#0xFED01004 = 4275048452
os.lseek(fd, 4275048452, os.SEEK_SET)

ret = os.read(fd,2)
print ret

os.close(fd)
print "close"

But my ram size is 2 GB(0x7FFFFFFF) and it's less than 4275048452. It will get bad address error after executing this code.

I usually use memhack tool (write in c ) to do this work, it uses nmap to transform the physical address to virtual address in user space so the tool can read 0xFED01004 correctly. But now I want to use python to do this work.

Can Python achieve that?

If I add ram to 4GB then this code works, but it's not what I want.

python
c
linux
memory
embedded-linux
asked on Stack Overflow May 11, 2018 by austinc • edited May 11, 2018 by austinc

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0