HMODULE WINAPI MyLoadLibraryW( LPCWSTR lpFileName ) { HMODULE hMod = LoadLibraryW( lpFileName ); if (hMod && hMod != hKernel) HookAPIOneMod( hMod, Hooks, FALSE ); return hMod; }
BOOL HookAPIAllMod( PHookFn Hooks, BOOL restore ) { HANDLE hModuleSnap; MODULEENTRY32 me; BOOL fOk; // Take a snapshot of all modules in the current process. hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, GetCurrentProcessId() ); if (hModuleSnap == INVALID_HANDLE_VALUE) return FALSE; // Fill the size of the structure before using it. me.dwSize = sizeof(MODULEENTRY32); // Walk the module list of the modules. for (fOk = Module32First( hModuleSnap, &me ); fOk; fOk = Module32Next( hModuleSnap, &me )) { // We don't hook functions in our own module. if (me.hModule != hDllInstance && me.hModule != hKernel) { // Hook this function in this module. if (!HookAPIOneMod( me.hModule, Hooks, restore )) { CloseHandle( hModuleSnap ); return FALSE; } } } CloseHandle( hModuleSnap ); return TRUE; }
HMODULE WINAPI MyLoadLibraryExW( LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags ) { HMODULE hMod = LoadLibraryExW( lpFileName, hFile, dwFlags ); if (hMod && hMod != hKernel && !(dwFlags & LOAD_LIBRARY_AS_DATA)) HookAPIOneMod( hMod, Hooks, FALSE ); return hMod; }
HMODULE WINAPI MyLoadLibraryW( LPCWSTR lpFileName ) { HMODULE hMod = LoadLibraryW( lpFileName ); if (hMod && hMod != hKernel) { DEBUGSTR( L"Hooking in %s (LoadLibraryW)", lpFileName ); HookAPIOneMod( hMod, Hooks, FALSE ); } return hMod; }
HMODULE WINAPI MyLoadLibraryExW( LPCWSTR lpFileName, HANDLE hFile, DWORD dwFlags ) { HMODULE hMod = LoadLibraryExW( lpFileName, hFile, dwFlags ); if (hMod && hMod != hKernel && !(dwFlags & LOAD_LIBRARY_AS_DATAFILE)) { DEBUGSTR( L"Hooking in %s (LoadLibraryExW)", lpFileName ); HookAPIOneMod( hMod, Hooks, FALSE ); } return hMod; }
BOOL HookAPIAllMod( PHookFn Hooks, BOOL restore ) { HANDLE hModuleSnap; MODULEENTRY32 me; BOOL fOk; // Take a snapshot of all modules in the current process. hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, GetCurrentProcessId() ); if (hModuleSnap == INVALID_HANDLE_VALUE) { DEBUGSTR( L"error: %S(%d)", __FILE__, __LINE__ ); return FALSE; } // Fill the size of the structure before using it. me.dwSize = sizeof(MODULEENTRY32); // Walk the module list of the modules. for (fOk = Module32First( hModuleSnap, &me ); fOk; fOk = Module32Next( hModuleSnap, &me )) { // We don't hook functions in our own module. if (me.hModule != hDllInstance && me.hModule != hKernel) { //attempting to ignore NVIDIA 3D wrapper modules that seem to be in conflict on some systems if (_wcsnicmp(me.szModule, L"nvd3d9wrap", 10) == 0) { DEBUGSTR(L"Ignoring %s", me.szModule); continue; } DEBUGSTR( (restore) ? L"Unhooking from %s" : L"Hooking in %s", me.szModule ); // Hook this function in this module. if (!HookAPIOneMod( me.hModule, Hooks, restore )) { CloseHandle( hModuleSnap ); return FALSE; } } } CloseHandle( hModuleSnap ); return TRUE; }