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