How can I change the value of an memory-address in Python?

Viewed 284

My current code that does not show an error message but also doesn't work:

py import time
from ReadWriteMemory import ReadWriteMemory

process = ReadWriteMemory.get_process_by_name("Tutorial-i386.exe")
process.open()

address = 0x0195A810
health = process.get_pointer(address, offsets=[0])

while True:
    value = process.read(health)
    print(value)
    time.sleep(0.5)
1 Answers

You can try to use the ctypes library. Try this,

import ctypes

data = (ctypes.c_char).from_address(0x0195A810)

You can read and assign to the data variable. Make sure you select the correct type. I used char in this instance. Not sure what kind of value is stored there. You can see what types are available in the link below.

You can also get a list/array of memory addresses using this,

dataarr = (ctypes.c_char*offset).from_address(0x0195A810)

You can check out the documentation here,

https://docs.python.org/3/library/ctypes.html

Related