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 VersionLieInfo g_Win10RTM = { 0x47ba000a, 10, 0, 18362, VER_PLATFORM_WIN32_NT, 0, 0 }; 56 57 VersionLieInfo g_Win2k16RTM = { 0x3fab000a, 10, 0, 16299, VER_PLATFORM_WIN32_NT, 0, 0 }; 58 VersionLieInfo g_Win2k19RTM = { 0x4563000a, 10, 0, 17763, VER_PLATFORM_WIN32_NT, 0, 0 }; 59 60 /* Fill the OSVERSIONINFO[EX][W|A] struct with the info from the generic VersionLieInfo */ 61 62 BOOL FakeVersion(LPOSVERSIONINFOEXA pResult, VersionLieInfo* pFake) 63 { 64 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA) || 65 pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOW)) 66 { 67 pResult->dwMajorVersion = pFake->dwMajorVersion; 68 pResult->dwMinorVersion = pFake->dwMinorVersion; 69 pResult->dwBuildNumber = pFake->dwBuildNumber; 70 pResult->dwPlatformId = pFake->dwPlatformId; 71 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) || pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) 72 { 73 if (FAILED(StringCbCopyA(pResult->szCSDVersion, sizeof(pResult->szCSDVersion), pFake->szCSDVersionA))) 74 return FALSE; 75 if (pResult->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) 76 { 77 pResult->wServicePackMajor = pFake->wServicePackMajor; 78 pResult->wServicePackMinor = pFake->wServicePackMinor; 79 } 80 } 81 else 82 { 83 LPOSVERSIONINFOEXW pResultW = (LPOSVERSIONINFOEXW)pResult; 84 if (FAILED(StringCbCopyW(pResultW->szCSDVersion, sizeof(pResultW->szCSDVersion), pFake->szCSDVersionW))) 85 return FALSE; 86 if (pResultW->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW) && pFake->dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) 87 { 88 pResultW->wServicePackMajor = pFake->wServicePackMajor; 89 pResultW->wServicePackMinor = pFake->wServicePackMinor; 90 } 91 } 92 return TRUE; 93 } 94 return FALSE; 95 } 96 97 typedef BOOL(WINAPI* GETVERSIONEXAPROC)(LPOSVERSIONINFOEXA); 98 99 100 #define SHIM_NS Win95VersionLie 101 #include <setup_shim.inl> 102 103 DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)() 104 { 105 return g_Win95.FullVersion; 106 } 107 108 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo) 109 { 110 if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo)) 111 { 112 return FakeVersion(lpOsVersionInfo, &g_Win95); 113 } 114 return FALSE; 115 } 116 117 /* We do not call about the actual type, FakeVersion will correctly handle it either way */ 118 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo) 119 { 120 if (CALL_SHIM(2, GETVERSIONEXAPROC)(lpOsVersionInfo)) 121 { 122 return FakeVersion(lpOsVersionInfo, &g_Win95); 123 } 124 return FALSE; 125 } 126 127 #define SHIM_NUM_HOOKS 3 128 #define SHIM_SETUP_HOOKS \ 129 SHIM_HOOK(0, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \ 130 SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \ 131 SHIM_HOOK(2, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW)) 132 133 #include <implement_shim.inl> 134 135 136 137 138 #define SHIM_NS Win98VersionLie 139 #include <setup_shim.inl> 140 141 DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)() 142 { 143 return g_Win98.FullVersion; 144 } 145 146 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo) 147 { 148 if (CALL_SHIM(0, GETVERSIONEXAPROC)(lpOsVersionInfo)) 149 { 150 return FakeVersion(lpOsVersionInfo, &g_Win98); 151 } 152 return FALSE; 153 } 154 155 /* We do not call about the actual type, FakeVersion will correctly handle it either way */ 156 BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo) 157 { 158 if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo)) 159 { 160 return FakeVersion(lpOsVersionInfo, &g_Win98); 161 } 162 return FALSE; 163 } 164 165 #define SHIM_NUM_HOOKS 3 166 #define SHIM_SETUP_HOOKS \ 167 SHIM_HOOK(2, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \ 168 SHIM_HOOK(0, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \ 169 SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW)) 170 171 #include <implement_shim.inl> 172 173 174 175 #define SHIM_NS WinNT4SP5VersionLie 176 #define VERSION_INFO g_WinNT4SP5 177 #include "versionlie.inl" 178 179 180 #define SHIM_NS Win2000VersionLie 181 #define VERSION_INFO g_Win2000 182 #include "versionlie.inl" 183 184 #define SHIM_NS Win2000SP1VersionLie 185 #define VERSION_INFO g_Win2000SP1 186 #include "versionlie.inl" 187 188 #define SHIM_NS Win2000SP2VersionLie 189 #define VERSION_INFO g_Win2000SP2 190 #include "versionlie.inl" 191 192 #define SHIM_NS Win2000SP3VersionLie 193 #define VERSION_INFO g_Win2000SP3 194 #include "versionlie.inl" 195 196 197 #define SHIM_NS WinXPVersionLie 198 #define VERSION_INFO g_WinXP 199 #include "versionlie.inl" 200 201 #define SHIM_NS WinXPSP1VersionLie 202 #define VERSION_INFO g_WinXPSP1 203 #include "versionlie.inl" 204 205 #define SHIM_NS WinXPSP2VersionLie 206 #define VERSION_INFO g_WinXPSP2 207 #include "versionlie.inl" 208 209 #define SHIM_NS WinXPSP3VersionLie 210 #define VERSION_INFO g_WinXPSP3 211 #include "versionlie.inl" 212 213 214 #define SHIM_NS Win2k3RTMVersionLie 215 #define VERSION_INFO g_Win2k3RTM 216 #include "versionlie.inl" 217 218 #define SHIM_NS Win2k3SP1VersionLie 219 #define VERSION_INFO g_Win2k3SP1 220 #include "versionlie.inl" 221 222 223 #define SHIM_NS VistaRTMVersionLie 224 #define VERSION_INFO g_WinVistaRTM 225 #include "versionlie.inl" 226 227 #define SHIM_NS VistaSP1VersionLie 228 #define VERSION_INFO g_WinVistaSP1 229 #include "versionlie.inl" 230 231 #define SHIM_NS VistaSP2VersionLie 232 #define VERSION_INFO g_WinVistaSP2 233 #include "versionlie.inl" 234 235 236 #define SHIM_NS Win7RTMVersionLie 237 #define VERSION_INFO g_Win7RTM 238 #include "versionlie.inl" 239 240 #define SHIM_NS Win7SP1VersionLie 241 #define VERSION_INFO g_Win7SP1 242 #include "versionlie.inl" 243 244 245 #define SHIM_NS Win8RTMVersionLie 246 #define VERSION_INFO g_Win8RTM 247 #include "versionlie.inl" 248 249 #define SHIM_NS Win81RTMVersionLie 250 #define VERSION_INFO g_Win81RTM 251 #include "versionlie.inl" 252 253 254 #define SHIM_NS Win10RTMVersionLie 255 #define VERSION_INFO g_Win10RTM 256 #include "versionlie.inl" 257 258 259 #define SHIM_NS Win2k16RTMVersionLie 260 #define VERSION_INFO g_Win2k16RTM 261 #include "versionlie.inl" 262 263 264 #define SHIM_NS Win2k19RTMVersionLie 265 #define VERSION_INFO g_Win2k19RTM 266 #include "versionlie.inl" 267