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