VirtualBox

Changeset 50976 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 4, 2014 7:34:38 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
93145
Message:

RTSystemQueryOSInfo-win.cpp,init-win.cpp: Detect windows 8.1 correctly, it will try hide from us if we use GetVersionEx and the like. Fixed bug in service pack query where it would return ANSI strings instead of UTF-8 strings.

Location:
trunk/src/VBox/Runtime/r3/win
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp

    r47596 r50976  
    261261            {
    262262                /* just copy the entire string. */
    263                 memcpy(szTmp, g_WinOsInfoEx.szCSDVersion, sizeof(g_WinOsInfoEx.szCSDVersion));
    264                 szTmp[sizeof(g_WinOsInfoEx.szCSDVersion)] = '\0';
     263                char *pszTmp = szTmp;
     264                int rc = RTUtf16ToUtf8Ex(g_WinOsInfoEx.szCSDVersion, RT_ELEMENTS(g_WinOsInfoEx.szCSDVersion),
     265                                         &pszTmp, sizeof(szTmp), NULL);
     266                if (RT_SUCCESS(rc))
     267                    RTStrStripR(szTmp);
     268                else
     269                    szTmp[0] = '\0';
    265270                AssertCompile(sizeof(szTmp) > sizeof(g_WinOsInfoEx.szCSDVersion));
    266271            }
  • trunk/src/VBox/Runtime/r3/win/init-win.cpp

    r48304 r50976  
    4848*******************************************************************************/
    4949/** Windows DLL loader protection level. */
    50 DECLHIDDEN(RTR3WINLDRPROT)  g_enmWinLdrProt = RTR3WINLDRPROT_NONE;
     50DECLHIDDEN(RTR3WINLDRPROT)      g_enmWinLdrProt = RTR3WINLDRPROT_NONE;
    5151/** Our simplified windows version.    */
    52 DECLHIDDEN(RTWINOSTYPE)     g_enmWinVer = kRTWinOSType_UNKNOWN;
     52DECLHIDDEN(RTWINOSTYPE)         g_enmWinVer = kRTWinOSType_UNKNOWN;
    5353/** Extended windows version information. */
    54 DECLHIDDEN(OSVERSIONINFOEX) g_WinOsInfoEx;
     54DECLHIDDEN(OSVERSIONINFOEXW)    g_WinOsInfoEx;
    5555/** The native kernel32.dll handle. */
    56 DECLHIDDEN(HMODULE)         g_hModKernel32 = NULL;
     56DECLHIDDEN(HMODULE)             g_hModKernel32 = NULL;
    5757/** The native ntdll.dll handle. */
    58 DECLHIDDEN(HMODULE)         g_hModNtDll = NULL;
     58DECLHIDDEN(HMODULE)             g_hModNtDll = NULL;
    5959
    6060
     
    9292</pre>
    9393 */
    94 static RTWINOSTYPE rtR3InitWinSimplifiedVersion(OSVERSIONINFOEX const *pOSInfoEx)
     94static RTWINOSTYPE rtR3InitWinSimplifiedVersion(OSVERSIONINFOEXW const *pOSInfoEx)
    9595{
    9696    RTWINOSTYPE enmVer         = kRTWinOSType_UNKNOWN;
     
    169169
    170170
    171 DECLHIDDEN(int) rtR3InitNativeObtrusiveWorker(void)
     171/**
     172 * Initializes the global variables related to windows version.
     173 */
     174static void rtR3InitWindowsVersion(void)
     175{
     176    Assert(g_hModNtDll != NULL);
     177
     178    /*
     179     * ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe).
     180     */
     181    AssertCompileMembersSameSizeAndOffset(OSVERSIONINFOEX, szCSDVersion, OSVERSIONINFO, szCSDVersion);
     182    AssertCompileMemberOffset(OSVERSIONINFOEX, wServicePackMajor, sizeof(OSVERSIONINFO));
     183
     184    /*
     185     * Use the NT version of GetVersionExW so we don't get fooled by
     186     * compatability shims.
     187     */
     188    RT_ZERO(g_WinOsInfoEx);
     189    g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     190
     191    LONG (__stdcall *pfnRtlGetVersion)(OSVERSIONINFOEXW *);
     192    *(FARPROC *)&pfnRtlGetVersion = GetProcAddress(g_hModNtDll, "RtlGetVersion");
     193    LONG rcNt = -1;
     194    if (pfnRtlGetVersion)
     195        rcNt = pfnRtlGetVersion(&g_WinOsInfoEx);
     196    if (rcNt != 0)
     197    {
     198        /*
     199         * Couldn't find it or it failed, try the windows version of the API.
     200         */
     201        RT_ZERO(g_WinOsInfoEx);
     202        g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
     203        if (!GetVersionExW((POSVERSIONINFOW)&g_WinOsInfoEx))
     204        {
     205            /*
     206             * If that didn't work either, just get the basic version bits.
     207             */
     208            RT_ZERO(g_WinOsInfoEx);
     209            g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
     210            if (GetVersionExA((POSVERSIONINFOA)&g_WinOsInfoEx))
     211                Assert(g_WinOsInfoEx.dwPlatformId != VER_PLATFORM_WIN32_NT || g_WinOsInfoEx.dwMajorVersion < 5);
     212            else
     213            {
     214                AssertBreakpoint();
     215                RT_ZERO(g_WinOsInfoEx);
     216            }
     217        }
     218    }
     219
     220    if (g_WinOsInfoEx.dwOSVersionInfoSize)
     221        g_enmWinVer = rtR3InitWinSimplifiedVersion(&g_WinOsInfoEx);
     222}
     223
     224
     225static int rtR3InitNativeObtrusiveWorker(void)
    172226{
    173227    /*
     
    176230    UINT fOldErrMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
    177231    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | fOldErrMode);
    178 
    179     /*
    180      * Query the Windows version.
    181      * ASSUMES OSVERSIONINFOEX starts with the exact same layout as OSVERSIONINFO (safe).
    182      */
    183     AssertCompileMembersSameSizeAndOffset(OSVERSIONINFOEX, szCSDVersion, OSVERSIONINFO, szCSDVersion);
    184     AssertCompileMemberOffset(OSVERSIONINFOEX, wServicePackMajor, sizeof(OSVERSIONINFO));
    185     RT_ZERO(g_WinOsInfoEx);
    186     g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    187     if (!GetVersionExA((POSVERSIONINFOA)&g_WinOsInfoEx))
    188     {
    189         /* Fallback, just get the basic info. */
    190         RT_ZERO(g_WinOsInfoEx);
    191         g_WinOsInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    192         if (GetVersionExA((POSVERSIONINFOA)&g_WinOsInfoEx))
    193             Assert(g_WinOsInfoEx.dwPlatformId != VER_PLATFORM_WIN32_NT || g_WinOsInfoEx.dwMajorVersion < 5);
    194         else
    195         {
    196             AssertBreakpoint();
    197             RT_ZERO(g_WinOsInfoEx);
    198         }
    199     }
    200     if (g_WinOsInfoEx.dwOSVersionInfoSize)
    201         g_enmWinVer = rtR3InitWinSimplifiedVersion(&g_WinOsInfoEx);
    202232
    203233    /*
     
    252282        return VERR_INTERNAL_ERROR_2;
    253283
     284    rtR3InitWindowsVersion();
     285
    254286    int rc = VINF_SUCCESS;
    255287    if (!(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
  • trunk/src/VBox/Runtime/r3/win/internal-r3-win.h

    r47596 r50976  
    6060*   Global Variables                                                           *
    6161*******************************************************************************/
    62 extern DECLHIDDEN(RTR3WINLDRPROT)  g_enmWinLdrProt;
    63 extern DECLHIDDEN(RTWINOSTYPE)     g_enmWinVer;
     62extern DECLHIDDEN(RTR3WINLDRPROT)   g_enmWinLdrProt;
     63extern DECLHIDDEN(RTWINOSTYPE)      g_enmWinVer;
    6464#ifdef _WINDEF_
    65 extern DECLHIDDEN(HMODULE)         g_hModKernel32;
    66 extern DECLHIDDEN(HMODULE)         g_hModNtDll;
    67 extern DECLHIDDEN(OSVERSIONINFOEX) g_WinOsInfoEx;
     65extern DECLHIDDEN(HMODULE)          g_hModKernel32;
     66extern DECLHIDDEN(HMODULE)          g_hModNtDll;
     67extern DECLHIDDEN(OSVERSIONINFOEXW) g_WinOsInfoEx;
    6868#endif
    6969
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette