Home > Software design >  Python Pymem MemoryReadError GetLastError: 299
Python Pymem MemoryReadError GetLastError: 299

Time:04-11

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 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

CodePudding user response:

I wonder why you add the return value from pm.readint() with your offset. It seems that base is a valid address you can access, while addr some offset isn't.

I read from the documentation that read_int reads 4 byte from an area of memory in a specified process. Is the return value addr the address you want to use?

FYI, I found that the error code is thrown by kernel32, and it means ERROR_PARTIAL_COPY.

CodePudding user response:

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)
  • Related