ctype-python-long int太长,无法转换-

ctype-python-long int太长,无法转换-,python,ctypes,Python,Ctypes,问题: 回溯(最近一次调用):文件“C:\Users\Nutzer\Google 驱动器\Code\Code\memory\u read.py”,第26行,在 byref(ByteRead))ctypes.ArgumentError:参数2::long int太长,无法转换 代码: 我试图将bytesRead=c_ulong(0)更改为其他一些ctypes,但没有成功。在64位Windows 8.1系统上进行即时通讯。经过几个小时的搜索,我找不到任何解决方案或类似的问题。有人知道这里出了什么问题

问题:

回溯(最近一次调用):文件“C:\Users\Nutzer\Google 驱动器\Code\Code\memory\u read.py”,第26行,在 byref(ByteRead))ctypes.ArgumentError:参数2::long int太长,无法转换

代码:


我试图将bytesRead=c_ulong(0)更改为其他一些ctypes,但没有成功。在64位Windows 8.1系统上进行即时通讯。经过几个小时的搜索,我找不到任何解决方案或类似的问题。有人知道这里出了什么问题吗?

经过长时间的失败和错误,我终于有了答案

from ctypes import *
from ctypes.wintypes import *
import ctypes

OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle

PROCESS_ALL_ACCESS = 0x1F0FFF

pid = 2320
address = 0x00C98FCC

buffer = c_char_p(b"The data goes here")
val = c_int()
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)

processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)

if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
    memmove(ctypes.byref(val), buffer, ctypes.sizeof(val))

    print("Success: " + str(val.value))
else:
    print("Failed.")

CloseHandle(processHandle)

设置
SIZE\u T=c\u SIZE\u T
ReadProcessMemory.argtypes=[HANDLE,LPCVOID,LPVOID,SIZE\u T,POINTER(SIZE\u T)]
OpenProcess.restype=HANDLE
CloseHandle.argtypes=[HANDLE]
。不要修改Python字符串。使用
Create_string_buffer
或仅使用常规ctypes语法创建数组,例如
bufferSize=201
buffer=(c_char*bufferSize)(
。请确保对out参数使用正确的类型,
bytesRead=SIZE\u T()
。在Win64.BTW中是8个字节,参数2是地址。默认参数类型为32位
int
,给定值超出范围。我建议的
argtypes
使用
LPCVOID
作为此参数,即
void*
指针。
from ctypes import *
from ctypes.wintypes import *
import ctypes

OpenProcess = windll.kernel32.OpenProcess
ReadProcessMemory = windll.kernel32.ReadProcessMemory
CloseHandle = windll.kernel32.CloseHandle

PROCESS_ALL_ACCESS = 0x1F0FFF

pid = 2320
address = 0x00C98FCC

buffer = c_char_p(b"The data goes here")
val = c_int()
bufferSize = len(buffer.value)
bytesRead = c_ulong(0)

processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pid)

if ReadProcessMemory(processHandle, address, buffer, bufferSize, byref(bytesRead)):
    memmove(ctypes.byref(val), buffer, ctypes.sizeof(val))

    print("Success: " + str(val.value))
else:
    print("Failed.")

CloseHandle(processHandle)