1/*
2 * PROJECT:     ReactOS 'Layers' Shim library
3 * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE:     Version lie implementation helper
5 * COPYRIGHT:   Copyright 2016,2017 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8#include <setup_shim.inl>
9
10DWORD WINAPI SHIM_OBJ_NAME(APIHook_GetVersion)()
11{
12    return VERSION_INFO.FullVersion;
13}
14
15BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExA)(LPOSVERSIONINFOEXA lpOsVersionInfo)
16{
17    if (CALL_SHIM(0, GETVERSIONEXAPROC)(lpOsVersionInfo))
18    {
19        return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
20    }
21    return FALSE;
22}
23
24/* We do not care about the actual type, FakeVersion will correctly handle it either way */
25BOOL WINAPI SHIM_OBJ_NAME(APIHook_GetVersionExW)(LPOSVERSIONINFOEXA lpOsVersionInfo)
26{
27    if (CALL_SHIM(1, GETVERSIONEXAPROC)(lpOsVersionInfo))
28    {
29        return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
30    }
31    return FALSE;
32}
33
34/* We do not care about the actual type, FakeVersion will correctly handle it either way */
35BOOL WINAPI SHIM_OBJ_NAME(APIHook_RtlGetVersion)(LPOSVERSIONINFOEXA lpOsVersionInfo)
36{
37    if (CALL_SHIM(3, GETVERSIONEXAPROC)(lpOsVersionInfo))
38    {
39        return FakeVersion(lpOsVersionInfo, &VERSION_INFO);
40    }
41    return FALSE;
42}
43
44BOOL WINAPI SHIM_OBJ_NAME(Notify)(DWORD fdwReason, PVOID ptr)
45{
46    if (fdwReason == SHIM_NOTIFY_ATTACH && VERSION_INFO.wServicePackMajor)
47    {
48        static CONST WCHAR szServicePack[] = {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','%','u',0};
49        HRESULT hr = StringCbPrintfA(VERSION_INFO.szCSDVersionA, sizeof(VERSION_INFO.szCSDVersionA),
50            "Service Pack %u", VERSION_INFO.wServicePackMajor);
51        if (FAILED(hr))
52            return FALSE;
53        hr = StringCbPrintfW(VERSION_INFO.szCSDVersionW, sizeof(VERSION_INFO.szCSDVersionW),
54            szServicePack, VERSION_INFO.wServicePackMajor);
55        if (FAILED(hr))
56            return FALSE;
57    }
58    return TRUE;
59}
60
61
62#define SHIM_NUM_HOOKS  4
63#define SHIM_SETUP_HOOKS \
64    SHIM_HOOK(0, "KERNEL32.DLL", "GetVersionExA", SHIM_OBJ_NAME(APIHook_GetVersionExA)) \
65    SHIM_HOOK(1, "KERNEL32.DLL", "GetVersionExW", SHIM_OBJ_NAME(APIHook_GetVersionExW)) \
66    SHIM_HOOK(2, "KERNEL32.DLL", "GetVersion", SHIM_OBJ_NAME(APIHook_GetVersion)) \
67    SHIM_HOOK(3, "NTDLL.DLL", "RtlGetVersion", SHIM_OBJ_NAME(APIHook_RtlGetVersion))
68#define SHIM_NOTIFY_FN SHIM_OBJ_NAME(Notify)
69
70#include <implement_shim.inl>
71
72#undef VERSION_INFO
73
74