ReactOS 0.4.15-dev-7907-g95bf896
ignoreloadlib.c File Reference
#include <ntstatus.h>
#include <windows.h>
#include <ntndk.h>
#include "wine/test.h"
#include "appshim_apitest.h"
Include dependency graph for ignoreloadlib.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef HMODULE(WINAPILOADLIBRARYAPROC) (LPCSTR lpLibFileName)
 
typedef HMODULE(WINAPILOADLIBRARYWPROC) (LPCWSTR lpLibFileName)
 
typedef HMODULE(WINAPILOADLIBRARYEXAPROC) (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 
typedef HMODULE(WINAPILOADLIBRARYEXWPROC) (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 

Functions

UINT WINAPI GetErrorMode (VOID)
 
static HMODULE WINAPI my_LoadLibraryA (PCSTR Name)
 
static HMODULE WINAPI my_LoadLibraryExA (PCSTR Name, HANDLE hFile, DWORD dwFlags)
 
static HMODULE WINAPI my_LoadLibraryW (PCWSTR Name)
 
static HMODULE WINAPI my_LoadLibraryExW (PCWSTR Name, HANDLE hFile, DWORD dwFlags)
 
static void test_LoadLibraryA (PHOOKAPI hook)
 
static void test_LoadLibraryW (PHOOKAPI hook)
 
static void test_LoadLibraryExA (PHOOKAPI hook)
 
static void test_LoadLibraryExW (PHOOKAPI hook)
 
DWORD get_host_winver (void)
 
 START_TEST (ignoreloadlib)
 

Variables

static DWORD g_WinVersion
 
static tGETHOOKAPIS pGetHookAPIs
 
static HMODULE g_hSentinelModule = (HMODULE)&pGetHookAPIs
 
static HMODULE g_h123 = (HMODULE)123
 
static HMODULE g_h111 = (HMODULE)111
 
static HMODULE g_h0 = (HMODULE)0
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file ignoreloadlib.c.

Typedef Documentation

◆ LOADLIBRARYAPROC

typedef HMODULE(WINAPI * LOADLIBRARYAPROC) (LPCSTR lpLibFileName)

Definition at line 23 of file ignoreloadlib.c.

◆ LOADLIBRARYEXAPROC

typedef HMODULE(WINAPI * LOADLIBRARYEXAPROC) (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)

Definition at line 25 of file ignoreloadlib.c.

◆ LOADLIBRARYEXWPROC

typedef HMODULE(WINAPI * LOADLIBRARYEXWPROC) (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)

Definition at line 26 of file ignoreloadlib.c.

◆ LOADLIBRARYWPROC

typedef HMODULE(WINAPI * LOADLIBRARYWPROC) (LPCWSTR lpLibFileName)

Definition at line 24 of file ignoreloadlib.c.

Function Documentation

◆ get_host_winver()

DWORD get_host_winver ( void  )

Definition at line 796 of file data.c.

797{
798 if (!g_WinVersion)
799 {
800 RTL_OSVERSIONINFOEXW rtlinfo = {0};
801 void (__stdcall* pRtlGetVersion)(RTL_OSVERSIONINFOEXW*);
802 pRtlGetVersion = (void (__stdcall*)(RTL_OSVERSIONINFOEXW*))GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
803
804 rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo);
805 pRtlGetVersion(&rtlinfo);
806 g_WinVersion = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
807 }
808 return g_WinVersion;
809}
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
DWORD g_WinVersion
Definition: data.c:795
ULONG dwMajorVersion
Definition: rtltypes.h:270
ULONG dwMinorVersion
Definition: rtltypes.h:271
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:269
#define __stdcall
Definition: typedefs.h:25

Referenced by START_TEST().

◆ GetErrorMode()

UINT WINAPI GetErrorMode ( VOID  )

Definition at line 31 of file ignoreloadlib.c.

32{
34 UINT ErrMode;
35
36 /* Query the current setting */
39 &ErrMode,
40 sizeof(ErrMode),
41 NULL);
42 if (!NT_SUCCESS(Status))
43 {
44 /* Fail if we couldn't query */
45 return 0;
46 }
47
48 /* Check if NOT failing critical errors was requested */
49 if (ErrMode & SEM_FAILCRITICALERRORS)
50 {
51 /* Mask it out, since the native API works differently */
52 ErrMode &= ~SEM_FAILCRITICALERRORS;
53 }
54 else
55 {
56 /* OR it if the caller didn't, due to different native semantics */
57 ErrMode |= SEM_FAILCRITICALERRORS;
58 }
59
60 /* Return the mode */
61 return ErrMode;
62}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
@ ProcessDefaultHardErrorMode
Definition: winternl.h:868
unsigned int UINT
Definition: ndis.h:50
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59

