带有PROCESS_QUERY_INFORMATION的VirtualQueryEx给出错误24

时间:2016-03-30 20:51:57

标签: c# memory

我一直试图关注如何读取进程已分配的所有内存this tutorial。现在,我有点坚持这个问题:

每当我执行VirtualQueryEx请求一些基本内存信息时,该函数总是返回0并且我得到Win32错误24(ERROR_BAD_LENGTH)。据我所知,我严格遵循教程,但似乎错误在于教程源代码。似乎MEMORY_BASIC_INFORMATION结构有问题,但我不确定。

这是代码的缩减版本:

const int PROCESS_QUERY_INFORMATION = 0x0400;
const int PROCESS_WM_READ = 0x0010;

public struct MEMORY_BASIC_INFORMATION {
  public int BaseAddress;
  public int AllocationBase;
  public int AllocationProtect;
  public int RegionSize;
  public int State;
  public int Protect;
  public int lType;
}

IntPtr processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_WM_READ, false, process.Id);

MEMORY_BASIC_INFORMATION mem_basic_info = new MEMORY_BASIC_INFORMATION();

uint infoSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(mem_basic_info);
    VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, infoSize);

有人能指出我在正确的方向吗?提前谢谢!

Here's a pastebin of all the relevant code.

0 个答案:

没有答案