Skip to content

Instantly share code, notes, and snippets.

@Autoplay1999
Last active November 8, 2019 16:04
Show Gist options
  • Save Autoplay1999/2efe2245e14fe2dcd742c3d7058555b1 to your computer and use it in GitHub Desktop.
Save Autoplay1999/2efe2245e14fe2dcd742c3d7058555b1 to your computer and use it in GitHub Desktop.
#include <Windows.h>
#include <iostream>
int main()
{
MEMORY_BASIC_INFORMATION memBasicInfo;
DWORD64 curAddress = 0;
HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
RtlSecureZeroMemory( &memBasicInfo, sizeof( MEMORY_BASIC_INFORMATION ) );
while ( VirtualQuery( ( LPCVOID )( ULONG_PTR )curAddress, &memBasicInfo, sizeof( MEMORY_BASIC_INFORMATION ) ) )
{
if ( memBasicInfo.State != MEM_COMMIT || memBasicInfo.Protect & ( PAGE_NOACCESS | PAGE_GUARD | PAGE_NOCACHE | PAGE_WRITECOMBINE ) || memBasicInfo.AllocationProtect & ( PAGE_NOACCESS ) )
SetConsoleTextAttribute( hConsole, 12 );
else
SetConsoleTextAttribute( hConsole, 10 );
std::cout << "Base Address: " << memBasicInfo.BaseAddress << std::endl;
std::cout << "Allocation Base: " << memBasicInfo.AllocationBase << std::endl;
switch ( memBasicInfo.AllocationProtect )
{
case PAGE_NOACCESS:
std::cout << "Allocation Protect: No Access" << std::endl;
break;
case PAGE_READONLY:
std::cout << "Allocation Protect: Read" << std::endl;
break;
case PAGE_READWRITE:
std::cout << "Allocation Protect: Read+Write" << std::endl;
break;
case ( PAGE_GUARD | PAGE_READWRITE ):
std::cout << "Allocation Protect: Read+Write+Guard" << std::endl;
break;
case PAGE_WRITECOPY:
std::cout << "Allocation Protect: Write Copy" << std::endl;
break;
case PAGE_EXECUTE:
std::cout << "Allocation Protect: Execute" << std::endl;
break;
case PAGE_EXECUTE_READ:
std::cout << "Allocation Protect: Execute+Read" << std::endl;
break;
case PAGE_EXECUTE_READWRITE:
std::cout << "Allocation Protect: Execute+Read+Write" << std::endl;
break;
case PAGE_EXECUTE_WRITECOPY:
std::cout << "Allocation Protect: Execute+Write Copy" << std::endl;
break;
default:
std::cout << "Allocation Protect: -" << std::endl;
break;
}
switch ( memBasicInfo.State )
{
case MEM_FREE:
std::cout << "State: Free" << std::endl;
break;
case MEM_RESERVE:
std::cout << "State: Reserve" << std::endl;
break;
case MEM_COMMIT:
std::cout << "State: Commit" << std::endl;
break;
default:
std::cout << "State: -" << std::endl;
break;
}
switch ( memBasicInfo.Protect )
{
case PAGE_NOACCESS:
std::cout << "Protect: No Access" << std::endl;
break;
case PAGE_READONLY:
std::cout << "Protect: Read" << std::endl;
break;
case PAGE_READWRITE:
std::cout << "Protect: Read+Write" << std::endl;
break;
case ( PAGE_GUARD | PAGE_READWRITE ):
std::cout << "Protect: Read+Write+Guard" << std::endl;
break;
case PAGE_WRITECOPY:
std::cout << "Protect: Write Copy" << std::endl;
break;
case PAGE_EXECUTE:
std::cout << "Protect: Execute" << std::endl;
break;
case PAGE_EXECUTE_READ:
std::cout << "Protect: Execute+Read" << std::endl;
break;
case PAGE_EXECUTE_READWRITE:
std::cout << "Protect: Execute+Read+Write" << std::endl;
break;
case PAGE_EXECUTE_WRITECOPY:
std::cout << "Protect: Execute+Write Copy" << std::endl;
break;
default:
std::cout << "Protect: -" << std::endl;
break;
}
switch ( memBasicInfo.Type )
{
case MEM_PRIVATE:
std::cout << "Type: Private" << std::endl;
break;
case MEM_IMAGE:
std::cout << "Type: Image" << std::endl;
break;
case MEM_MAPPED:
std::cout << "Type: Mapped" << std::endl;
break;
default:
std::cout << "Type: -" << std::endl;
break;
}
std::cout << "Size: " << ( PVOID )memBasicInfo.RegionSize << std::endl << std::endl;
curAddress += ( DWORD64 )memBasicInfo.RegionSize ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment