ReactOS 0.4.15-dev-7918-g2a2556c
forcedxsetup.c File Reference
#include <ntstatus.h>
#include <windows.h>
#include "wine/test.h"
#include "appshim_apitest.h"
Include dependency graph for forcedxsetup.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Typedefs

typedef HMODULE(WINAPILOADLIBRARYAPROC) (PCSTR)
 
typedef HMODULE(WINAPILOADLIBRARYWPROC) (PCWSTR)
 
typedef FARPROC(WINAPIGETPROCADDRESSPROC) (HMODULE, PCSTR)
 
typedef BOOL(WINAPIFREELIBRARYPROC) (HMODULE)
 

Functions

static INT (WINAPI *DirectXSetupGetVersion)(DWORD *lpdwVersion
 
static HMODULE WINAPI my_LoadLibraryA (PCSTR Name)
 
static void test_LoadLibraryA (PHOOKAPI hook)
 
static HMODULE WINAPI my_LoadLibraryW (PCWSTR Name)
 
static void test_LoadLibraryW (PHOOKAPI hook)
 
static void test_GetProcAddress (PHOOKAPI hook)
 
BOOL WINAPI my_FreeLibrary (HMODULE module)
 
static void test_FreeLibrary (PHOOKAPI hook)
 
 START_TEST (forcedxsetup)
 

Variables

static HMODULE g_hShimDll
 
static HMODULE g_hSentinelModule = (HMODULE)&g_hShimDll
 
static tGETHOOKAPIS pGetHookAPIs
 
static DWORDlpdwMinorVersion
 
static int g_NumShim = 0
 
static int g_NumSentinel = 0
 
static int g_NumCalls = 0
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 9 of file forcedxsetup.c.

Typedef Documentation

◆ FREELIBRARYPROC

typedef BOOL(WINAPI * FREELIBRARYPROC) (HMODULE)

Definition at line 25 of file forcedxsetup.c.

◆ GETPROCADDRESSPROC

typedef FARPROC(WINAPI * GETPROCADDRESSPROC) (HMODULE, PCSTR)

Definition at line 24 of file forcedxsetup.c.

◆ LOADLIBRARYAPROC

typedef HMODULE(WINAPI * LOADLIBRARYAPROC) (PCSTR)

Definition at line 22 of file forcedxsetup.c.

◆ LOADLIBRARYWPROC

typedef HMODULE(WINAPI * LOADLIBRARYWPROC) (PCWSTR)

Definition at line 23 of file forcedxsetup.c.

Function Documentation

◆ INT()

static INT ( WINAPI DirectXSetupGetVersion)
static

◆ my_FreeLibrary()

BOOL WINAPI my_FreeLibrary ( HMODULE  module)

Definition at line 154 of file forcedxsetup.c.

155{
158 else if (module == g_hShimDll)
159 ++g_NumShim;
160 ++g_NumCalls;
161 return 33;
162}
static int g_NumShim
Definition: forcedxsetup.c:151
static int g_NumSentinel
Definition: forcedxsetup.c:152
static HMODULE g_hSentinelModule
Definition: forcedxsetup.c:16
static HMODULE g_hShimDll
Definition: forcedxsetup.c:15
static int g_NumCalls
Definition: forcedxsetup.c:153

Referenced by test_FreeLibrary().

◆ my_LoadLibraryA()

static HMODULE WINAPI my_LoadLibraryA ( PCSTR  Name)
static

Definition at line 28 of file forcedxsetup.c.

29{
30 return g_hSentinelModule;
31}

Referenced by test_LoadLibraryA().

◆ my_LoadLibraryW()

static HMODULE WINAPI my_LoadLibraryW ( PCWSTR  Name)
static

Definition at line 70 of file forcedxsetup.c.

71{
72 return g_hSentinelModule;
73}

Referenced by test_LoadLibraryW().

◆ START_TEST()

START_TEST ( forcedxsetup  )

Definition at line 185 of file forcedxsetup.c.

186{
187 DWORD num_shims = 0, n;
189
190 if (!LoadShimDLL(L"aclayers.dll", &g_hShimDll, &pGetHookAPIs))
191 return;
192
193 hook = pGetHookAPIs("", L"ForceDxSetupSuccess", &num_shims);
194
195 ok(hook != NULL, "Expected hook to be a valid pointer\n");
196 ok(num_shims == 6, "Expected num_shims to be 6, was: %u\n", num_shims);
197
198 if (!hook || !num_shims)
199 return;
200
201 for (n = 0; n < num_shims; ++n)
202 {
203 if (!_stricmp(hook[n].FunctionName, "LoadLibraryA"))
205 else if (!_stricmp(hook[n].FunctionName, "LoadLibraryW"))
207 else if (!_stricmp(hook[n].FunctionName, "GetProcAddress"))
209 else if (!_stricmp(hook[n].FunctionName, "FreeLibrary"))
211 }
212
213 ok(DirectXSetupGetVersion != NULL, "No DirectXSetupGetVersion\n");
215 {
216 DWORD dwVersion = 0xdeadbeef;
217 DWORD dwMinorVersion = 0xbeefdead;
218 INT Res = DirectXSetupGetVersion(&dwVersion, &dwMinorVersion);
219 ok_int(Res, 1);
220 ok_hex(dwVersion, MAKELONG(7, 4)); // DirectX 7.0
221 ok_hex(dwMinorVersion, MAKELONG(1792, 0));
222
224 ok_int(Res, 1);
225 }
226}
@ 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
BOOL LoadShimDLL(PCWSTR ShimDll, HMODULE *module, tGETHOOKAPIS *ppGetHookAPIs)
Definition: versionlie.c:307
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define ok_int(expression, result)
Definition: atltest.h:134
#define _stricmp
Definition: cat.c:22
#define NULL
Definition: types.h:112
unsigned long DWORD
Definition: ntddk_ex.h:95
static void test_GetProcAddress(PHOOKAPI hook)
Definition: forcedxsetup.c:113
static void test_LoadLibraryA(PHOOKAPI hook)
Definition: forcedxsetup.c:33
static void test_LoadLibraryW(PHOOKAPI hook)
Definition: forcedxsetup.c:75
static tGETHOOKAPIS pGetHookAPIs
Definition: forcedxsetup.c:17
static void test_FreeLibrary(PHOOKAPI hook)
Definition: forcedxsetup.c:164
INT_PTR WINAPI DirectXSetupGetVersion(DWORD *lpdwVersion, DWORD *lpdwMinorVersion)
GLdouble n
Definition: glext.h:7729
#define L(x)
Definition: ntvdm.h:50
int32_t INT
Definition: typedefs.h:58
#define MAKELONG(a, b)
Definition: typedefs.h:249

◆ test_FreeLibrary()

static void test_FreeLibrary ( PHOOKAPI  hook)
static

Definition at line 164 of file forcedxsetup.c.

165{
167
168 ok_str(hook->LibraryName, "KERNEL32.DLL");
169 hook->OriginalFunction = my_FreeLibrary;
170 proc = hook->ReplacementFunction;
171
172 ok_int(proc(NULL), 33);
173 ok_int(proc(NULL), 33);
178
179 ok_int(g_NumShim, 0);
181 ok_int(g_NumCalls, 4);
182}
#define ok_str(x, y)
Definition: atltest.h:127
#define TRUE
Definition: types.h:120
BOOL(WINAPI * FREELIBRARYPROC)(HMODULE)
Definition: forcedxsetup.c:25
BOOL WINAPI my_FreeLibrary(HMODULE module)
Definition: forcedxsetup.c:154
static HANDLE proc()
Definition: pdb.c:34

Referenced by START_TEST().

◆ test_GetProcAddress()

static void test_GetProcAddress ( PHOOKAPI  hook)
static

Definition at line 113 of file forcedxsetup.c.

114{
116 DWORD n;
117 PCSTR Functions[] = {
118 "DirectXSetup",
119 "DirectXSetupA",
120 "DirectXSetupW",
121 "DirectXSetupGetVersion",
122 /* And not case sensitive? */
123 "directxsetup",
124 "DIRECTXSETUPA",
125 "DiReCtXsEtUpW",
126 NULL
127 };
128 HMODULE mod = GetModuleHandleA("kernel32.dll");
129
130 ok_str(hook->LibraryName, "KERNEL32.DLL");
131 hook->OriginalFunction = GetProcAddress; /* Some versions seem to call GetProcAddress regardless of what is put here.. */
132 proc = hook->ReplacementFunction;
133
134 ok_ptr(proc(mod, "CreateFileA"), GetProcAddress(mod, "CreateFileA"));
135 ok_ptr(proc(g_hShimDll, "CreateFileA"), NULL);
136
137 for (n = 0; Functions[n]; ++n)
138 {
139 FARPROC fn = proc(g_hShimDll, Functions[n]);
140 ok(fn != NULL, "Got NULL for %s\n", Functions[n]);
141 /* And yet, no export! */
142 ok_ptr(GetProcAddress(g_hShimDll, Functions[n]), NULL);
143 }
144
145 /* Not every function is shimmed */
146 ok_ptr(proc(g_hShimDll, "DirectXSetupShowEULA"), NULL);
147 /* Retrieve a pointer for our next test */
148 DirectXSetupGetVersion = (PVOID)proc(g_hShimDll, "DirectXSetupGetVersion");
149}
#define ok_ptr(expression, result)
Definition: atltest.h:108
int(* FARPROC)()
Definition: compat.h:36
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
FARPROC(WINAPI * GETPROCADDRESSPROC)(HMODULE, PCSTR)
Definition: forcedxsetup.c:24
static int mod
Definition: i386-dis.c:1288
void * PVOID
Definition: typedefs.h:50
const char * PCSTR
Definition: typedefs.h:52
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by START_TEST().

◆ test_LoadLibraryA()

static void test_LoadLibraryA ( PHOOKAPI  hook)
static

Definition at line 33 of file forcedxsetup.c.

34{
36
37 ok_str(hook->LibraryName, "KERNEL32.DLL");
38 hook->OriginalFunction = my_LoadLibraryA;
39 proc = hook->ReplacementFunction;
40
41 /* Original function is not called */
42 ok_ptr(proc("dsetup"), g_hShimDll);
43 ok_ptr(proc("dsetup.dll"), g_hShimDll);
44 ok_ptr(proc("DSETUP.DLL"), g_hShimDll);
45 ok_ptr(proc("DSeTuP.DlL"), g_hShimDll);
46
47 ok_ptr(proc("dsetup32"), g_hShimDll);
48 ok_ptr(proc("dsetup32.dll"), g_hShimDll);
49 ok_ptr(proc("DSETUP32.DLL"), g_hShimDll);
50 ok_ptr(proc("DSeTuP32.DlL"), g_hShimDll);
51
52 ok_ptr(proc("c:\\bogus/dsetup"), g_hShimDll);
53 ok_ptr(proc("c:\\bogus\\dsetup.dll"), g_hShimDll);
54 ok_ptr(proc("c:/bogus/DSETUP.DLL"), g_hShimDll);
55 ok_ptr(proc("c:\\bogus\\DSeTuP.DlL"), g_hShimDll);
56
57 ok_ptr(proc("////////////////////dsetup32"), g_hShimDll);
58 ok_ptr(proc("\\\\\\\\\\\\\\dsetup32.dll"), g_hShimDll);
59 ok_ptr(proc("xxxxxxxxxxx\\DSETUP32.DLL"), g_hShimDll);
60 ok_ptr(proc("xxxxxxxxxxx//DSeTuP32.DlL"), g_hShimDll);
61
62 /* Original function is called */
64 ok_ptr(proc("dsetup\\something"), g_hSentinelModule);
65 ok_ptr(proc("dsetup.dl"), g_hSentinelModule);
66 ok_ptr(proc("c:\\DSETUP.DLL."), g_hSentinelModule);
67 ok_ptr(proc("DSeTuP.D"), g_hSentinelModule);
68}
static HMODULE WINAPI my_LoadLibraryA(PCSTR Name)
Definition: forcedxsetup.c:28
HMODULE(WINAPI * LOADLIBRARYAPROC)(PCSTR)
Definition: forcedxsetup.c:22

Referenced by START_TEST().

◆ test_LoadLibraryW()

static void test_LoadLibraryW ( PHOOKAPI  hook)
static

Definition at line 75 of file forcedxsetup.c.

76{
78
79 ok_str(hook->LibraryName, "KERNEL32.DLL");
80
81 hook->OriginalFunction = my_LoadLibraryW;
82 proc = hook->ReplacementFunction;
83
84 /* Original function is not called */
85 ok_ptr(proc(L"dsetup"), g_hShimDll);
86 ok_ptr(proc(L"dsetup.dll"), g_hShimDll);
87 ok_ptr(proc(L"DSETUP.DLL"), g_hShimDll);
88 ok_ptr(proc(L"DSeTuP.DlL"), g_hShimDll);
89
90 ok_ptr(proc(L"dsetup32"), g_hShimDll);
91 ok_ptr(proc(L"dsetup32.dll"), g_hShimDll);
92 ok_ptr(proc(L"DSETUP32.DLL"), g_hShimDll);
93 ok_ptr(proc(L"DSeTuP32.DlL"), g_hShimDll);
94
95 ok_ptr(proc(L"c:\\bogus/dsetup"), g_hShimDll);
96 ok_ptr(proc(L"c:\\bogus\\dsetup.dll"), g_hShimDll);
97 ok_ptr(proc(L"c:/bogus/DSETUP.DLL"), g_hShimDll);
98 ok_ptr(proc(L"c:\\bogus\\DSeTuP.DlL"), g_hShimDll);
99
100 ok_ptr(proc(L"////////////////////dsetup32"), g_hShimDll);
101 ok_ptr(proc(L"\\\\\\\\\\\\\\dsetup32.dll"), g_hShimDll);
102 ok_ptr(proc(L"xxxxxxxxxxx\\DSETUP32.DLL"), g_hShimDll);
103 ok_ptr(proc(L"xxxxxxxxxxx//DSeTuP32.DlL"), g_hShimDll);
104
105 /* Original function is called */
107 ok_ptr(proc(L"dsetup\\something"), g_hSentinelModule);
108 ok_ptr(proc(L"dsetup.dl"), g_hSentinelModule);
109 ok_ptr(proc(L"c:\\DSETUP.DLL."), g_hSentinelModule);
110 ok_ptr(proc(L"DSeTuP.D"), g_hSentinelModule);
111}
static HMODULE WINAPI my_LoadLibraryW(PCWSTR Name)
Definition: forcedxsetup.c:70
HMODULE(WINAPI * LOADLIBRARYWPROC)(PCWSTR)
Definition: forcedxsetup.c:23

Referenced by START_TEST().

Variable Documentation

◆ g_hSentinelModule

◆ g_hShimDll

◆ g_NumCalls

int g_NumCalls = 0
static

Definition at line 153 of file forcedxsetup.c.

Referenced by my_FreeLibrary(), and test_FreeLibrary().

◆ g_NumSentinel

int g_NumSentinel = 0
static

Definition at line 152 of file forcedxsetup.c.

Referenced by my_FreeLibrary(), and test_FreeLibrary().

◆ g_NumShim

int g_NumShim = 0
static

Definition at line 151 of file forcedxsetup.c.

Referenced by my_FreeLibrary(), and test_FreeLibrary().

◆ lpdwMinorVersion

DWORD* lpdwMinorVersion

Definition at line 19 of file forcedxsetup.c.

Referenced by DirectXSetupGetVersion().

◆ pGetHookAPIs

tGETHOOKAPIS pGetHookAPIs
static

Definition at line 17 of file forcedxsetup.c.

Referenced by START_TEST().