Referenced by my_LoadLibraryA(), my_LoadLibraryExA(), my_LoadLibraryExW(), my_LoadLibraryW(), START_TEST(), test_LoadLibraryA(), test_LoadLibraryExA(), test_LoadLibraryExW(), and test_LoadLibraryW().

◆ my_LoadLibraryA()

static HMODULE WINAPI my_LoadLibraryA ( PCSTR  Name)
static

Definition at line 64 of file ignoreloadlib.c.

65{
66 DWORD dwErrorMode = GetErrorMode();
68 "Unexpected error mode: 0x%x\n", dwErrorMode);
69 return g_hSentinelModule;
70}
#define ok(value,...)
Definition: atltest.h:57
unsigned long DWORD
Definition: ntddk_ex.h:95
static HMODULE g_hSentinelModule
Definition: ignoreloadlib.c:18
UINT WINAPI GetErrorMode(VOID)
Definition: ignoreloadlib.c:31
#define SEM_NOGPFAULTERRORBOX
Definition: rtltypes.h:70
#define SEM_NOOPENFILEERRORBOX
Definition: rtltypes.h:72

Referenced by test_LoadLibraryA().

◆ my_LoadLibraryExA()

static HMODULE WINAPI my_LoadLibraryExA ( PCSTR  Name,
HANDLE  hFile,
DWORD  dwFlags 
)
static

Definition at line 72 of file ignoreloadlib.c.

73{
74 DWORD dwErrorMode = GetErrorMode();
76 "Unexpected error mode: 0x%x\n", dwErrorMode);
77 return g_hSentinelModule;
78}

Referenced by test_LoadLibraryExA().

◆ my_LoadLibraryExW()

static HMODULE WINAPI my_LoadLibraryExW ( PCWSTR  Name,
HANDLE  hFile,
DWORD  dwFlags 
)
static

Definition at line 88 of file ignoreloadlib.c.

89{
90 DWORD dwErrorMode = GetErrorMode();
92 "Unexpected error mode: 0x%x\n", dwErrorMode);
93 return g_hSentinelModule;
94}

Referenced by test_LoadLibraryExW().

◆ my_LoadLibraryW()

static HMODULE WINAPI my_LoadLibraryW ( PCWSTR  Name)
static

Definition at line 80 of file ignoreloadlib.c.

81{
82 DWORD dwErrorMode = GetErrorMode();
84 "Unexpected error mode: 0x%x\n", dwErrorMode);
85 return g_hSentinelModule;
86}

Referenced by test_LoadLibraryW().

◆ START_TEST()

START_TEST ( ignoreloadlib  )

Definition at line 244 of file ignoreloadlib.c.

245{
246 DWORD num_shims = 0, n, dwErrorMode;
248
250
252 pGetHookAPIs = LoadShimDLL2(L"aclayers.dll");
253 else
254 pGetHookAPIs = LoadShimDLL2(L"acgenral.dll");
255
256 if (!pGetHookAPIs)
257 {
258 skip("GetHookAPIs not found\n");
259 return;
260 }
261
262 hook = pGetHookAPIs("test123.dll:123;test111:111;Something.mark:0;empty", L"IgnoreLoadLibrary", &num_shims);
263
264 ok(hook != NULL, "Expected hook to be a valid pointer\n");
265 ok(num_shims == 4, "Expected num_shims to be 0, was: %u\n", num_shims);
266
267 if (!hook || num_shims != 4)
268 return;
269
270 dwErrorMode = GetErrorMode();
271 trace("Error mode: 0x%x\n", dwErrorMode);
272
273 for (n = 0; n < num_shims; ++n)
274 {
275 ok_str(hook[n].LibraryName, "KERNEL32.DLL");
276 if (!_stricmp(hook[n].FunctionName, "LoadLibraryA"))
277 {
278 ok_int(n, 0);
280 }
281 else if (!_stricmp(hook[n].FunctionName, "LoadLibraryExA"))
282 {
283 ok_int(n, 1);
285 }
286 else if (!_stricmp(hook[n].FunctionName, "LoadLibraryW"))
287 {
288 ok_int(n, 2);
290 }
291 else if (!_stricmp(hook[n].FunctionName, "LoadLibraryExW"))
292 {
293 ok_int(n, 3);
295 }
296 else
297 {
298 ok(0, "Unknown function %s\n", hook[n].FunctionName);
299 }
300 }
301}
@ hook
Definition: SystemMenu.c:35
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char * FunctionName
Definition: acpixf.h:1279
tGETHOOKAPIS LoadShimDLL2(PCWSTR ShimDll)
Definition: versionlie.c:369
#define trace
Definition: atltest.h:70
#define ok_str(x, y)
Definition: atltest.h:127
#define skip(...)
Definition: atltest.h:64
#define ok_int(expression, result)
Definition: atltest.h:134
#define _stricmp
Definition: cat.c:22
GLdouble n
Definition: glext.h:7729
DWORD get_host_winver(void)
Definition: data.c:796
static void test_LoadLibraryA(PHOOKAPI hook)
Definition: ignoreloadlib.c:97
static void test_LoadLibraryExW(PHOOKAPI hook)
static void test_LoadLibraryW(PHOOKAPI hook)
static DWORD g_WinVersion
Definition: ignoreloadlib.c:16
static void test_LoadLibraryExA(PHOOKAPI hook)
static tGETHOOKAPIS pGetHookAPIs
Definition: ignoreloadlib.c:17
#define L(x)
Definition: ntvdm.h:50
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29

