使用python,调用writeprocessmemory函数,用管理员权限运行后,并没有实现内存写入的功能,错误代码998,请问一下,是哪里的问题?感谢!(地址address至少是可读的,可以读出内容)
import ctypes
from ctypes import wintypes
# 定义函数所需的参数类型和返回类型
OpenProcess = ctypes.windll.kernel32.OpenProcess
OpenProcess.argtypes = [wintypes.DWORD, wintypes.BOOL, wintypes.DWORD]
OpenProcess.restype = wintypes.HANDLE
CloseHandle = ctypes.windll.kernel32.CloseHandle
CloseHandle.argtypes = [wintypes.HANDLE]
CloseHandle.restype = wintypes.BOOL
WriteProcessMemory = ctypes.windll.kernel32.WriteProcessMemory
WriteProcessMemory.argtypes = [wintypes.HANDLE, wintypes.LPVOID, wintypes.LPCVOID, ctypes.c_size_t, ctypes.POINTER(ctypes.c_size_t)]
WriteProcessMemory.restype = wintypes.BOOL
# 调用OpenProcess函数
current_pid =1184 # 获取当前进程的PID(进程标识符)
PROCESS_ALL_ACCESS = 0x1F0FFF # 所有访问权限
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, current_pid)
# 调用WriteProcessMemory函数
data_to_write = ctypes.c_int(1) # 要写入的数据
target_address = 0x0D008889 # 目标地址
bytes_written = ctypes.c_size_t() # 创建一个缓冲区来接收写入的字节数
success = WriteProcessMemory(hProcess, target_address, ctypes.addressof(data_to_write), ctypes.sizeof(data_to_write), ctypes.byref(bytes_written))
#获取上一步的失败代码
error_code = ctypes.GetLastError()
print(error_code)
# 调用CloseHandle函数
CloseHandle(hProcess)
#最后输出结果
if success:
print("Successfully")
else:
print("Failed")