当您调用 VirtualAlloc() 时,您可以分配一段跨越多个页面的内存。当您在该部分的中间进行 VirtualQuery() 页面时,AllocationBase 将是 VirtualAlloc 的返回值,它是由 VirtualAlloc() 分配的内存的开始。BaseAddress 将是您查询的单个页面的基地址。
这是一个示例程序,它显示了它的实际效果:
int main()
{
intptr_t addr = (intptr_t)VirtualAlloc(0, 0x3000, MEM_COMMIT, PAGE_READWRITE);
MEMORY_BASIC_INFORMATION mbi{ 0 };
VirtualQuery((void*)(addr + 0x2000), &mbi, sizeof(mbi));
intptr_t middleAddr = addr + 0x2000;
std::cout << "VirtualAlloc returned = 0x" << std::hex << addr << "\n";
std::cout << "Middle Address Queried = 0x" << std::hex << middleAddr << "\n";
std::cout << "mbi.AllocationBase = 0x" << std::hex << mbi.AllocationBase << "\n";
std::cout << "mbi.BaseAddress = 0x" << std::hex << mbi.BaseAddress << "\n";
getchar();
return 0;
}
输出:
VirtualAlloc returned = 0x5d0000
Middle Address Queried = 0x5d2000
mbi.AllocationBase = 0x005D0000
mbi.BaseAddress = 0x005D2000
同样,AllocationProtect 关注分配页面,而不是您查询的单个页面。