◆ test_LoadLibraryA()

static void test_LoadLibraryA ( PHOOKAPI  hook)
static

Definition at line 97 of file ignoreloadlib.c.

98{
100 DWORD dwErrorMode, dwOldErrorMode;
101
102 hook->OriginalFunction = my_LoadLibraryA;
103 proc = hook->ReplacementFunction;
104
105 dwOldErrorMode = GetErrorMode();
106
107 /* Exact names return what is specified */
108 ok_ptr(proc("test123.dll"), g_h123);
109 ok_ptr(proc("test111"), g_h111);
110 /* Extension is not added */
111 ok_ptr(proc("test111.dll"), g_hSentinelModule);
112 /* Zero can be specified */
113 ok_ptr(proc("Something.mark"), g_h0);
114 /* Or default returned */
115 ok_ptr(proc("empty"), g_h0);
116
117 /* Paths, do not have to be valid */
118 ok_ptr(proc("\\test123.dll"), g_h123);
119 ok_ptr(proc("/test123.dll"), g_h123);
120 ok_ptr(proc("\\\\\\\\test123.dll"), g_h123);
121 ok_ptr(proc("////test123.dll"), g_h123);
122 ok_ptr(proc("mypath:something\\does\\not\\matter\\test123.dll"), g_h123);
123 ok_ptr(proc("/put/whatever/you/want/here/test123.dll"), g_h123);
124
125 /* path separator is checked, not just any point in the path */
126 ok_ptr(proc("-test123.dll"), g_hSentinelModule);
127 ok_ptr(proc("test123.dll-"), g_hSentinelModule);
128
129 dwErrorMode = GetErrorMode();
130 ok(dwErrorMode == dwOldErrorMode, "ErrorMode changed, was 0x%x, is 0x%x\n", dwOldErrorMode, dwErrorMode);
131}
#define ok_ptr(expression, result)
Definition: atltest.h:108
static HMODULE g_h111
Definition: ignoreloadlib.c:20
static HMODULE WINAPI my_LoadLibraryA(PCSTR Name)
Definition: ignoreloadlib.c:64
HMODULE(WINAPI * LOADLIBRARYAPROC)(LPCSTR lpLibFileName)
Definition: ignoreloadlib.c:23
static HMODULE g_h0
Definition: ignoreloadlib.c:21
static HMODULE g_h123
Definition: ignoreloadlib.c:19
static HANDLE proc()
Definition: pdb.c:34

Referenced by START_TEST().

◆ test_LoadLibraryExA()

static void test_LoadLibraryExA ( PHOOKAPI  hook)
static

Definition at line 169 of file ignoreloadlib.c.

