1

I need function in python to read a value from a specific memory address on Linux . I've a PID process and memory address '4df0568'. i try using ctypes, ptrace.

sample: a int32 value on adress '4df0568' = 3065

i need a loop function to read this address and return a int value.

note: this is a game memory address

EDIT: this a SoLUTION

pid = 4563

address=0x4df0568 # top of stack (have a look at /proc/{pid}/maps for the interesting addresses)                                               

    fd = open(f"/proc/{pid}/mem", "rb")
    fd.seek(address)
    value = fd.read(4) # read an int32
    print(int.from_bytes(value, byteorder='little'))

  • Does this answer your question? [Access memory address in python](https://stackoverflow.com/questions/8250625/access-memory-address-in-python) – Slava Knyazev Jul 21 '20 at 18:22
  • thx, but this don't work on external process on linux. – Helio Junior Jul 21 '20 at 18:30
  • I see. Python is not really designed around low-level constructs in mind. If you don't find a pure Python way of doing it, I would recommend writing a library in another language and calling it using FFI from python. – Slava Knyazev Jul 21 '20 at 18:43
  • 2
    If you're attempting to read a memory location that isn't allocated to your process by the operating system I'm reasonably confident that it isn't possible - modern operating systems don't tend to like software trying to touch memory assigned to other processes. – jonyfries Jul 21 '20 at 18:43
  • i've mistake delete previuos comment, this a solution: address=0x4df0568 # top of stack (have a look at /proc/{pid}/maps for the interesting addresses) fd = open(f"/proc/{pid}/mem", "rb") fd.seek(address) value = fd.read(4) # read an int32 print(int.from_bytes(value, byteorder='little')) – Helio Junior Jul 21 '20 at 19:44

0 Answers0