ReactOS  0.4.14-dev-384-g5b37caa
forcedxsetupsuccess.c File Reference
#include <windef.h>
#include <winbase.h>
#include <shimlib.h>
#include "ntndk.h"
#include <setup_shim.inl>
#include <implement_shim.inl>
Include dependency graph for forcedxsetupsuccess.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define SHIM_NS   ForceDXSetupSuccess
 
#define DSETUPERR_SUCCESS   0
 
#define SHIM_NUM_HOOKS   6
 
#define SHIM_SETUP_HOOKS
 

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)
 
typedef FARPROC(WINAPIGETPROCADDRESSPROC) (HMODULE hModule, LPCSTR lpProcName)
 
typedef BOOL(WINAPIFREELIBRARYPROC) (HINSTANCE hLibModule)
 

Functions

INT_PTR WINAPI DirectXSetup (HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
 
INT_PTR WINAPI DirectXSetupA (HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
 
INT_PTR WINAPI DirectXSetupW (HWND hWnd, LPWSTR lpszRootPath, DWORD dwFlags)
 
INT_PTR WINAPI DirectXSetupGetVersion (DWORD *lpdwVersion, DWORD *lpdwMinorVersion)
 
static BOOL IsDxSetupW (PCUNICODE_STRING LibraryPath)
 
static BOOL IsDxSetupA (PCANSI_STRING LibraryPath)
 
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryA (LPCSTR lpLibFileName)
 
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryW (LPCWSTR lpLibFileName)
 
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExA (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExW (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 
FARPROC WINAPI SHIM_OBJ_NAME() APIHook_GetProcAddress (HMODULE hModule, LPCSTR lpProcName)
 
BOOL WINAPI SHIM_OBJ_NAME() APIHook_FreeLibrary (HINSTANCE hLibModule)
 

Macro Definition Documentation

◆ DSETUPERR_SUCCESS

#define DSETUPERR_SUCCESS   0

Definition at line 26 of file forcedxsetupsuccess.c.

◆ SHIM_NS

#define SHIM_NS   ForceDXSetupSuccess

Definition at line 22 of file forcedxsetupsuccess.c.

◆ SHIM_NUM_HOOKS

#define SHIM_NUM_HOOKS   6

Definition at line 192 of file forcedxsetupsuccess.c.

◆ SHIM_SETUP_HOOKS

#define SHIM_SETUP_HOOKS
Value:
SHIM_HOOK(0, "KERNEL32.DLL", "LoadLibraryA", SHIM_OBJ_NAME(APIHook_LoadLibraryA)) \
SHIM_HOOK(1, "KERNEL32.DLL", "LoadLibraryW", SHIM_OBJ_NAME(APIHook_LoadLibraryW)) \
SHIM_HOOK(2, "KERNEL32.DLL", "LoadLibraryExA", SHIM_OBJ_NAME(APIHook_LoadLibraryExA)) \
SHIM_HOOK(3, "KERNEL32.DLL", "LoadLibraryExW", SHIM_OBJ_NAME(APIHook_LoadLibraryExW)) \
SHIM_HOOK(4, "KERNEL32.DLL", "GetProcAddress", SHIM_OBJ_NAME(APIHook_GetProcAddress)) \
SHIM_HOOK(5, "KERNEL32.DLL", "FreeLibrary", SHIM_OBJ_NAME(APIHook_FreeLibrary))
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
BOOL WINAPI SHIM_OBJ_NAME() APIHook_FreeLibrary(HINSTANCE hLibModule)
FARPROC WINAPI SHIM_OBJ_NAME() APIHook_GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryA(LPCSTR lpLibFileName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryW(LPCWSTR lpLibFileName)
HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)

Definition at line 193 of file forcedxsetupsuccess.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file forcedxsetupsuccess.c.

Typedef Documentation

◆ FREELIBRARYPROC

typedef BOOL(WINAPI* FREELIBRARYPROC) (HINSTANCE hLibModule)

Definition at line 19 of file forcedxsetupsuccess.c.

◆ GETPROCADDRESSPROC

typedef FARPROC(WINAPI* GETPROCADDRESSPROC) (HMODULE hModule, LPCSTR lpProcName)

Definition at line 18 of file forcedxsetupsuccess.c.

◆ LOADLIBRARYAPROC

typedef HMODULE(WINAPI* LOADLIBRARYAPROC) (LPCSTR lpLibFileName)

Definition at line 14 of file forcedxsetupsuccess.c.

◆ LOADLIBRARYEXAPROC

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

Definition at line 16 of file forcedxsetupsuccess.c.

◆ LOADLIBRARYEXWPROC

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

Definition at line 17 of file forcedxsetupsuccess.c.

◆ LOADLIBRARYWPROC

typedef HMODULE(WINAPI* LOADLIBRARYWPROC) (LPCWSTR lpLibFileName)

Definition at line 15 of file forcedxsetupsuccess.c.

Function Documentation

◆ APIHook_FreeLibrary()

BOOL WINAPI SHIM_OBJ_NAME() APIHook_FreeLibrary ( HINSTANCE  hLibModule)

Definition at line 180 of file forcedxsetupsuccess.c.

181 {
182  if (hLibModule == ShimLib_Instance())
183  {
184  SHIM_MSG("Intercepted\n");
185  return TRUE;
186  }
187 
188  return CALL_SHIM(5, FREELIBRARYPROC)(hLibModule);
189 }
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
HINSTANCE hLibModule
Definition: sfc.c:23
#define TRUE
Definition: types.h:120
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
BOOL(WINAPI * FREELIBRARYPROC)(HINSTANCE hLibModule)

◆ APIHook_GetProcAddress()

FARPROC WINAPI SHIM_OBJ_NAME() APIHook_GetProcAddress ( HMODULE  hModule,
LPCSTR  lpProcName 
)

Definition at line 148 of file forcedxsetupsuccess.c.

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[] = {
157  DirectXSetup,
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 }
INT_PTR WINAPI DirectXSetupGetVersion(DWORD *lpdwVersion, DWORD *lpdwMinorVersion)
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
#define TRUE
Definition: types.h:120
INT_PTR WINAPI DirectXSetup(HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
GLdouble n
Definition: glext.h:7729
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NTSYSAPI BOOLEAN NTAPI RtlEqualString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:63
INT_PTR WINAPI DirectXSetupA(HWND hWnd, LPSTR lpszRootPath, DWORD dwFlags)
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
unsigned long DWORD
Definition: ntddk_ex.h:95
std::wstring STRING
Definition: fontsub.cpp:33
FARPROC(WINAPI * GETPROCADDRESSPROC)(HMODULE hModule, LPCSTR lpProcName)
#define MAXUSHORT
Definition: typedefs.h:81
INT_PTR WINAPI DirectXSetupW(HWND hWnd, LPWSTR lpszRootPath, DWORD dwFlags)
int(* FARPROC)()
Definition: compat.h:28
HMODULE hModule
Definition: animate.c:44
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ APIHook_LoadLibraryA()

HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryA ( LPCSTR  lpLibFileName)

Definition at line 104 of file forcedxsetupsuccess.c.

105 {
107 
108  RtlInitAnsiString(&Library, lpLibFileName);
109  if (IsDxSetupA(&Library))
110  return ShimLib_Instance();
111 
112  return CALL_SHIM(0, LOADLIBRARYAPROC)(lpLibFileName);
113 }
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
HMODULE(WINAPI * LOADLIBRARYAPROC)(LPCSTR lpLibFileName)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
static BOOL IsDxSetupA(PCANSI_STRING LibraryPath)

◆ APIHook_LoadLibraryExA()

HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExA ( LPCSTR  lpLibFileName,
HANDLE  hFile,
DWORD  dwFlags 
)

Definition at line 126 of file forcedxsetupsuccess.c.

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 }
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
static BOOL IsDxSetupA(PCANSI_STRING LibraryPath)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ HANDLE hFile
Definition: mswsock.h:90
HMODULE(WINAPI * LOADLIBRARYEXAPROC)(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)

◆ APIHook_LoadLibraryExW()

HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryExW ( LPCWSTR  lpLibFileName,
HANDLE  hFile,
DWORD  dwFlags 
)

Definition at line 137 of file forcedxsetupsuccess.c.

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 }
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
HMODULE(WINAPI * LOADLIBRARYEXWPROC)(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
static BOOL IsDxSetupW(PCUNICODE_STRING LibraryPath)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ HANDLE hFile
Definition: mswsock.h:90
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ APIHook_LoadLibraryW()

HMODULE WINAPI SHIM_OBJ_NAME() APIHook_LoadLibraryW ( LPCWSTR  lpLibFileName)

Definition at line 115 of file forcedxsetupsuccess.c.

116 {
118 
119  RtlInitUnicodeString(&Library, lpLibFileName);
120  if (IsDxSetupW(&Library))
121  return ShimLib_Instance();
122 
123  return CALL_SHIM(1, LOADLIBRARYWPROC)(lpLibFileName);
124 }
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
HMODULE(WINAPI * LOADLIBRARYWPROC)(LPCWSTR lpLibFileName)
static BOOL IsDxSetupW(PCUNICODE_STRING LibraryPath)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

◆ DirectXSetup()

INT_PTR WINAPI DirectXSetup ( HWND  hWnd,
LPSTR  lpszRootPath,
DWORD  dwFlags 
)

Definition at line 28 of file forcedxsetupsuccess.c.

29 {
30  SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
31  return DSETUPERR_SUCCESS;
32 }
#define DSETUPERR_SUCCESS
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75

Referenced by APIHook_GetProcAddress().

◆ DirectXSetupA()

INT_PTR WINAPI DirectXSetupA ( HWND  hWnd,
LPSTR  lpszRootPath,
DWORD  dwFlags 
)

Definition at line 34 of file forcedxsetupsuccess.c.

35 {
36  SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
37  return DSETUPERR_SUCCESS;
38 }
#define DSETUPERR_SUCCESS
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75

Referenced by APIHook_GetProcAddress().

◆ DirectXSetupGetVersion()

INT_PTR WINAPI DirectXSetupGetVersion ( DWORD lpdwVersion,
DWORD lpdwMinorVersion 
)

Definition at line 46 of file forcedxsetupsuccess.c.

47 {
48  if (lpdwVersion)
49  *lpdwVersion = MAKELONG(7, 4); // DirectX 7.0
50  if (lpdwMinorVersion)
51  *lpdwMinorVersion = MAKELONG(1792, 0);
52 
53  return TRUE;
54 }
#define TRUE
Definition: types.h:120
#define MAKELONG(a, b)
Definition: typedefs.h:248
static DWORD * lpdwMinorVersion
Definition: forcedxsetup.c:19

Referenced by APIHook_GetProcAddress(), START_TEST(), and test_GetProcAddress().

◆ DirectXSetupW()

INT_PTR WINAPI DirectXSetupW ( HWND  hWnd,
LPWSTR  lpszRootPath,
DWORD  dwFlags 
)

Definition at line 40 of file forcedxsetupsuccess.c.

41 {
42  SHIM_MSG("Returning DSETUPERR_SUCCESS\n");
43  return DSETUPERR_SUCCESS;
44 }
#define DSETUPERR_SUCCESS
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75

Referenced by APIHook_GetProcAddress().

◆ IsDxSetupA()

static BOOL IsDxSetupA ( PCANSI_STRING  LibraryPath)
static

Definition at line 90 of file forcedxsetupsuccess.c.

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 }
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
static BOOL IsDxSetupW(PCUNICODE_STRING LibraryPath)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)

Referenced by APIHook_LoadLibraryA(), and APIHook_LoadLibraryExA().

◆ IsDxSetupW()

static BOOL IsDxSetupW ( PCUNICODE_STRING  LibraryPath)
static

Definition at line 56 of file forcedxsetupsuccess.c.

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 }
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
GLdouble n
Definition: glext.h:7729
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by APIHook_LoadLibraryExW(), APIHook_LoadLibraryW(), and IsDxSetupA().