srounet / Pymem

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

MemoryWriteError, GetLastError 87 while trying to write_bool #81

Closed kyriakid1s closed 2 years ago

kyriakid1s commented 2 years ago

Describe the bug I try to make a radar hack for cs go. My code is below.

Your Environment

  1. python version (3.10)
  2. os version (64)
  3. pymem version 1.8.5

Expected behavior I try to make a radar hack for cs go. My code is below

import pymem.process
import keyboard

dwEntityList = (0x4DD245C)
m_bSpotted = (0x93D)

def test_write_uchar():
    pm = pymem.Pymem('python.exe')
    address = pm.allocate(10)

    pm.write_uchar(address, 114)
    assert pm.read_uchar(address) == 114
    pm.free(address)

    with pytest.raises(TypeError):
        pm.write_uchar(0x111111, "114")

    pm = pymem.Pymem()
    with pytest.raises(pymem.exception.ProcessError):
        pm.write_uchar(0x111111, 114)
def main():
    pm = pymem.Pymem("csgo.exe")
    client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll

    while True:
        if keyboard.is_pressed("end"):
            exit(0)
        for i in range(1, 32):
            entity = pm.read_int(client + dwEntityList + i * 0x10)
            if entity:
                pm.write_bool(entity + m_bSpotted, True)

if __name__ == '__main__':
    main()

Traceback I get this error

Traceback (most recent call last):
  File "C:\Users\kyriakidis\PycharmProjects\pythonProject1\main.py", line 23, in <module>
    main()
  File "C:\Users\kyriakidis\PycharmProjects\pythonProject1\main.py", line 19, in main
    pm.write_bool(entity + m_bSpotted, True)
  File "C:\Users\kyriakidis\PycharmProjects\pythonProject1\venv\lib\site-packages\pymem\__init__.py", line 895, in write_bool
    raise pymem.exception.MemoryWriteError(address, value, e.error_code)
pymem.exception.MemoryWriteError: Could not write memory at: -1884891523, length: True - GetLastError: 87

Additional context The weird thing now is that 1 out of 10 times the code works, but the resr 9 i showa the above error

PS. i tried write_uchar, write_int but it gives the same error