0

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
Kal-1
  • 177
  • 1
  • 9
  • Could you add the line number of the error? Did your program read the base address successfully? Also, what's the value for the base address here (gameModule + 0x04D934B0)? – Joe_Bao Apr 09 '22 at 11:55
  • the error is at the line 'addr = pm.read_int(addr + offset)' the value of base is 140696812060672 and addr is 9460301 – Kal-1 Apr 09 '22 at 12:36

2 Answers2

1

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.

Joe_Bao
  • 116
  • 6
  • I updated my question with the cheat engine screenshot of the address I also tried to just do pm.read(addr) but i have the same error with same code 299 – Kal-1 Apr 09 '22 at 13:39
  • @Kal-1 What would happen if we directly try to read_int from the memory address "1B5B599 31A0" – Joe_Bao Apr 10 '22 at 14:21
  • That give me the good result but the problem is this is not the static address if i close and re open the game a new address is generated – Kal-1 Apr 10 '22 at 14:40
  • I think i've found the probleme I don't have the first address 1B5E6419C00 so the rest is fcked up – Kal-1 Apr 10 '22 at 14:47
  • 1
    May that have something to do with your usage of addr = pm.read_int(base)? I read from the documentation that it only reads 4 bytes (32 bit). I think from the base address "140696812060672" you are probably using 64-bit address. Will read_longlong(address) be what you want? – Joe_Bao Apr 10 '22 at 14:51
  • pm.read_longlong(base) give me the result "0x300905a4d" but I'm on 64bit application that's true – Kal-1 Apr 10 '22 at 14:55
  • lpBaseOfDll is the load address of the module "***-Win64.exe", and I guess maybe you could simply add base with offset, and use pm.read_int(base + offset) to read the int value you want? – Joe_Bao Apr 10 '22 at 15:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/243766/discussion-between-kal-1-and-joe-bao). – Kal-1 Apr 10 '22 at 15:10
0

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)
Kal-1
  • 177
  • 1
  • 9