Skip to content

Instantly share code, notes, and snippets.

@hackpascal
Created March 26, 2017 13:00
Show Gist options
  • Save hackpascal/c35a056a7d185eba3a46a01aa4045215 to your computer and use it in GitHub Desktop.
Save hackpascal/c35a056a7d185eba3a46a01aa4045215 to your computer and use it in GitHub Desktop.
获取进程的内存映射表
int main()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
char *pMin = (char*)si.lpMinimumApplicationAddress;
char *pMax = (char*)si.lpMaximumApplicationAddress;
for (char* pAddress = pMin; pAddress<pMax; /*Empty*/)
{
MEMORY_BASIC_INFORMATION mbi;
DWORD res = VirtualQuery(pAddress, &mbi, sizeof(mbi));
if (res != sizeof(mbi))
{
cerr << "VirtualQuery failed!" << endl;
return -1;
}
if (mbi.State == MEM_COMMIT)
{
DWORD base = (DWORD)mbi.BaseAddress;
cout << hex << showbase << base << " - " << base + mbi.RegionSize-1 << endl;
}
pAddress += mbi.RegionSize;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment