GetLoadedModules - returns a vector * representing a set of loaded modules in the current process returns nullptr on failure */
| 731 | returns nullptr on failure |
| 732 | */ |
| 733 | std::vector<ProcessData::MODULE_DATA> Process::GetLoadedModules() |
| 734 | { |
| 735 | |
| 736 | #ifdef _M_IX86 |
| 737 | MYPEB* peb = (MYPEB*)__readfsdword(0x30); |
| 738 | #else |
| 739 | MYPEB* peb = (MYPEB*)__readgsqword(0x60); |
| 740 | #endif |
| 741 | |
| 742 | uintptr_t kernel32Base = 0; |
| 743 | |
| 744 | LIST_ENTRY* current_record = NULL; |
| 745 | LIST_ENTRY* start = &(peb->Ldr->InLoadOrderModuleList); |
| 746 | |
| 747 | current_record = start->Flink; |
| 748 | |
| 749 | std::vector<ProcessData::MODULE_DATA> moduleList; |
| 750 | |
| 751 | while (true) |
| 752 | { |
| 753 | MY_LDR_DATA_TABLE_ENTRY* module_entry = (MY_LDR_DATA_TABLE_ENTRY*)CONTAINING_RECORD(current_record, MY_LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); |
| 754 | ProcessData::MODULE_DATA module; |
| 755 | |
| 756 | module.name = wstring(module_entry->FullDllName.Buffer); |
| 757 | module.baseName = wstring(module_entry->BaseDllName.Buffer); |
| 758 | |
| 759 | module.hModule = (HMODULE)module_entry->DllBase; |
| 760 | module.dllInfo.lpBaseOfDll = module_entry->DllBase; |
| 761 | module.dllInfo.SizeOfImage = module_entry->SizeOfImage; |
| 762 | moduleList.push_back(module); |
| 763 | |
| 764 | current_record = current_record->Flink; |
| 765 | |
| 766 | if (current_record == start) |
| 767 | { |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | return moduleList; |
| 773 | } |
| 774 | |
| 775 | /* |
| 776 | GetModuleInfo - returns a ProcessData::MODULE_DATA* representing the module given `name`. |
nothing calls this directly
no outgoing calls
no test coverage detected