1 /* 2 * PROJECT: ReactOS 'Layers' Shim library 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: IgnoreLoadLibrary shim 5 * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8 #define WIN32_NO_STATUS 9 #include <windef.h> 10 #include <winbase.h> 11 #include <shimlib.h> 12 #include "ntndk.h" 13 14 typedef HMODULE(WINAPI* LOADLIBRARYAPROC)(LPCSTR lpLibFileName); 15 typedef HMODULE(WINAPI* LOADLIBRARYEXAPROC)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); 16 typedef HMODULE(WINAPI* LOADLIBRARYWPROC)(LPCWSTR lpLibFileName); 17 typedef HMODULE(WINAPI* LOADLIBRARYEXWPROC)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); 18 19 20 #define SHIM_NS IgnoreLoadLibrary 21 #include <setup_shim.inl> 22 23 24 HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryA)(LPCSTR lpLibFileName) 25 { 26 HMODULE Module; 27 DWORD dwOldErrorMode; 28 29 dwOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); 30 Module = CALL_SHIM(0, LOADLIBRARYAPROC)(lpLibFileName); 31 SetErrorMode(dwOldErrorMode); 32 33 return Module; 34 } 35 36 HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryExA)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) 37 { 38 HMODULE Module; 39 DWORD dwOldErrorMode; 40 41 dwOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); 42 Module = CALL_SHIM(1, LOADLIBRARYEXAPROC)(lpLibFileName, hFile, dwFlags); 43 SetErrorMode(dwOldErrorMode); 44 45 return Module; 46 } 47 48 HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryW)(LPCWSTR lpLibFileName) 49 { 50 HMODULE Module; 51 DWORD dwOldErrorMode; 52 53 dwOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); 54 Module = CALL_SHIM(2, LOADLIBRARYWPROC)(lpLibFileName); 55 SetErrorMode(dwOldErrorMode); 56 57 return Module; 58 } 59 60 HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryExW)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) 61 { 62 HMODULE Module; 63 DWORD dwOldErrorMode; 64 65 dwOldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); 66 Module = CALL_SHIM(3, LOADLIBRARYEXWPROC)(lpLibFileName, hFile, dwFlags); 67 SetErrorMode(dwOldErrorMode); 68 69 return Module; 70 } 71 72 73 #define SHIM_NUM_HOOKS 4 74 #define SHIM_SETUP_HOOKS \ 75 SHIM_HOOK(0, "KERNEL32.DLL", "LoadLibraryA", SHIM_OBJ_NAME(APIHook_LoadLibraryA)) \ 76 SHIM_HOOK(1, "KERNEL32.DLL", "LoadLibraryExA", SHIM_OBJ_NAME(APIHook_LoadLibraryExA)) \ 77 SHIM_HOOK(2, "KERNEL32.DLL", "LoadLibraryW", SHIM_OBJ_NAME(APIHook_LoadLibraryW)) \ 78 SHIM_HOOK(3, "KERNEL32.DLL", "LoadLibraryExW", SHIM_OBJ_NAME(APIHook_LoadLibraryExW)) 79 80 #include <implement_shim.inl> 81