MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / GetModuleList

Method GetModuleList

Source/Client/NM_Engine/IModuleScanner.cpp:506–614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

504
505
506std::vector < std::shared_ptr <SModuleEnumContext> > IScanner::GetModuleList(HANDLE hProcess)
507{
508 auto vOutput = std::vector < std::shared_ptr <SModuleEnumContext> >();
509 auto iModuleCount = 0;
510 auto iRetryCount = 0;
511
512 auto szProcessName = CProcessFunctions::GetProcessName(hProcess);
513 if (szProcessName.empty())
514 {
515 SCANNER_LOG(LL_ERR, "Process name read fail! Target process: %p Error: %u", hProcess, g_winapiApiTable->GetLastError());
516 return vOutput;
517 }
518
519 if (g_nmApp->FunctionsInstance()->IsWow64Process(NtCurrentProcess))
520 {
521 auto ntStat = DWORD64(0x0);
522 PROCESS_BASIC_INFORMATION_WOW64 pPBI = { 0 };
523 ntStat = g_winapiApiTable->NtWow64QueryInformationProcess64(hProcess, ProcessBasicInformation, &pPBI, sizeof(pPBI), NULL);
524 if (!NT_SUCCESS(ntStat))
525 {
526 SCANNER_LOG(LL_ERR, "NtWow64QueryInformationProcess64(ProcessBasicInformation) fail! Target process: %p Status: %p", hProcess, ntStat);
527 return vOutput;
528 }
529
530 PEB64 pPEB = { 0 };
531 SIZE_T ulReadBytes;
532 ntStat = ReadProcessMemory64(hProcess, (DWORD64)pPBI.PebBaseAddress, &pPEB, sizeof(pPEB), &ulReadBytes);
533 if (!NT_SUCCESS(ntStat))
534 {
535 SCANNER_LOG(LL_ERR, "ReadProcessMemory64(1) fail! Target process: %p Status: %p", hProcess, ntStat);
536 return vOutput;
537 }
538
539 if (!pPEB.Ldr)
540 {
541 SCANNER_LOG(LL_ERR, "Peb Loader data is null!");
542 return vOutput;
543 }
544
545 PEB_LDR_DATA64 pPebLdrData = { 0 };
546 ntStat = ReadProcessMemory64(hProcess, (DWORD64)pPEB.Ldr, &pPebLdrData, sizeof(pPebLdrData), &ulReadBytes);
547 if (!NT_SUCCESS(ntStat))
548 {
549 SCANNER_LOG(LL_ERR, "ReadProcessMemory64(2) fail! Target process: %p Status: %p", hProcess, ntStat);
550 return vOutput;
551 }
552
553 auto Head = pPebLdrData.InLoadOrderModuleList.Flink;
554 auto Node = Head;
555
556 Head -= sizeof(LIST_ENTRY64);
557
558 do
559 {
560 LDR_DATA_TABLE_ENTRY64 pCurrModule = { 0 };
561 ntStat = ReadProcessMemory64(hProcess, (DWORD64)Node, &pCurrModule, sizeof(pCurrModule), NULL);
562 if (NT_SUCCESS(ntStat))
563 {

Callers

nothing calls this directly

Calls 3

ReadProcessMemory64Function · 0.85
IsWow64ProcessMethod · 0.80
FunctionsInstanceMethod · 0.80

Tested by

no test coverage detected