ReactOS 0.4.16-dev-306-g647d351
forcedxsetupsuccess.c
Go to the documentation of this file.
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: ForceDxSetupSuccess 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
14typedef HMODULE(WINAPI* LOADLIBRARYAPROC)(LPCSTR lpLibFileName);
15typedef HMODULE(WINAPI* LOADLIBRARYWPROC)(LPCWSTR lpLibFileName);
20
21
22#define SHIM_NS ForceDXSetupSuccess
23#include <setup_shim.inl>
24
25
26#define DSETUPERR_SUCCESS 0
27
29{
30 SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
31 return DSETUPERR_SUCCESS;
32}
33
35{
36 SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
37 return DSETUPERR_SUCCESS;
38}
39
41{
42 SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
43 return DSETUPERR_SUCCESS;
44}
45
47{
48 if (lpdwVersion)
49 *lpdwVersion = MAKELONG(7, 4); // DirectX 7.0
51 *lpdwMinorVersion = MAKELONG(1792, 0);
52
53 return TRUE;
54}
55
56static BOOL IsDxSetupW(PCUNICODE_STRING LibraryPath)
57{
58 static const UNICODE_STRING DxSetupDlls[] = {
59 RTL_CONSTANT_STRING(L"dsetup.dll"),
60 RTL_CONSTANT_STRING(L"dsetup32.dll"),
61 RTL_CONSTANT_STRING(L"dsetup"),
62 RTL_CONSTANT_STRING(L"dsetup32"),
63 };
64 static const UNICODE_STRING PathDividerFind = RTL_CONSTANT_STRING(L"\\/");
65 UNICODE_STRING LibraryName;
66 USHORT PathDivider;
67 DWORD n;
68
69 if (!NT_SUCCESS(RtlFindCharInUnicodeString(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END, LibraryPath, &PathDividerFind, &PathDivider)))
70 PathDivider = 0;
71
72 if (PathDivider)
73 PathDivider += sizeof(WCHAR);
74
75 LibraryName.Buffer = LibraryPath->Buffer + PathDivider / sizeof(WCHAR);
76 LibraryName.Length = LibraryPath->Length - PathDivider;
77 LibraryName.MaximumLength = LibraryPath->MaximumLength - PathDivider;
78
79 for (n = 0; n < ARRAYSIZE(DxSetupDlls); ++n)
80 {
81 if (RtlEqualUnicodeString(&LibraryName, DxSetupDlls + n, TRUE))
82 {
83 SHIM_MSG("Found %wZ\n", DxSetupDlls + n);
84 return TRUE;
85 }
86 }
87 return FALSE;
88}
89
90static BOOL IsDxSetupA(PCANSI_STRING LibraryPath)
91{
92 BOOL bIsDxSetup;
93 UNICODE_STRING LibraryPathW;
94
95 if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&LibraryPathW, LibraryPath, TRUE)))
96 {
97 bIsDxSetup = IsDxSetupW(&LibraryPathW);
98 RtlFreeUnicodeString(&LibraryPathW);
99 return bIsDxSetup;
100 }
101 return FALSE;
102}
103
104HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryA)(LPCSTR lpLibFileName)
105{
107
108 RtlInitAnsiString(&Library, lpLibFileName);
109 if (IsDxSetupA(&Library))
110 return ShimLib_Instance();
111
112 return CALL_SHIM(0, LOADLIBRARYAPROC)(lpLibFileName);
113}
114
115HMODULE WINAPI SHIM_OBJ_NAME(APIHook_LoadLibraryW)(LPCWSTR lpLibFileName)
116{
118
119 RtlInitUnicodeString(&Library, lpLibFileName);
120 if (IsDxSetupW(&Library))
121 return ShimLib_Instance();
122
123 return CALL_SHIM(1, LOADLIBRARYWPROC)(lpLibFileName);
124}
125
127{
129
130 RtlInitAnsiString(&Library, lpLibFileName);
131 if (IsDxSetupA(&Library))
132 return ShimLib_Instance();
133
134 return CALL_SHIM(2, LOADLIBRARYEXAPROC)(lpLibFileName, hFile, dwFlags);
135}
136
138{
140
141 RtlInitUnicodeString(&Library, lpLibFileName);
142 if (IsDxSetupW(&Library))
143 return ShimLib_Instance();
144
145 return CALL_SHIM(3, LOADLIBRARYEXWPROC)(lpLibFileName, hFile, dwFlags);
146}
147
149{
150 static const STRING DxSetupFunctions[] = {
151 RTL_CONSTANT_STRING("DirectXSetup"),
152 RTL_CONSTANT_STRING("DirectXSetupA"),
153 RTL_CONSTANT_STRING("DirectXSetupW"),
154 RTL_CONSTANT_STRING("DirectXSetupGetVersion"),
155 };
156 static const FARPROC DxSetupRedirections[] = {
161 };
162 DWORD n;
163
164 if (hModule == ShimLib_Instance() && ((ULONG_PTR)lpProcName > MAXUSHORT))
165 {
166 STRING ProcName;
167 RtlInitAnsiString(&ProcName, lpProcName);
168 for (n = 0; n < ARRAYSIZE(DxSetupFunctions); ++n)
169 {
170 if (RtlEqualString(&ProcName, DxSetupFunctions + n, TRUE))
171 {
172 SHIM_MSG("Intercepted %Z\n", DxSetupFunctions + n);
173 return DxSetupRedirections[n];
174 }
175 }
176 }
177 return CALL_SHIM(4, GETPROCADDRESSPROC)(hModule, lpProcName);
178}
179
181{
183 {
184 SHIM_MSG("Intercepted\n");
185 return TRUE;
186 }
187
188 return CALL_SHIM(5, FREELIBRARYPROC)(hLibModule);
189}
190
191
192#define SHIM_NUM_HOOKS 6
193#define SHIM_SETUP_HOOKS \
194 SHIM_HOOK(0, "KERNEL32.DLL", "LoadLibraryA", SHIM_OBJ_NAME(APIHook_LoadLibraryA)) \
195 SHIM_HOOK(1, "KERNEL32.DLL", "LoadLibraryW", SHIM_OBJ_NAME(APIHook_LoadLibraryW)) \
196 SHIM_HOOK(2, "KERNEL32.DLL", "LoadLibraryExA", SHIM_OBJ_NAME(APIHook_LoadLibraryExA)) \
197 SHIM_HOOK(3, "KERNEL32.DLL", "LoadLibraryExW", SHIM_OBJ_NAME(APIHook_LoadLibraryExW)) \
198 SHIM_HOOK(4, "KERNEL32.DLL", "GetProcAddress", SHIM_OBJ_NAME(APIHook_GetProcAddress)) \
199 SHIM_HOOK(5, "KERNEL32.DLL", "FreeLibrary", SHIM_OBJ_NAME(APIHook_FreeLibrary))
200
201#include <implement_shim.inl>
HWND hWnd
Definition: settings.c:17
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HMODULE hModule
Definition: animate.c:44
int(* FARPROC)()
Definition: compat.h:36
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
std::wstring STRING
Definition: fontsub.cpp:33
static DWORD * lpdwMinorVersion
Definition: forcedxsetup.c:19
INT_PTR WINAPI DirectXSetupGetVersion(DWORD *lpdwVersion, DWORD *lpdwMinorVersion)
INT_PTR WINAPI DirectXSetupA(HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
HMODULE(WINAPI * LOADLIBRARYEXAPROC)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryW(LPCWSTR lpLibFileName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
static BOOL IsDxSetupA(PCANSI_STRING LibraryPath)
HMODULE(WINAPI * LOADLIBRARYWPROC)(LPCWSTR lpLibFileName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryA(LPCSTR lpLibFileName)
#define DSETUPERR_SUCCESS
BOOL(WINAPI * FREELIBRARYPROC)(HINSTANCE hLibModule)
BOOL WINAPI SHIM_OBJ_NAME() APIHook_FreeLibrary(HINSTANCE hLibModule)
HMODULE(WINAPI * LOADLIBRARYAPROC)(LPCSTR lpLibFileName)
INT_PTR WINAPI DirectXSetupW(HWND hWnd, LPWSTR lpszRootPath, DWORD dwFlags)
FARPROC(WINAPI * GETPROCADDRESSPROC)(HMODULE hModule, LPCSTR lpProcName)
HMODULE(WINAPI * LOADLIBRARYEXWPROC)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
static BOOL IsDxSetupW(PCUNICODE_STRING LibraryPath)
FARPROC WINAPI SHIM_OBJ_NAME() APIHook_GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
INT_PTR WINAPI DirectXSetup(HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
GLdouble n
Definition: glext.h:7729
_In_ HANDLE hFile
Definition: mswsock.h:90
#define BOOL
Definition: nt_native.h:43
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI BOOLEAN NTAPI RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END
Definition: rtl.h:25
NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
HINSTANCE hLibModule
Definition: sfc.c:23
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
int32_t INT_PTR
Definition: typedefs.h:64
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MAKELONG(a, b)
Definition: typedefs.h:249
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
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185