Reputation:
How can I get the range of all readable memory in a process?
VirtualQuery only allows me to query pages at a time.
Upvotes: 0
Views: 328
Reputation: 3923
The only way to do this is to iterate over each memory region.
This code will do that, and output the start and end address of each region:
MEMORY_BASIC_INFORMATION meminfo;
unsigned char* addr = 0;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
MEMORY_BASIC_INFORMATION mbi;
while (VirtualQueryEx(hProc, addr, &mbi, sizeof(mbi)))
{
if (mbi.State == MEM_COMMIT && mbi.Protect != PAGE_NOACCESS)
{
std::cout << "base : 0x" << std::hex << mbi.BaseAddress << " end : 0x" << std::hex << (uintptr_t)mbi.BaseAddress + mbi.RegionSize << "\n";
}
addr += mbi.RegionSize;
}
Upvotes: 0
Reputation: 24477
There is no way to just get a list of readable pages. You need to iterate through all the memory (starting from the lowest address containing valid memory) with VirtualQuery. You can read the RegionSize from the MEMORY-BASIC_INFORMATION structure to know what base address to call at.
Upvotes: 1