| 47 | }; |
| 48 | |
| 49 | inline HMODULE CustomGetModuleHandle(const std::string & szModule) |
| 50 | { |
| 51 | HMODULE hModule = NULL; |
| 52 | auto pPEB = GetCurrentPEB(); |
| 53 | auto CurrentEntry = pPEB->LoaderData->InLoadOrderModuleList.Flink; |
| 54 | |
| 55 | DEBUG_LOG(LL_TRACE, "\t[*] Searching for loaded module: %s", szModule.c_str()); |
| 56 | |
| 57 | while (CurrentEntry != &pPEB->LoaderData->InLoadOrderModuleList && CurrentEntry != NULL) |
| 58 | { |
| 59 | auto Current = CONTAINING_RECORD(CurrentEntry, _LDR_MODULE, InLoadOrderModuleList); |
| 60 | |
| 61 | std::wstring wszCurrentModuleFullName(Current->FullDllName.Buffer, Current->FullDllName.Length / 2); |
| 62 | std::string szCurrentModuleFullName(wszCurrentModuleFullName.begin(), wszCurrentModuleFullName.end()); |
| 63 | |
| 64 | if (strcmp(szCurrentModuleFullName.c_str(), szModule.c_str()) == 0) |
| 65 | { |
| 66 | DEBUG_LOG(LL_TRACE, "Found in memory: %p", Current->BaseAddress); |
| 67 | hModule = (HMODULE)Current->BaseAddress; |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | CurrentEntry = CurrentEntry->Flink; |
| 72 | } |
| 73 | |
| 74 | if (!hModule) |
| 75 | hModule = g_winapiApiTable->LoadLibraryA(szModule.c_str()); |
| 76 | |
| 77 | if (!hModule) |
| 78 | { |
| 79 | DEBUG_LOG(LL_ERR, "Module can not loaded: %s", szModule.c_str()); |
| 80 | return hModule; |
| 81 | } |
| 82 | |
| 83 | return hModule; |
| 84 | } |
| 85 | |
| 86 | inline FARPROC WINAPI CustomGetProcAddress(const HMODULE hModule, PCSTR lpProcName) |
| 87 | { |
no test coverage detected