GetModuleInfo - returns a ProcessData::MODULE_DATA* representing the module given `name`. returns nullptr on failure/no module found */
| 777 | returns nullptr on failure/no module found |
| 778 | */ |
| 779 | ProcessData::MODULE_DATA Process::GetModuleInfo(__in const wchar_t* name) |
| 780 | { |
| 781 | if (name == nullptr) |
| 782 | { |
| 783 | Logger::logf(Err, "name was nullptr @ Process::GetModuleInfo"); |
| 784 | return {}; |
| 785 | } |
| 786 | |
| 787 | #ifdef _M_IX86 |
| 788 | MYPEB* peb = (MYPEB*)__readfsdword(0x30); |
| 789 | #else |
| 790 | MYPEB* peb = (MYPEB*)__readgsqword(0x60); |
| 791 | #endif |
| 792 | |
| 793 | uintptr_t kernel32Base = 0; |
| 794 | |
| 795 | LIST_ENTRY* current_record = NULL; |
| 796 | LIST_ENTRY* start = &(peb->Ldr->InLoadOrderModuleList); |
| 797 | |
| 798 | current_record = start->Flink; |
| 799 | |
| 800 | while (true) |
| 801 | { |
| 802 | MY_LDR_DATA_TABLE_ENTRY* module_entry = (MY_LDR_DATA_TABLE_ENTRY*)CONTAINING_RECORD(current_record, MY_LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); |
| 803 | |
| 804 | if (wcscmp(module_entry->BaseDllName.Buffer, name) == 0) |
| 805 | { |
| 806 | ProcessData::MODULE_DATA module; |
| 807 | |
| 808 | module.name = wstring(module_entry->FullDllName.Buffer); |
| 809 | module.baseName = wstring(module_entry->BaseDllName.Buffer); |
| 810 | module.hModule = (HMODULE)module_entry->DllBase; |
| 811 | module.dllInfo.lpBaseOfDll = module_entry->DllBase; |
| 812 | module.dllInfo.SizeOfImage = module_entry->SizeOfImage; |
| 813 | return module; |
| 814 | } |
| 815 | |
| 816 | current_record = current_record->Flink; |
| 817 | |
| 818 | if (current_record == start) |
| 819 | { |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | return {}; |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | GetModuleHandle_Ldr - returns base address of a module as HMODULE type |
nothing calls this directly
no outgoing calls
no test coverage detected