170{
172 DWORD dwErrorMode, dwOldErrorMode;
173
174 hook->OriginalFunction = my_LoadLibraryExA;
175 proc = hook->ReplacementFunction;
176
177 dwOldErrorMode = GetErrorMode();
178
179 /* Exact names return what is specified */
180 ok_ptr(proc("test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
181 ok_ptr(proc("test111", INVALID_HANDLE_VALUE, 0), g_h111);
182 /* Extension is not added */
184 /* Zero can be specified */
185 ok_ptr(proc("Something.mark", INVALID_HANDLE_VALUE, 0), g_h0);
186 /* Or default returned */
187 ok_ptr(proc("empty", INVALID_HANDLE_VALUE, 0), g_h0);
188
189 /* Paths, do not have to be valid */
190 ok_ptr(proc("\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
191 ok_ptr(proc("/test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
192 ok_ptr(proc("\\\\\\\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
193 ok_ptr(proc("////test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
194 ok_ptr(proc("mypath:something\\does\\not\\matter\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
195 ok_ptr(proc("/put/whatever/you/want/here/test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
196
197 /* path separator is checked, not just any point in the path */
200
201 dwErrorMode = GetErrorMode();
202 ok(dwErrorMode == dwOldErrorMode, "ErrorMode changed, was 0x%x, is 0x%x\n", dwOldErrorMode, dwErrorMode);
203}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HMODULE(WINAPI * LOADLIBRARYEXAPROC)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:25
static HMODULE WINAPI my_LoadLibraryExA(PCSTR Name, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:72

Referenced by START_TEST().

◆ test_LoadLibraryExW()

static void test_LoadLibraryExW ( PHOOKAPI  hook)
static

Definition at line 205 of file ignoreloadlib.c.

206{
208 DWORD dwErrorMode, dwOldErrorMode;
209
210 hook->OriginalFunction = my_LoadLibraryExW;
211 proc = hook->ReplacementFunction;
212
213 dwOldErrorMode = GetErrorMode();
214
215 /* Exact names return what is specified */
216 ok_ptr(proc(L"test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
217 ok_ptr(proc(L"test111", INVALID_HANDLE_VALUE, 0), g_h111);
218 /* Extension is not added */
220 /* Zero can be specified */
221 ok_ptr(proc(L"Something.mark", INVALID_HANDLE_VALUE, 0), g_h0);
222 /* Or default returned */
223 ok_ptr(proc(L"empty", INVALID_HANDLE_VALUE, 0), g_h0);
224
225 /* Paths, do not have to be valid */
226 ok_ptr(proc(L"\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
227 ok_ptr(proc(L"/test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
228 ok_ptr(proc(L"\\\\\\\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
229 ok_ptr(proc(L"////test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
230 ok_ptr(proc(L"mypath:something\\does\\not\\matter\\test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
231 ok_ptr(proc(L"/put/whatever/you/want/here/test123.dll", INVALID_HANDLE_VALUE, 0), g_h123);
232
233 /* path separator is checked, not just any point in the path */
236
237 dwErrorMode = GetErrorMode();
238 ok(dwErrorMode == dwOldErrorMode, "ErrorMode changed, was 0x%x, is 0x%x\n", dwOldErrorMode, dwErrorMode);
239}
static HMODULE WINAPI my_LoadLibraryExW(PCWSTR Name, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:88
HMODULE(WINAPI * LOADLIBRARYEXWPROC)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:26

Referenced by START_TEST().

◆ test_LoadLibraryW()

static void test_LoadLibraryW ( PHOOKAPI  hook)
static

Definition at line 133 of file ignoreloadlib.c.

134{
136 DWORD dwErrorMode, dwOldErrorMode;
137
138 hook->OriginalFunction = my_LoadLibraryW;
139 proc = hook->ReplacementFunction;
140
141 dwOldErrorMode = GetErrorMode();
142
143 /* Exact names return what is specified */
144 ok_ptr(proc(L"test123.dll"), g_h123);
145 ok_ptr(proc(L"test111"), g_h111);
146 /* Extension is not added */
147 ok_ptr(proc(L"test111.dll"), g_hSentinelModule);
148 /* Zero can be specified */
149 ok_ptr(proc(L"Something.mark"), g_h0);
150 /* Or default returned */
151 ok_ptr(proc(L"empty"), g_h0);
152
153 /* Paths, do not have to be valid */
154 ok_ptr(proc(L"\\test123.dll"), g_h123);
155 ok_ptr(proc(L"/test123.dll"), g_h123);
156 ok_ptr(proc(L"\\\\\\\\test123.dll"), g_h123);
157 ok_ptr(proc(L"////test123.dll"), g_h123);
158 ok_ptr(proc(L"mypath:something\\does\\not\\matter\\test123.dll"), g_h123);
159 ok_ptr(proc(L"/put/whatever/you/want/here/test123.dll"), g_h123);
160
161 /* path separator is checked, not just any point in the path */
162 ok_ptr(proc(L"-test123.dll"), g_hSentinelModule);
163 ok_ptr(proc(L"test123.dll-"), g_hSentinelModule);
164
165 dwErrorMode = GetErrorMode();
166 ok(dwErrorMode == dwOldErrorMode, "ErrorMode changed, was 0x%x, is 0x%x\n", dwOldErrorMode, dwErrorMode);
167}
HMODULE(WINAPI * LOADLIBRARYWPROC)(LPCWSTR lpLibFileName)
Definition: ignoreloadlib.c:24
static HMODULE WINAPI my_LoadLibraryW(PCWSTR Name)
Definition: ignoreloadlib.c:80

Referenced by START_TEST().

Variable Documentation

◆ g_h0

HMODULE g_h0 = (HMODULE)0
static

◆ g_h111

HMODULE g_h111 = (HMODULE)111
static

◆ g_h123

HMODULE g_h123 = (HMODULE)123
static

◆ g_hSentinelModule

◆ g_WinVersion

DWORD g_WinVersion
static

Definition at line 16 of file ignoreloadlib.c.

Referenced by START_TEST().

◆ pGetHookAPIs

tGETHOOKAPIS pGetHookAPIs
static

Definition at line 17 of file ignoreloadlib.c.

Referenced by START_TEST().