ReactOS 0.4.16-dev-237-gd6eebaa
ignoreloadlib.c
Go to the documentation of this file.
1/*
2* PROJECT: appshim_apitest
3* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4* PURPOSE: Tests for IgnoreLoadLibrary shim
5* COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6*/
7
8#include <ntstatus.h>
9#define WIN32_NO_STATUS
10#include <windows.h>
11#include <ntndk.h>
12#include "wine/test.h"
13
14#include "appshim_apitest.h"
15
18static HMODULE g_hSentinelModule = (HMODULE)&pGetHookAPIs; /* Not a valid hmodule, so a nice sentinel */
19static HMODULE g_h123 = (HMODULE)123;
20static HMODULE g_h111 = (HMODULE)111;
21static HMODULE g_h0 = (HMODULE)0;
22
23typedef HMODULE(WINAPI* LOADLIBRARYAPROC)(LPCSTR lpLibFileName);
24typedef HMODULE(WINAPI* LOADLIBRARYWPROC)(LPCWSTR lpLibFileName);
27
28
29UINT
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}
63
65{
66 DWORD dwErrorMode = GetErrorMode();
68 "Unexpected error mode: 0x%x\n", dwErrorMode);
69 return g_hSentinelModule;
70}
71
73{
74 DWORD dwErrorMode = GetErrorMode();
76 "Unexpected error mode: 0x%x\n", dwErrorMode);
77 return g_hSentinelModule;
78}
79
81{
82 DWORD dwErrorMode = GetErrorMode();
84 "Unexpected error mode: 0x%x\n", dwErrorMode);
85 return g_hSentinelModule;
86}
87
89{
90 DWORD dwErrorMode = GetErrorMode();
92 "Unexpected error mode: 0x%x\n", dwErrorMode);
93 return g_hSentinelModule;
94}
95
96
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}
132
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}
168
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}
204
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}
240
241/* versionlie.c */
243
244START_TEST(ignoreloadlib)
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
PHOOKAPI(WINAPI * tGETHOOKAPIS)(LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount)
tGETHOOKAPIS LoadShimDLL2(PCWSTR ShimDll)
Definition: versionlie.c:369
#define trace
Definition: atltest.h:70
#define ok_str(x, y)
Definition: atltest.h:127
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define ok_ptr(expression, result)
Definition: atltest.h:108
LONG NTSTATUS
Definition: precomp.h:26
#define _stricmp
Definition: cat.c:22
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
GLdouble n
Definition: glext.h:7729
HMODULE(WINAPI * LOADLIBRARYEXAPROC)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:25
DWORD get_host_winver(void)
Definition: data.c:796
static HMODULE g_h111
Definition: ignoreloadlib.c:20
HMODULE(WINAPI * LOADLIBRARYWPROC)(LPCWSTR lpLibFileName)
Definition: ignoreloadlib.c:24
static HMODULE WINAPI my_LoadLibraryA(PCSTR Name)
Definition: ignoreloadlib.c:64
static HMODULE g_hSentinelModule
Definition: ignoreloadlib.c:18
static void test_LoadLibraryA(PHOOKAPI hook)
Definition: ignoreloadlib.c:97
static void test_LoadLibraryExW(PHOOKAPI hook)
static void test_LoadLibraryW(PHOOKAPI hook)
static HMODULE WINAPI my_LoadLibraryExW(PCWSTR Name, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:88
HMODULE(WINAPI * LOADLIBRARYAPROC)(LPCSTR lpLibFileName)
Definition: ignoreloadlib.c:23
static DWORD g_WinVersion
Definition: ignoreloadlib.c:16
HMODULE(WINAPI * LOADLIBRARYEXWPROC)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:26
static HMODULE WINAPI my_LoadLibraryW(PCWSTR Name)
Definition: ignoreloadlib.c:80
static void test_LoadLibraryExA(PHOOKAPI hook)
static tGETHOOKAPIS pGetHookAPIs
Definition: ignoreloadlib.c:17
UINT WINAPI GetErrorMode(VOID)
Definition: ignoreloadlib.c:31
static HMODULE g_h0
Definition: ignoreloadlib.c:21
static HMODULE WINAPI my_LoadLibraryExA(PCSTR Name, HANDLE hFile, DWORD dwFlags)
Definition: ignoreloadlib.c:72
static HMODULE g_h123
Definition: ignoreloadlib.c:19
@ ProcessDefaultHardErrorMode
Definition: winternl.h:868
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define SEM_NOGPFAULTERRORBOX
Definition: rtltypes.h:70
#define SEM_NOOPENFILEERRORBOX
Definition: rtltypes.h:72
#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
#define L(x)
Definition: ntvdm.h:50
static HANDLE proc()
Definition: pdb.c:34
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
const uint16_t * PCWSTR
Definition: typedefs.h:57
const char * PCSTR
Definition: typedefs.h:52
HANDLE HMODULE
Definition: typedefs.h:77
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185