好吧,你们所有ctypes
的大师都在那里...
我有一个每秒读取内存地址一百次的 python 脚本。存储在此内存地址的值表示一个无符号整数。该值随时间增加。不幸的是,当它通过 2^8、2^16 或 2^24 时,ReadProcessMemory 调用没有读取足够的字节来获取更大的整数。事实上,它似乎在第一次读取后没有读取正确数量的字节。
这是代码片段:
from time import sleep
from ctypes import *
from struct import *
pid = 0x0D50
op = windll.kernel32.OpenProcess
rpm = windll.kernel32.ReadProcessMemory
ch = windll.kernel32.CloseHandle
PAA = 0x1F0FFF
addy = 0x38D53368
ph = op(PAA,False,int(pid)) #program handle
lastvalue = 0
while True:
datadummy = b'.'*4
buff = c_char_p(datadummy)
bufferSize = (len(buff.value))
bytesRead = c_ulong(0)
if rpm(ph,addy,buff,bufferSize,byref(bytesRead)):
value = unpack('I',datadummy)[0]
if lastvalue != value:
print value
print bytesRead
lastvalue = value
sleep(.01)
输出可能类似于:
191
c_ulong(4L) ////Here it got 4 bytes like I expected
211
c_ulong(1L) ////But here it only got 1 byte.?? It should be reading 4 bytes everytime
231
c_ulong(1L)
251
c_ulong(1L)
15 ////This value is incorrect, because it only reads 1 byte. (should be 271)
c_ulong(1L)
在我看来,它只是读取前一个调用需要读取的字节数......
我怎样才能解决这个问题?