xref: /reactos/win32ss/user/rtl/image.c (revision bed8b2a0)
1 /*
2  * PROJECT:     ReactOS user32.dll and win32k.sys
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     RtlGetExpWinVer function
5  * COPYRIGHT:   Copyright 2019 James Tabor <james.tabor@reactos.org>
6  *              Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7  */
8 
9 #ifdef _WIN32K_
10 #include <win32k.h>
11 DBG_DEFAULT_CHANNEL(UserMisc);
12 #else
13 #include <user32.h>
14 #include <wine/debug.h>
15 WINE_DEFAULT_DEBUG_CHANNEL(user32);
16 #endif
17 
18 /* Get the expected OS version from the application module */
19 ULONG
20 RtlGetExpWinVer(_In_ PVOID BaseAddress)
21 {
22     ULONG dwMajorVersion = 3, dwMinorVersion = 10; /* Set default to Windows 3.10 (WINVER_WIN31) */
23     PIMAGE_NT_HEADERS pNTHeader;
24     ULONG_PTR AlignedAddress = (ULONG_PTR)BaseAddress;
25 
26     TRACE("(%p)\n", BaseAddress);
27 
28     /* Remove the magic flag for non-mapped images */
29     if (AlignedAddress & 1)
30         AlignedAddress = (AlignedAddress & ~1);
31 
32     if (AlignedAddress && !LOWORD(AlignedAddress))
33     {
34         pNTHeader = RtlImageNtHeader((PVOID)AlignedAddress);
35         if (pNTHeader)
36         {
37             dwMajorVersion = pNTHeader->OptionalHeader.MajorSubsystemVersion;
38             if (dwMajorVersion == 1)
39                 dwMajorVersion = 3;
40             else
41                 dwMinorVersion = pNTHeader->OptionalHeader.MinorSubsystemVersion;
42         }
43     }
44 
45     return MAKEWORD(dwMinorVersion, dwMajorVersion);
46 }
47