Skip to content
Snippets Groups Projects
Commit 0c385ef2 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Only use RtlGetVersion for Windows 10/11

This function appears to truncate the service pack info for Windows 7 (6.1):
"Windows NT Version 6.1 (Build 7601) Service Pack 1 x86" became:
"Windows NT Version 6.1 (Build 7601) S x86"

Don't close the handle to ntdll.dll (hey, that's stupid filename, Microsoft!)
since the module could be unloaded from the address space and then a call to
the captured procedure address could/would crash. This handle will be closed
when the process terminates anyway.

While we're here, correct the Windows 6.1 -> 7.0 numbering. That looks better:
"Windows NT Version 7.0 (Build 7601) Service Pack 1 x86"

Something should probably be done for Windows 6.2 -> 8.0 numbering too, but I
don't have a VM handy. Is anyone actually still running Windows 8.x?
parent d58cc13f
No related branches found
No related tags found
No related merge requests found
Pipeline #7407 passed
......@@ -782,22 +782,11 @@ char* os_version(char *str, size_t size)
/* Windows Version */
char* winflavor="";
OSVERSIONINFO winver;
static NTSTATUS (WINAPI *pRtlGetVersion)(PRTL_OSVERSIONINFOW lpVersionInformation) = NULL;
winver.dwOSVersionInfoSize=sizeof(winver);
if(pRtlGetVersion == NULL) {
HINSTANCE ntdll = LoadLibrary("ntdll.dll");
if(ntdll != NULL) {
pRtlGetVersion = (NTSTATUS (WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(ntdll, "RtlGetVersion");
FreeLibrary(ntdll);
}
}
if(pRtlGetVersion == NULL) {
#pragma warning(suppress : 4996) // error C4996: 'GetVersionExA': was declared deprecated
GetVersionEx(&winver);
} else
pRtlGetVersion((PRTL_OSVERSIONINFOW)&winver);
#pragma warning(suppress : 4996) // error C4996: 'GetVersionExA': was declared deprecated
GetVersionEx(&winver);
switch(winver.dwPlatformId) {
case VER_PLATFORM_WIN32_NT:
......@@ -812,6 +801,14 @@ char* os_version(char *str, size_t size)
}
if(winver.dwMajorVersion == 10 && winver.dwMinorVersion == 0) {
static NTSTATUS (WINAPI *pRtlGetVersion)(PRTL_OSVERSIONINFOW lpVersionInformation) = NULL;
if(pRtlGetVersion == NULL) {
HINSTANCE ntdll = LoadLibrary("ntdll.dll");
if(ntdll != NULL)
pRtlGetVersion = (NTSTATUS (WINAPI *)(PRTL_OSVERSIONINFOW))GetProcAddress(ntdll, "RtlGetVersion");
}
if(pRtlGetVersion != NULL)
pRtlGetVersion((PRTL_OSVERSIONINFOW)&winver);
if(winver.dwBuildNumber >= 22000)
winver.dwMajorVersion = 11;
}
......@@ -824,6 +821,10 @@ char* os_version(char *str, size_t size)
winver.dwBuildNumber = 0;
}
}
else if(winver.dwMajorVersion == 6 && winver.dwMinorVersion == 1) {
winver.dwMajorVersion = 7;
winver.dwMinorVersion = 0;
}
safe_snprintf(str, size, "Windows %sVersion %lu.%lu"
,winflavor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment