srounet / Pymem

A python library for windows, providing the needed functions to start working on your own with memory editing.
MIT License
303 stars 45 forks source link

GetLastError: 299 while reading an int from memory #60

Closed AtaeKurri closed 3 years ago

AtaeKurri commented 3 years ago

Describe the bug I'm trying to run an 'SoD.read_int(0x9969BC)'. It should give me the int value of that memory space, but it gives me this error : pymem.exception.MemoryReadError: Could not read memory at: 10054076, length: 4 - GetLastError: 299 My code is :

import pymem

SoD = pymem.Pymem("SoD.exe")

addr = {
    "x": 0x00C599F4,
    "y": 0x00C599F8,
    "map": 0x9969BC
}

x = SoD.read_int(addr["map"])
print(x)

What am I doing wrong ?

Your Environment

  1. python version (3.7.9)
  2. os version (64)
  3. pymem version (1.8.4)

Expected behavior Should return some value, here for example it should return int(504).

Traceback

Traceback (most recent call last):
  File "C:\Users\kurri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymem\__init__.py", line 530, in read_int
    value = pymem.memory.read_int(self.process_handle, address)
  File "C:\Users\kurri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymem\memory.py", line 304, in read_int
    bytes = read_bytes(handle, address, struct.calcsize('i'))
  File "C:\Users\kurri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymem\memory.py", line 105, in read_bytes
    raise pymem.exception.WinAPIError(error_code)
pymem.exception.WinAPIError: Windows api error, error_code: 299

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Bordel sans nom\logiciels\SoD\app.py", line 15, in <module>
    x = SoD.read_int(addr["map"])
  File "C:\Users\kurri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymem\__init__.py", line 532, in read_int
    raise pymem.exception.MemoryReadError(address, struct.calcsize('i'), e.error_code)
pymem.exception.MemoryReadError: Could not read memory at: 10054076, length: 4 - GetLastError: 299
StarrFox commented 3 years ago

Error code 299 is ERROR_PARTIAL_COPY (Only part of a ReadProcessMemory or WriteProcessMemory request was completed.) as per https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-

Are you sure this is the correct address for the value you're trying to read?

AtaeKurri commented 3 years ago

Yes i'm sure this is the right address, I tried with other programs and it reads perfectly the good value, so it must be something with the module, python or my code, well, with what I know

AtaeKurri commented 3 years ago

It works after a bit of thinkering, it was my PC's fault.