From 97aa50d4f417443d9ca31cb3f1b821bce600f167 Mon Sep 17 00:00:00 2001 From: vxunderground <57078196+vxunderground@users.noreply.github.com> Date: Fri, 15 Jul 2022 12:14:20 -0500 Subject: [PATCH] Create RfGetModuleHandle.cpp --- Windows API/RfGetModuleHandle.cpp | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Windows API/RfGetModuleHandle.cpp diff --git a/Windows API/RfGetModuleHandle.cpp b/Windows API/RfGetModuleHandle.cpp new file mode 100644 index 0000000..41ea8bd --- /dev/null +++ b/Windows API/RfGetModuleHandle.cpp @@ -0,0 +1,42 @@ +HMODULE RfGetModuleHandleA(LPCSTR lpModuleName) +{ + PPEB Peb = GetPeb(); + PLDR_MODULE Module = NULL; + CHAR wDllName[64] = { 0 }; + + Module = (PLDR_MODULE)((PBYTE)Peb->LoaderData->InMemoryOrderModuleList.Flink - 16); + + while (Module != NULL) + { + Module = (PLDR_MODULE)((PBYTE)Module->InMemoryOrderModuleList.Flink - 16); + if (Module->BaseDllName.Buffer != NULL) + { + RfZeroMemory(wDllName, sizeof(wDllName)); + WCharStringToCharString(wDllName, Module->BaseDllName.Buffer, 64); + if (StringCompareA(lpModuleName, wDllName) == 0) + return (HMODULE)Module->BaseAddress; + } + } + + return NULL; +} + +HMODULE RfGetModuleHandleW(LPCWSTR lpModuleName) +{ + PPEB Peb = GetPeb(); + PLDR_MODULE Module = NULL; + + Module = (PLDR_MODULE)((PBYTE)Peb->LoaderData->InMemoryOrderModuleList.Flink - 16); + + while (Module != NULL) + { + Module = (PLDR_MODULE)((PBYTE)Module->InMemoryOrderModuleList.Flink - 16); + if (Module->BaseDllName.Buffer != NULL) + { + if (StringCompareW(lpModuleName, Module->BaseDllName.Buffer) == 0) + return (HMODULE)Module->BaseAddress; + } + } + + return NULL; +}