Python ctypes 长整数错误,我该如何解决这个问题?

问题描述 投票:0回答:1

我正在使用Python开发内存快照/采集软件,所以我使用“pymem_snapshot”库和“winpmem”驱动程序。

自己的Python类链接

但是当我想要获得大容量内存(超过 2GB)时,我会得到整数错误。

我的程序(稳定)

from src.pymem_class import PyMem

if __name__ == "__main__":
    PyMem.service_create()
    # Drivers: https://github.com/Velocidex/WinPmem/tree/master/kernel/binaries
    # Run "bcdedit /set testsigning on" command
    # Check Memory Compression with "Get-MMAgent" command
    # Disable Memory Compression with "Disable-MMAgent -mc" command
    # Restart computer
    PyMem.dump_and_save_memory("demo", int(1024 * 1024 * 1024)) # 1 GB Memory Image WORKING

我的程序(崩溃)

from src.pymem_class import PyMem

if __name__ == "__main__":
    PyMem.service_create()
    # Drivers: https://github.com/Velocidex/WinPmem/tree/master/kernel/binaries
    # Run "bcdedit /set testsigning on" command
    # Check Memory Compression with "Get-MMAgent" command
    # Disable Memory Compression with "Disable-MMAgent -mc" command
    # Restart computer
    PyMem.dump_and_save_memory("demo", int(8 * 1024 * 1024 * 1024)) # 8 GB Memory Image CRASH

崩溃日志

Traceback (most recent call last):
  File "C:\Users\dfnss\OneDrive\Desktop\pymem_snapshot\example.py", line 11, in <module>
    PyMem.dump_and_save_memory("demo", memsize)
  File "C:\Users\dfnss\OneDrive\Desktop\pymem_snapshot\src\pymem_class.py", line 51, in dump_and_save_memory
    data = win32file.ReadFile(device_handle, memsize)[1] # Reading memory...
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Second param must be an integer or writeable buffer object

我该如何解决这个问题?我什至尝试过 ChatGPT 的帮助,但没有成功

谢谢各位的解答

python security ctypes pywin32 pywin
1个回答
1
投票

Pymem 需要一个整数(

int
)类型作为内存大小的参数。 Python 上的
int
数据类型范围为 -2,147,483,648 到 + 2,147,483,647 (来源:在此处输入链接描述)。这意味着您的方程
1024 * 1024 * 1024
在此范围内,但
8 * 1024 * 1024 * 1024
不在该范围内。

© www.soinside.com 2019 - 2024. All rights reserved.