【问题标题】:VirtualQueryEx returning ERROR_BAD_LENGTH (Python)VirtualQueryEx 返回 ERROR_BAD_LENGTH (Python)
【发布时间】:2022-10-15 01:11:34
【问题描述】:

我正在尝试执行 VirtualQueryEx 函数,但收到错误 24 (ERROR_BAD_LENGTH),我无法弄清楚我做错了什么。这是我的代码(仅包括必要的部分)。

import ctypes as ct
from ctypes.wintypes import *


SIZE_T = ct.c_size_t
PVOID = LPVOID


class MEMORY_BASIC_INFORMATION(ct.Structure):
    _fields = (
        ("BaseAddress", PVOID),
        ("AllocationBase", PVOID),
        ("AllocationProtect", DWORD),
        ("PartitionId", WORD),
        ("RegionSize", SIZE_T),
        ("State", DWORD),
        ("Protect", DWORD),
        ("Size", DWORD),
    )


k32 = ct.WinDLL('kernel32')
VirtualQueryEx = k32.VirtualQueryEx
VirtualQueryEx.argtypes = HANDLE, LPCVOID, ct.POINTER(MEMORY_BASIC_INFORMATION), SIZE_T
VirtualQueryEx.restype = SIZE_T


info = MEMORY_BASIC_INFORMATION()
# proch comes from an OpenProcess call and the starting address I chose is one I picked from CheatEngine for testing.
bytes_returned = VirtualQueryEx(proch, 0x1408E125, ct.byref(info), ct.sizeof(info))
if bytes_returned == 0:
    print(f"Error occurred: {k32.GetLastError()}")
else:
    print(bytes_returned)

【问题讨论】:

    标签: python winapi ctypes


    【解决方案1】:

    我不敢相信我错过了这个,但我把 _fields 而不是 _fields_ 放在 MEMORY_BASIC_INFORMATION 类中。更改后,它工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多