Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HMODULE getRemoteModule(HANDLE proc, TCHAR *moduleName)
- {
- if (proc == NULL) { return NULL; }
- HMODULE psapi;
- psapi = LoadLibrary(L"psapi");
- _EnumProcessModules EPM;
- EPM = (_EnumProcessModules)GetProcAddress(psapi, "EnumProcessModules");
- if (EPM == NULL) { FreeLibrary(psapi); return NULL; }
- _GetModuleFileNameExW GMFNEXW;
- GMFNEXW = (_GetModuleFileNameExW)GetProcAddress(psapi, "GetModuleFileNameExW");
- if (GMFNEXW == NULL) { FreeLibrary(psapi); return NULL; }
- TCHAR currModuleName[MAX_PATH];
- HMODULE modules[256];
- DWORD cbNeeded;
- UINT idx;
- if (EPM(proc, modules, sizeof(modules), &cbNeeded))
- {
- for (idx = 0; idx < (cbNeeded / sizeof(HMODULE)); idx++)
- {
- if (GMFNEXW(proc, modules[idx], currModuleName, sizeof(moduleName) / sizeof(TCHAR)))
- {
- if (lstrcmpW(moduleName, currModuleName) == 0)
- {
- FreeLibrary(psapi);
- return modules[idx];
- }
- }
- }
- }
- FreeLibrary(psapi);
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement