[STORAHCI] Merge Storport Miniport driver by Aman Priyadarshi in GSoC.
[reactos.git] / reactos / dll / appcompat / shims / layer / versionlie.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Shim library
4 * FILE: dll/appcompat/shims/layer/versionlie.c
5 * PURPOSE: Version lie shims
6 * PROGRAMMER: Mark Jansen
7 */
8
9 #include <windows.h>
10 #include <shimlib.h>
11 #include <strsafe.h>
12
13 /* Generic version info to use with the shims */
14 typedef struct VersionLieInfo
15 {
16 DWORD FullVersion;
17 WORD dwMajorVersion;
18 WORD dwMinorVersion;
19 DWORD dwBuildNumber;
20 WORD dwPlatformId;
21 WORD wServicePackMajor;
22 WORD wServicePackMinor;
23 char szCSDVersionA[20];
24 WCHAR szCSDVersionW[20];
25 } VersionLieInfo;
26
27 VersionLieInfo g_Win95 = { 0xC3B60004, 4, 0, 950, VER_PLATFORM_WIN32_WINDOWS, 0, 0 };
28 VersionLieInfo g_WinNT4SP5 = { 0x05650004, 4, 0, 1381, VER_PLATFORM_WIN32_NT, 5, 0 };
29 VersionLieInfo g_Win98 = { 0xC0000A04, 4, 10, 0x040A08AE, VER_PLATFORM_WIN32_WINDOWS, 0, 0 };
30
31 VersionLieInfo g_Win2000 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 0, 0 };
32 VersionLieInfo g_Win2000SP1 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 1, 0 };
33 VersionLieInfo g_Win2000SP2 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 2, 0 };
34 VersionLieInfo g_Win2000SP3 = { 0x08930005, 5, 0, 2195, VER_PLATFORM_WIN32_NT, 3, 0 };
35
36 VersionLieInfo g_WinXP = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 0, 0 };
37 VersionLieInfo g_WinXPSP1 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 1, 0 };
38 VersionLieInfo g_WinXPSP2 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 2, 0 };
39 VersionLieInfo g_WinXPSP3 = { 0x0a280105, 5, 1, 2600, VER_PLATFORM_WIN32_NT, 3, 0 };
40
41 VersionLieInfo g_Win2k3RTM = { 0x0ece0205, 5, 2, 3790, VER_PLATFORM_WIN32_NT, 0, 0 };
42 VersionLieInfo g_Win2k3SP1 = { 0x0ece0205, 5, 2, 3790, VER_PLATFORM_WIN32_NT, 1, 0 };
43
44 VersionLieInfo g_WinVistaRTM = { 0x17700006, 6, 0, 6000, VER_PLATFORM_WIN32_NT, 0, 0 };
45 VersionLieInfo g_WinVistaSP1 = { 0x17710006, 6, 0, 6001, VER_PLATFORM_WIN32_NT, 1, 0 };
46 VersionLieInfo g_WinVistaSP2 = { 0x17720006, 6, 0, 6002, VER_PLATFORM_WIN32_NT, 2, 0 };
47
48 VersionLieInfo g_Win7RTM = { 0x1db00106, 6, 1, 7600, VER_PLATFORM_WIN32_NT, 0, 0 };
49
50
51 /* Fill the OSVERSIONINFO[EX][W|A] struct with the info from the generic VersionLieInfo */
52
53 BOOL FakeVersion(LPOSVERSIONINFOEXA pResult, VersionLieInfo* pFake)
54 {
55 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA) ||
56 pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOW))
57 {
58 pResult->dwMajorVersion = pFake->dwMajorVersion;
59 pResult->dwMinorVersion = pFake->dwMinorVersion;
60 pResult->dwBuildNumber = pFake->dwBuildNumber;
61 pResult->dwPlatformId = pFake->dwPlatformId;
62 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA))
63 {
64 if (FAILED(StringCbCopyA(pResult->szCSDVersion, sizeof(pResult->szCSDVersion), pFake->szCSDVersionA)))
65 return FALSE;
66 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
67 {
68 pResult->wServicePackMajor = pFake->wServicePackMajor;
69 pResult->wServicePackMinor = pFake->wServicePackMinor;
70 }
71 }
72 else
73 {
74 LPOSVERSIONINFOEXW pResultW = (LPOSVERSIONINFOEXW)pResult;
75 if (FAILED(StringCbCopyW(pResultW->szCSDVersion, sizeof(pResultW->szCSDVersion), pFake->szCSDVersionW)))
76 return FALSE;
77 if (pResultW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
78 {
79 pResultW->wServicePackMajor = pFake->wServicePackMajor;
80 pResultW->wServicePackMinor = pFake->wServicePackMinor;
81 }
82 }
83 return TRUE;
84 }
85 return FALSE;
86 }
87
88 typedef BOOL(WINAPI* GETVERSIONEXAPROC)(LPOSVERSIONINFOEXA);
89
90
91 #define SHIM_NS Win95VersionLie
92 #include <setup_shim.inl>
93
94 DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
95 {
96 return g_Win95.FullVersion;
97 }
98
99 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
100 {
101 if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
102 {
103 return FakeVersion(lpOsVersionInfo, &g_Win95);
104 }
105 return FALSE;
106 }
107
108 /* We do not call about the actual type, FakeVersion will correctly handle it either way */
109 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
110 {
111 if (CALL_SHIM(2, GETVERSIONEXAPROC)(lpOsVersionInfo))
112 {
113 return FakeVersion(lpOsVersionInfo, &g_Win95);
114 }
115 return FALSE;
116 }
117
118 #define SHIM_NUM_HOOKS 3
119 #define SHIM_SETUP_HOOKS \
120 SHIM_HOOK(0, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
121 SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
122 SHIM_HOOK(2, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW))
123
124 #include <implement_shim.inl>
125
126
127
128
129 #define SHIM_NS Win98VersionLie
130 #include <setup_shim.inl>
131
132 DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
133 {
134 return g_Win98.FullVersion;
135 }
136
137 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
138 {
139 if (CALL_SHIM(0, GETVERSIONEXAPROC)(lpOsVersionInfo))
140 {
141 return FakeVersion(lpOsVersionInfo, &g_Win98);
142 }
143 return FALSE;
144 }
145
146 /* We do not call about the actual type, FakeVersion will correctly handle it either way */
147 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
148 {
149 if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
150 {
151 return FakeVersion(lpOsVersionInfo, &g_Win98);
152 }
153 return FALSE;
154 }
155
156 #define SHIM_NUM_HOOKS 3
157 #define SHIM_SETUP_HOOKS \
158 SHIM_HOOK(2, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
159 SHIM_HOOK(0, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
160 SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW))
161
162 #include <implement_shim.inl>
163
164
165
166 #define SHIM_NS WinNT4SP5VersionLie
167 #define VERSION_INFO g_WinNT4SP5
168 #include "versionlie.inl"
169
170 #define SHIM_NS Win2000VersionLie
171 #define VERSION_INFO g_Win2000
172 #include "versionlie.inl"
173
174 #define SHIM_NS Win2000SP1VersionLie
175 #define VERSION_INFO g_Win2000SP1
176 #include "versionlie.inl"
177
178 #define SHIM_NS Win2000SP2VersionLie
179 #define VERSION_INFO g_Win2000SP2
180 #include "versionlie.inl"
181
182 #define SHIM_NS Win2000SP3VersionLie
183 #define VERSION_INFO g_Win2000SP3
184 #include "versionlie.inl"
185
186
187 #define SHIM_NS WinXPVersionLie
188 #define VERSION_INFO g_WinXP
189 #include "versionlie.inl"
190
191 #define SHIM_NS WinXPSP1VersionLie
192 #define VERSION_INFO g_WinXPSP1
193 #include "versionlie.inl"
194
195 #define SHIM_NS WinXPSP2VersionLie
196 #define VERSION_INFO g_WinXPSP2
197 #include "versionlie.inl"
198
199 #define SHIM_NS WinXPSP3VersionLie
200 #define VERSION_INFO g_WinXPSP3
201 #include "versionlie.inl"
202
203
204 #define SHIM_NS Win2k3RTMVersionLie
205 #define VERSION_INFO g_Win2k3RTM
206 #include "versionlie.inl"
207
208 #define SHIM_NS Win2k3SP1VersionLie
209 #define VERSION_INFO g_Win2k3SP1
210 #include "versionlie.inl"
211
212
213 #define SHIM_NS VistaRTMVersionLie
214 #define VERSION_INFO g_WinVistaRTM
215 #include "versionlie.inl"
216
217 #define SHIM_NS VistaSP1VersionLie
218 #define VERSION_INFO g_WinVistaSP1
219 #include "versionlie.inl"
220
221 #define SHIM_NS VistaSP2VersionLie
222 #define VERSION_INFO g_WinVistaSP2
223 #include "versionlie.inl"
224
225
226 #define SHIM_NS Win7RTMVersionLie
227 #define VERSION_INFO g_Win7RTM
228 #include "versionlie.inl"
229
230