GetVersion, GetVersionExA and GetVersionExW reimplemented correctly (almost)

svn path=/trunk/; revision=4095
This commit is contained in:
KJK::Hyperion 2003-02-01 19:58:17 +00:00
parent c2e49604ca
commit 035dcd8224
2 changed files with 162 additions and 24 deletions

View file

@ -23,3 +23,4 @@
#include <napi/npipe.h> #include <napi/npipe.h>
#include <ntos/minmax.h> #include <ntos/minmax.h>
#include <csrss/csrss.h> #include <csrss/csrss.h>
#include <reactos/buildno.h>

View file

@ -1,4 +1,4 @@
/* $Id: env.c,v 1.18 2003/01/15 21:24:34 chorns Exp $ /* $Id: env.c,v 1.19 2003/02/01 19:58:17 hyperion Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -211,48 +211,185 @@ DWORD
STDCALL STDCALL
GetVersion(VOID) GetVersion(VOID)
{ {
DWORD Version = 0; PPEB pPeb = NtCurrentPeb();
OSVERSIONINFO VersionInformation; DWORD nVersion;
GetVersionExW(&VersionInformation);
Version |= ( VersionInformation.dwMajorVersion << 8 ); nVersion = MAKEWORD(pPeb->OSMajorVersion, pPeb->OSMinorVersion);
Version |= VersionInformation.dwMinorVersion;
Version |= ( VersionInformation.dwPlatformId << 16 ); /* behave consistently when posing as another operating system */
/* build number */
if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_WINDOWS)
nVersion |= ((DWORD)(pPeb->OSBuildNumber)) << 16;
/* non-NT platform flag */
if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_NT)
nVersion |= 0x80000000;
return Version; return nVersion;
} }
WINBOOL WINBOOL
STDCALL STDCALL
GetVersionExW( GetVersionExW(
LPOSVERSIONINFO lpVersionInformation LPOSVERSIONINFOW lpVersionInformation
) )
{ {
lpVersionInformation->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); PPEB pPeb = NtCurrentPeb();
lpVersionInformation->dwMajorVersion = 4;
lpVersionInformation->dwMinorVersion = 0; /* TODO: move this into RtlGetVersion */
lpVersionInformation->dwBuildNumber = 12; switch(lpVersionInformation->dwOSVersionInfoSize)
lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT; {
lstrcpyW((WCHAR *)lpVersionInformation->szCSDVersion,L"Ariadne was here..."); case sizeof(OSVERSIONINFOEXW):
return TRUE; {
LPOSVERSIONINFOEXW lpVersionInformationEx =
(LPOSVERSIONINFOEXW)lpVersionInformation;
lpVersionInformationEx->wServicePackMajor = pPeb->SPMajorVersion;
lpVersionInformationEx->wServicePackMinor = pPeb->SPMinorVersion;
/* TODO: read from the KUSER_SHARED_DATA */
lpVersionInformationEx->wSuiteMask = 0;
/* TODO: call RtlGetNtProductType */
lpVersionInformationEx->wProductType = 0;
/* ??? */
lpVersionInformationEx->wReserved = 0;
/* fall through */
}
case sizeof(OSVERSIONINFOW):
{
lpVersionInformation->dwMajorVersion = pPeb->OSMajorVersion;
lpVersionInformation->dwMinorVersion = pPeb->OSMinorVersion;
lpVersionInformation->dwBuildNumber = pPeb->OSBuildNumber;
lpVersionInformation->dwPlatformId = pPeb->OSPlatformId;
/* version string is "ReactOS x.y.z" */
wcsncpy
(
lpVersionInformation->szCSDVersion,
L"ReactOS " KERNEL_VERSION_STR,
sizeof(lpVersionInformation->szCSDVersion) / sizeof(WCHAR)
);
/* null-terminate, just in case */
lpVersionInformation->szCSDVersion
[
sizeof(lpVersionInformation->szCSDVersion) / sizeof(WCHAR) - 1
] = 0;
break;
}
default:
{
/* unknown version information revision */
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
}
return TRUE;
} }
WINBOOL WINBOOL
STDCALL STDCALL
GetVersionExA( GetVersionExA(
LPOSVERSIONINFO lpVersionInformation LPOSVERSIONINFOA lpVersionInformation
) )
{ {
lpVersionInformation->dwOSVersionInfoSize = sizeof(OSVERSIONINFO); NTSTATUS nErrCode;
lpVersionInformation->dwMajorVersion = 4; OSVERSIONINFOEXW oviVerInfo;
lpVersionInformation->dwMinorVersion = 0; LPOSVERSIONINFOEXA lpVersionInformationEx;
lpVersionInformation->dwBuildNumber = 12;
lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT; /* UNICODE_STRING descriptor of the Unicode version string */
lstrcpyA((char *)lpVersionInformation->szCSDVersion,"ReactOs Pre-Alpha"); UNICODE_STRING wstrVerStr =
return TRUE; {
/*
gives extra work to RtlUnicodeStringToAnsiString, but spares us an
RtlInitUnicodeString round
*/
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion) *
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion[0]) -
1,
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion) *
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion[0]),
oviVerInfo.szCSDVersion
};
/* ANSI_STRING descriptor of the ANSI version string buffer */
ANSI_STRING strVerStr =
{
0,
sizeof(((LPOSVERSIONINFOA)NULL)->szCSDVersion) *
sizeof(((LPOSVERSIONINFOA)NULL)->szCSDVersion[0]) -
1,
lpVersionInformation->szCSDVersion
};
switch(lpVersionInformation->dwOSVersionInfoSize)
{
case sizeof(OSVERSIONINFOEXA):
{
oviVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
break;
}
case sizeof(OSVERSIONINFOA):
{
oviVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
break;
}
default:
{
/* unknown version information revision */
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
}
if(!GetVersionExW((LPOSVERSIONINFOW)&oviVerInfo))
return FALSE;
/* null-terminate, just in case */
oviVerInfo.szCSDVersion
[
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion) *
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion[0]) -
1
] = 0;
/* convert the version string */
nErrCode = RtlUnicodeStringToAnsiString(&strVerStr, &wstrVerStr, FALSE);
if(!NT_SUCCESS(nErrCode))
{
/* failure */
SetLastErrorByStatus(nErrCode);
return FALSE;
}
/* copy the fields */
lpVersionInformation->dwMajorVersion = oviVerInfo.dwMajorVersion;
lpVersionInformation->dwMinorVersion = oviVerInfo.dwMinorVersion;
lpVersionInformation->dwBuildNumber = oviVerInfo.dwBuildNumber;
lpVersionInformation->dwPlatformId = oviVerInfo.dwPlatformId;
if(lpVersionInformation->dwOSVersionInfoSize < sizeof(OSVERSIONINFOEXA))
/* success */
return TRUE;
/* copy the extended fields */
lpVersionInformationEx = (LPOSVERSIONINFOEXA)lpVersionInformation;
lpVersionInformationEx->wServicePackMajor = oviVerInfo.wServicePackMajor;
lpVersionInformationEx->wServicePackMinor = oviVerInfo.wServicePackMinor;
lpVersionInformationEx->wSuiteMask = oviVerInfo.wSuiteMask;
lpVersionInformationEx->wProductType = oviVerInfo.wProductType;
lpVersionInformationEx->wReserved = oviVerInfo.wReserved;
/* success */
return TRUE;
} }