python-3.x - Python Pymem 出现很多错误
问题描述
我正在使用 Pymem 为 CSGO 进行黑客攻击(仅限 Bot 服务器,别担心),但不断出现错误。我决定使用线程,因为我的函数有无限的 while 循环。但我不断收到以下错误:
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\gjohn\PycharmProjects\csgoGlow\venv\lib\site-packages\pymem\__init__.py", line 484, in read_int
value = pymem.memory.read_int(self.process_handle, address)
File "C:\Users\gjohn\PycharmProjects\csgoGlow\venv\lib\site-packages\pymem\memory.py", line 271, in read_int
bytes = read_bytes(handle, address, struct.calcsize('i'))
File "C:\Users\gjohn\PycharmProjects\csgoGlow\venv\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: 998
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:/Users/gjohn/PycharmProjects/csgoGlow/main.py", line 34, in glow
entity_team_id = pm.read_int(entity + m_iTeamNum)
File "C:\Users\gjohn\PycharmProjects\csgoGlow\venv\lib\site-packages\pymem\__init__.py", line 486, in read_int
raise pymem.exception.MemoryReadError(address, struct.calcsize('i'), e.error_code)
pymem.exception.MemoryReadError: Could not read memory at: -1899196620, length: 4 - GetLastError: 998
我不知道为什么。这是我的代码:
import keyboard
import pymem
import pymem.process
import time
from win32gui import GetWindowText, GetForegroundWindow
import threading
dwEntityList = (0x4DA2F44)
dwGlowObjectManager = (0x52EB540)
m_iGlowIndex = (0xA438)
dwForceAttack = (0x31D44D4)
dwForceJump = (0x524CEA4)
dwLocalPlayer = (0xD8B2BC)
m_fFlags = (0x104)
m_iCrosshairId = (0xB3E4)
m_iTeamNum = (0xF4)
m_flFlashMaxAlpha = (0xA41C)
trigger_key = "shift"
def glow():
print("Diamond has launched.")
pm = pymem.Pymem("csgo.exe")
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
while True:
glow_manager = pm.read_int(client + dwGlowObjectManager)
for i in range(1, 32): # Entities 1-32 are reserved for players.
entity = pm.read_int(client + dwEntityList + i * 0x10)
if entity:
entity_team_id = pm.read_int(entity + m_iTeamNum)
entity_glow = pm.read_int(entity + m_iGlowIndex)
if entity_team_id == 2: # Terrorist
pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(1)) # R
pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(1)) # G
pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(0)) # B
pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1)) # Alpha
pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1) # Enable glow
elif entity_team_id == 3: # Counter-terrorist
pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(0)) # R
pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(0)) # G
pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(1)) # B
pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1)) # Alpha
pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1) # Enable glow
def triggerBot():
print("Sapphire has launched.")
pm = pymem.Pymem("csgo.exe")
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
while True:
if not keyboard.is_pressed(trigger_key):
time.sleep(0.1)
if not GetWindowText(GetForegroundWindow()) == "Counter-Strike: Global Offensive":
continue
if keyboard.is_pressed(trigger_key):
player = pm.read_int(client + dwLocalPlayer)
entity_id = pm.read_int(player + m_iCrosshairId)
entity = pm.read_int(client + dwEntityList + (entity_id - 1) * 0x10)
entity_team = pm.read_int(entity + m_iTeamNum)
player_team = pm.read_int(player + m_iTeamNum)
if entity_id > 0 and entity_id <= 64 and player_team != entity_team:
pm.write_int(client + dwForceAttack, 6)
time.sleep(0.006)
def speed():
print("Ruby has launched.")
pm = pymem.Pymem("csgo.exe")
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
while True:
if not GetWindowText(GetForegroundWindow()) == "Counter-Strike: Global Offensive":
continue
if keyboard.is_pressed("space"):
force_jump = client + dwForceJump
player = pm.read_int(client + dwLocalPlayer)
if player:
on_ground = pm.read_int(player + m_fFlags)
if on_ground and on_ground == 257:
pm.write_int(force_jump, 5)
time.sleep(0.08)
pm.write_int(force_jump, 4)
time.sleep(0.002)
def flash():
print("Emerald has launched.")
pm = pymem.Pymem("csgo.exe")
client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
while True:
player = pm.read_int(client + dwLocalPlayer)
if player:
flash_value = player + m_flFlashMaxAlpha
if flash_value:
pm.write_float(flash_value, float(0))
time.sleep(1)
if __name__ == '__main__':
thread1 = threading.Thread(target=speed)
thread2 = threading.Thread(target=glow)
thread3 = threading.Thread(target=triggerBot)
thread4 = threading.Thread(target=flash)
thread1.start()
thread2.start()
thread3.start()
thread4.start()
thread1.join()
thread2.join()
thread3.join()
thread4.join()
我尝试了一切,它有点工作,直到我添加了第四个功能。这没有意义,因为错误不是针对那个线程的,当我注释掉那个线程时,glow 仍然返回这个错误。
解决方案
我收到了这个错误,实际上我尝试了几种不同的代码变体,基本上一个写入指针,另一个读取点,我也收到这个 win api 错误,错误 299 和 998。
我相信这与 pymem 本身有关,你可以尝试用 c++ 编写它,我相信它更适合读写内存,或者你也可以尝试 ReadWriteMemory 另一个 python 模块,但我怀疑你会有任何运气到,它已停产,我自己尝试过,它似乎无法读取地址而不会出现一些溢出错误。
推荐阅读
- java - MongoDB在过滤器中返回指定文档
- java - Java:编组或解组数据时出错:null
- r - ggplot图例键宽度由标签长度确定
- ios - Swift - 呈现 UIView(不是 ViewController)
- c# - 将一个数组复制到另一个数组,但 C# 中的一个属性除外
- python - uproot 的字符串数组
- java - Hibernate Search FieldBridge 可以为动态字段配置构面吗?
- python - 更改列中第一个非零元素上方的数组值
- python - 插值函数 - 矩阵
- android - 使用 Kotlin 向 ROOM 数据库中的特定 id 添加注释