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

Function QueryMemoryRegions

RedEdrShared/process_query.cpp:441–480  ·  view source on GitHub ↗

Unused, produces a lot of data

Source from the content-addressed store, hash-verified

439
440// Unused, produces a lot of data
441bool QueryMemoryRegions(HANDLE hProcess) {
442 MEMORY_BASIC_INFORMATION mbi;
443 PVOID address = 0;
444 SIZE_T returnLength = 0;
445 char buf[DATA_BUFFER_SIZE];
446
447 int c = 0, cc = 0;
448 while (NtQueryVirtualMemory(hProcess, address, MemoryBasicInformation, &mbi, sizeof(mbi), &returnLength) == 0) {
449 if (mbi.Type == 0 || mbi.Protect == 0 || mbi.State != MEM_COMMIT) {
450 address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);
451 continue;
452 }
453 // skip IMAGE regions
454 //if (mbi.Type == MEM_IMAGE) {
455 if (mbi.Type != MEM_PRIVATE) {
456 address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);
457 continue;
458 }
459
460 //printf("addr:%p;size:%zu;state:0x%lx;protect:0x%lx;type:0x%lx\n",
461 // mbi.BaseAddress, mbi.RegionSize, mbi.State, mbi.Protect, mbi.Type);
462
463 //printf("addr:%p;size:%zu;protect:0x%lx;type:0x%lx\n",
464 // mbi.BaseAddress, mbi.RegionSize, mbi.Protect, mbi.Type);
465
466 sprintf_s(buf, sizeof(buf), "addr:%p;size:%zu;protect:0x%lx;",
467 mbi.BaseAddress, mbi.RegionSize, mbi.Protect);
468 c += (int)strlen(buf);
469 cc += 1;
470 printf("%s\n", buf);
471
472 //printf("Protection: ");
473 //PrintProtectionFlags(mbi.Protect);
474 address = (PVOID)((ULONG_PTR)mbi.BaseAddress + mbi.RegionSize);
475 }
476
477 printf("Len bytes: %i lines: %i\n", c, cc);
478
479 return TRUE;
480}
481
482
483// Utils

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected