MCPcopy Create free account
hub / github.com/dobin/RedEdr / EnumerateMemoryRegions

Function EnumerateMemoryRegions

RedTest/redtest.cpp:80–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void EnumerateMemoryRegions() {
81 printf("\n=== MEMORY REGIONS ===\n\n");
82 printf("%-18s %-18s %-10s %-8s %-8s %-10s\n",
83 "Base Address", "Region Size", "State", "Protect", "Type", "Alloc Protect");
84 printf("================================================================================\n");
85
86 MEMORY_BASIC_INFORMATION mbi = { 0 };
87 LPVOID address = NULL;
88 SIZE_T totalCommitted = 0;
89 SIZE_T totalReserved = 0;
90 int regionCount = 0;
91
92 while (VirtualQuery(address, &mbi, sizeof(mbi)) == sizeof(mbi)) {
93 if (mbi.State != MEM_FREE) {
94 printf("0x%016p 0x%016zx %-10s %-8s %-8s %-10s\n",
95 mbi.BaseAddress,
96 mbi.RegionSize,
97 GetStateString(mbi.State),
98 GetProtectionString(mbi.Protect),
99 GetTypeString(mbi.Type),
100 GetProtectionString(mbi.AllocationProtect));
101
102 if (mbi.State == MEM_COMMIT) {
103 totalCommitted += mbi.RegionSize;
104 }
105 if (mbi.State == MEM_RESERVE) {
106 totalReserved += mbi.RegionSize;
107 }
108 regionCount++;
109 }
110
111 address = (LPVOID)((SIZE_T)mbi.BaseAddress + mbi.RegionSize);
112 }
113
114 printf("================================================================================\n");
115 printf("Total regions: %d\n", regionCount);
116 printf("Total committed: %zu bytes (%.2f MB)\n", totalCommitted, totalCommitted / (1024.0 * 1024.0));
117 printf("Total reserved: %zu bytes (%.2f MB)\n", totalReserved, totalReserved / (1024.0 * 1024.0));
118 printf("\n");
119}
120
121void PrintMemorySegments() {
122 printf("\n=== MEMORY SEGMENTS ===\n\n");

Callers 1

mainFunction · 0.85

Calls 3

GetStateStringFunction · 0.85
GetProtectionStringFunction · 0.85
GetTypeStringFunction · 0.85

Tested by

no test coverage detected