Search code examples
pythonpython-3.xmemorymemory-management

Python Pymem MemoryReadError GetLastError: 299


Since 2 day i try to read docs of pymem and search an error on forums but all solution i've seen failed

I can't just read the int in the memory address and i don't know if it's a probleme of code or my pc

from pymem import *
from pymem.process import module_from_name


pm = pymem.Pymem("***-Win64.exe")

gameModule = module_from_name(pm.process_handle, "***-Win64.exe").lpBaseOfDll

def GetPtrAddr(base, offsets):
    addr = pm.read_int(base) # addr = 9460301, base = 140696812060672
    for i in offsets:
        if i != offsets[-1]:
            addr = pm.read_int(addr + i) # <- here is the error line
    return addr + offsets[-1]

pm.read_int(GetPtrAddr(gameModule + 0x04D934B0, [0x50, 0x30, 0x98, 0xf0, 0x380]))

error

pymem.exception.MemoryReadError: Could not read memory at: 9460349, length: 4 - GetLastError: 299

i tried this too Reading Memory Address from a process with a Static Address and Offsets in Python but i have error

ctypes.ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert

but the only value i try to get is from 0 to 12 enter image description here

I add a try catch in the for loop and here is the error

Could not read memory at: 9460349, length: 4 - GetLastError: 299
Could not read memory at: 9460973, length: 4 - GetLastError: 299
Could not read memory at: 9460589, length: 4 - GetLastError: 299
Could not read memory at: 9460301, length: 4 - GetLastError: 299

Solution

  • I fanally found my error thanks to @Joe_Bao for the help

    The problem was because my application is in 64bit and i tried to read a int but that's not enough so here the complete code

    from pymem import *
    from pymem.process import *
    
    offsets = [0x50,0x30,0x98,0xF0,0x380]
    
    pm = Pymem('***-Win64.exe')
    
    gameModule = module_from_name(pm.process_handle, '***-Win64.exe').lpBaseOfDll
    
    
    def GetPointer(base, offsets):
        addr = pm.read_longlong(base+0x04D934B0) # <-- here was the probleme solved
        print(hex(addr))
        for offset in offsets:
            if offset != offsets[-1]:
                try:
                    addr = pm.read_longlong(addr + offset)
                    print(addr)
                except Exception as e:
                    print(e)
        return addr + offsets[-1]
    
    GetPointer(gameModule, offsets)