MCPcopy Create free account
hub / github.com/DFHack/dfhack / getMemRanges

Method getMemRanges

library/Process.cpp:501–598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499}
500
501void Process::getMemRanges(vector<t_memrange>& ranges)
502{
503 MEMORY_BASIC_INFORMATION MBI;
504 //map<char *, unsigned int> heaps;
505 uint64_t movingStart = 0;
506 PVOID LastAllocationBase = 0;
507 map <char*, string> nameMap;
508 map <string, string> dosDrives;
509
510 // get page size
511 SYSTEM_INFO si;
512 GetSystemInfo(&si);
513 uint64_t PageSize = si.dwPageSize;
514
515 // get dos drive names
516 GetDosNames(dosDrives);
517
518 ranges.clear();
519
520 HANDLE my_handle = GetCurrentProcess();
521
522 // enumerate heaps
523 // HeapNodes(d->my_pid, heaps);
524 // go through all the VM regions, convert them to our internal format
525 while (VirtualQueryEx(my_handle, (const void*)(movingStart), &MBI, sizeof(MBI)) == sizeof(MBI))
526 {
527 t_memrange temp;
528 movingStart = ((uint64_t)MBI.BaseAddress + MBI.RegionSize);
529 if (movingStart % PageSize != 0)
530 movingStart = (movingStart / PageSize + 1) * PageSize;
531
532 // Skip unallocated address space
533 if (MBI.State & MEM_FREE)
534 continue;
535
536 // Find range and permissions
537 memset(&temp, 0, sizeof(temp));
538
539 temp.start = (char*)MBI.BaseAddress;
540 temp.end = ((char*)MBI.BaseAddress + (uint64_t)MBI.RegionSize);
541 temp.valid = true;
542
543 if (!(MBI.State & MEM_COMMIT))
544 temp.valid = false; // reserved address space
545 else if (MBI.Protect & PAGE_EXECUTE)
546 temp.execute = true;
547 else if (MBI.Protect & PAGE_EXECUTE_READ)
548 temp.execute = temp.read = true;
549 else if (MBI.Protect & PAGE_EXECUTE_READWRITE)
550 temp.execute = temp.read = temp.write = true;
551 else if (MBI.Protect & PAGE_EXECUTE_WRITECOPY)
552 temp.execute = temp.read = temp.write = true;
553 else if (MBI.Protect & PAGE_READONLY)
554 temp.read = true;
555 else if (MBI.Protect & PAGE_READWRITE)
556 temp.read = temp.write = true;
557 else if (MBI.Protect & PAGE_WRITECOPY)
558 temp.read = temp.write = true;

Callers 6

ParseVersionMethod · 0.80
verifyAccessMethod · 0.80
internal_getMemRangesFunction · 0.80
memviewFunction · 0.80
getRangesFunction · 0.80
CheckerMethod · 0.80

Calls 7

GetDosNamesFunction · 0.85
clearMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected