BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved ) { BOOL bResult = TRUE; PHookFn hook; LPSTR name; if (dwReason == DLL_PROCESS_ATTACH) { #if defined(_WIN64) || defined(W32ON64) hDllNameType = hDllName - 6 + #endif GetModuleFileName( hInstance, hDllName, lenof(hDllName) ); hDllInstance = hInstance; // save Dll instance handle // Don't hook WriteFile in errout.exe (static load). name = Hooks[lenof(Hooks)-2].name; if (lpReserved != NULL) Hooks[lenof(Hooks)-2].name = NULL; // Get the entry points to the original functions. hKernel = GetModuleHandleA( APIKernel ); for (hook = Hooks; hook->name; ++hook) hook->oldfunc = GetProcAddress( hKernel, hook->name ); bResult = HookAPIAllMod( Hooks, FALSE ); DisableThreadLibraryCalls( hInstance ); Hooks[lenof(Hooks)-2].name = name; #ifdef W32ON64 if (global.hStdOut == NULL) CopyGlobals(); #endif } else if (dwReason == DLL_PROCESS_DETACH) { // Unhook if it's being unloaded, but not if the process is exiting. if (lpReserved == NULL) HookAPIAllMod( Hooks, TRUE ); } return( bResult ); }
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved ) { BOOL bResult = TRUE; HMODULE api; PHookFn hook; if (dwReason == DLL_PROCESS_ATTACH) { hDllInstance = hInstance; // save Dll instance handle DEBUGSTR( L"hDllInstance = %p", hDllInstance ); // Get the entry points to the original functions. hKernel = GetModuleHandleA( APIKernel ); for (hook = Hooks; hook->name; ++hook) { hook->oldfunc = GetProcAddress( hKernel, hook->name ); api = GetModuleHandleA( hook->lib ); if (api) hook->apifunc = GetProcAddress( api, hook->name ); } bResult = HookAPIAllMod( Hooks, FALSE ); OriginalAttr(); DisableThreadLibraryCalls( hInstance ); } else if (dwReason == DLL_PROCESS_DETACH) { if (lpReserved == NULL) { DEBUGSTR( L"Unloading" ); HookAPIAllMod( Hooks, TRUE ); } else { DEBUGSTR( L"Terminating" ); } } return( bResult ); }