Memory, is a complex module in Programing, especially on Windows.
This time, I use cpp with win windows api{
VirtualQueryEx(); //Get the available memory page(block)
ReadProcessMemory(); //Read the specific memory
LookupPrivilegeValue(); //Get the avalible Privileges in windows
AdjustTokenPrivileges();//Enable or disable privilege for specific process
}
Now, we skip the step of getting privilege, and directly talking about the detail of reading memories.
At first, we should understand that we cannot directly read memory at once by giving a big number of memory required.
Normally, we should make a loop to record the detail of every pages(blocks) of memory [VirtualQueryEx()] and Read them [ReadProcessMemory()].
while (true)
{
if (VirtualQueryEx(hProcess, (LPVOID)cur_addr, &meminf, dwInfoSize) == )
break;
if (!(meminf.State == MEM_COMMIT || meminf.State == MEM_IMAGE || meminf.State == MEM_MAPPED))
{
cur_addr = (DWORD)meminf.BaseAddress + meminf.RegionSize;
continue;
}
if ((dbg = ReadProcessMemory(hProcess, (LPCVOID)meminf.BaseAddress, memget, meminf.RegionSize, &ReadSize)) == false)
cout << "Failed to read memory at address:" << meminf.BaseAddress << endl;
else
memget += meminf.RegionSize;
cur_addr = (DWORD)meminf.BaseAddress + eminf.RegionSize;
}