1. made the PEB structure match xp's layout

2. fixed GetVersionEx()

svn path=/trunk/; revision=13639
This commit is contained in:
Thomas Bluemel 2005-02-19 03:38:43 +00:00
parent c8ad5d3ade
commit 5239de8ad5
4 changed files with 107 additions and 176 deletions

View file

@ -105,8 +105,8 @@ typedef struct _PEB
UCHAR InheritedAddressSpace; /* 00h */ UCHAR InheritedAddressSpace; /* 00h */
UCHAR ReadImageFileExecOptions; /* 01h */ UCHAR ReadImageFileExecOptions; /* 01h */
UCHAR BeingDebugged; /* 02h */ UCHAR BeingDebugged; /* 02h */
UCHAR Spare; /* 03h */ BOOLEAN SpareBool; /* 03h */
PVOID Mutant; /* 04h */ HANDLE Mutant; /* 04h */
PVOID ImageBaseAddress; /* 08h */ PVOID ImageBaseAddress; /* 08h */
PPEB_LDR_DATA Ldr; /* 0Ch */ PPEB_LDR_DATA Ldr; /* 0Ch */
PRTL_USER_PROCESS_PARAMETERS ProcessParameters; /* 10h */ PRTL_USER_PROCESS_PARAMETERS ProcessParameters; /* 10h */
@ -131,7 +131,6 @@ typedef struct _PEB
PVOID UnicodeCaseTableData; /* 60h */ PVOID UnicodeCaseTableData; /* 60h */
ULONG NumberOfProcessors; /* 64h */ ULONG NumberOfProcessors; /* 64h */
ULONG NtGlobalFlag; /* 68h */ ULONG NtGlobalFlag; /* 68h */
UCHAR Spare2[0x4]; /* 6Ch */
LARGE_INTEGER CriticalSectionTimeout; /* 70h */ LARGE_INTEGER CriticalSectionTimeout; /* 70h */
ULONG HeapSegmentReserve; /* 78h */ ULONG HeapSegmentReserve; /* 78h */
ULONG HeapSegmentCommit; /* 7Ch */ ULONG HeapSegmentCommit; /* 7Ch */
@ -139,7 +138,7 @@ typedef struct _PEB
ULONG HeapDeCommitFreeBlockThreshold; /* 84h */ ULONG HeapDeCommitFreeBlockThreshold; /* 84h */
ULONG NumberOfHeaps; /* 88h */ ULONG NumberOfHeaps; /* 88h */
ULONG MaximumNumberOfHeaps; /* 8Ch */ ULONG MaximumNumberOfHeaps; /* 8Ch */
PVOID** ProcessHeaps; /* 90h */ PVOID* ProcessHeaps; /* 90h */
PVOID GdiSharedHandleTable; /* 94h */ PVOID GdiSharedHandleTable; /* 94h */
PVOID ProcessStarterHelper; /* 98h */ PVOID ProcessStarterHelper; /* 98h */
PVOID GdiDCAttributeList; /* 9Ch */ PVOID GdiDCAttributeList; /* 9Ch */
@ -147,13 +146,19 @@ typedef struct _PEB
ULONG OSMajorVersion; /* A4h */ ULONG OSMajorVersion; /* A4h */
ULONG OSMinorVersion; /* A8h */ ULONG OSMinorVersion; /* A8h */
USHORT OSBuildNumber; /* ACh */ USHORT OSBuildNumber; /* ACh */
UCHAR SPMajorVersion; /* AEh */ USHORT OSCSDVersion; /* AEh */
UCHAR SPMinorVersion; /* AFh */
ULONG OSPlatformId; /* B0h */ ULONG OSPlatformId; /* B0h */
ULONG ImageSubSystem; /* B4h */ ULONG ImageSubSystem; /* B4h */
ULONG ImageSubSystemMajorVersion; /* B8h */ ULONG ImageSubSystemMajorVersion; /* B8h */
ULONG ImageSubSystemMinorVersion; /* C0h */ ULONG ImageSubSystemMinorVersion; /* BCh */
ULONG ImageProcessAffinityMask; /* C0h */
ULONG GdiHandleBuffer[0x22]; /* C4h */ ULONG GdiHandleBuffer[0x22]; /* C4h */
PVOID PostProcessInitRoutine; /* 14Ch */
PVOID *TlsExpansionBitmap; /* 150h */
ULONG TlsExpansionBitmapBits[0x20]; /* 154h */
ULONG SessionId; /* 1D4h */
PVOID AppCompatInfo; /* 1D8h */
UNICODE_STRING CSDVersion; /* 1DCh */
} PEB; } PEB;
#ifndef __USE_W32API #ifndef __USE_W32API

View file

@ -226,21 +226,21 @@ DWORD
STDCALL STDCALL
GetVersion(VOID) GetVersion(VOID)
{ {
PPEB pPeb = NtCurrentPeb(); PPEB pPeb = NtCurrentPeb();
DWORD nVersion; DWORD nVersion;
nVersion = MAKEWORD(pPeb->OSMajorVersion, pPeb->OSMinorVersion); nVersion = MAKEWORD(pPeb->OSMajorVersion, pPeb->OSMinorVersion);
/* behave consistently when posing as another operating system */ /* behave consistently when posing as another operating system */
/* build number */ /* build number */
if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_WINDOWS) if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_WINDOWS)
nVersion |= ((DWORD)(pPeb->OSBuildNumber)) << 16; nVersion |= ((DWORD)(pPeb->OSBuildNumber)) << 16;
/* non-NT platform flag */ /* non-NT platform flag */
if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_NT) if(pPeb->OSPlatformId != VER_PLATFORM_WIN32_NT)
nVersion |= 0x80000000; nVersion |= 0x80000000;
return nVersion; return nVersion;
} }
@ -253,67 +253,44 @@ GetVersionExW(
LPOSVERSIONINFOW lpVersionInformation LPOSVERSIONINFOW lpVersionInformation
) )
{ {
PPEB pPeb = NtCurrentPeb(); NTSTATUS Status;
WCHAR *RosVersion;
if(lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
/* TODO: move this into RtlGetVersion */ lpVersionInformation->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
switch(lpVersionInformation->dwOSVersionInfoSize)
{
case sizeof(OSVERSIONINFOEXW):
{ {
LPOSVERSIONINFOEXW lpVersionInformationEx = /* for some reason win sets ERROR_INSUFFICIENT_BUFFER even if it is large
(LPOSVERSIONINFOEXW)lpVersionInformation; enough but doesn't match the exact sizes supported, ERROR_INVALID_PARAMETER
would've been much more appropriate... */
lpVersionInformationEx->wServicePackMajor = pPeb->SPMajorVersion; SetLastError(ERROR_INSUFFICIENT_BUFFER);
lpVersionInformationEx->wServicePackMinor = pPeb->SPMinorVersion; return FALSE;
/* TODO: read from the KUSER_SHARED_DATA */
lpVersionInformationEx->wSuiteMask = 0;
/* TODO: call RtlGetNtProductType */
lpVersionInformationEx->wProductType = 0;
/* ??? */
lpVersionInformationEx->wReserved = 0;
/* fall through */
} }
case sizeof(OSVERSIONINFOW): Status = RtlGetVersion((PRTL_OSVERSIONINFOW)lpVersionInformation);
if(NT_SUCCESS(Status))
{ {
lpVersionInformation->dwMajorVersion = pPeb->OSMajorVersion; int ln, maxlen;
lpVersionInformation->dwMinorVersion = pPeb->OSMinorVersion;
lpVersionInformation->dwBuildNumber = pPeb->OSBuildNumber; /* append a reactos specific string to the szCSDVersion string */
lpVersionInformation->dwPlatformId = pPeb->OSPlatformId;
/* First the Windows compatible string */ /* FIXME - we shouldn't do this when there is a (ros-specific) compatibility
_snwprintf(lpVersionInformation->szCSDVersion, flag set so we don't screw applications that might depend on a
sizeof(lpVersionInformation->szCSDVersion) / sizeof(WCHAR), certain string */
L"Service Pack %u", pPeb->SPMajorVersion);
/* Add the Reactos-specific string */
RosVersion = lpVersionInformation->szCSDVersion + wcslen(lpVersionInformation->szCSDVersion) + 1;
wcsncpy
(
RosVersion,
L"ReactOS " KERNEL_VERSION_STR L" (Build " KERNEL_VERSION_BUILD_STR L")",
sizeof(lpVersionInformation->szCSDVersion) / sizeof(WCHAR) -
((RosVersion - lpVersionInformation->szCSDVersion) + 1)
);
/* null-terminate, just in case */ ln = wcslen(lpVersionInformation->szCSDVersion);
lpVersionInformation->szCSDVersion maxlen = (sizeof(lpVersionInformation->szCSDVersion) / sizeof(lpVersionInformation->szCSDVersion[0]) - 1);
[ if(maxlen > ln)
sizeof(lpVersionInformation->szCSDVersion) / sizeof(WCHAR) - 1 {
] = 0; PWCHAR szVer = lpVersionInformation->szCSDVersion + ln;
RtlZeroMemory(szVer, (maxlen - ln + 1) * sizeof(WCHAR));
break; wcsncpy(szVer,
L" ReactOS " KERNEL_VERSION_STR L" (Build " KERNEL_VERSION_BUILD_STR L")",
maxlen - ln);
}
return TRUE;
} }
default: return FALSE;
{
/* unknown version information revision */
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
}
return TRUE;
} }
@ -326,111 +303,61 @@ GetVersionExA(
LPOSVERSIONINFOA lpVersionInformation LPOSVERSIONINFOA lpVersionInformation
) )
{ {
NTSTATUS nErrCode; OSVERSIONINFOEXW viw;
OSVERSIONINFOEXW oviVerInfo;
LPOSVERSIONINFOEXA lpVersionInformationEx; RtlZeroMemory(&viw, sizeof(viw));
/* UNICODE_STRING descriptor of the Unicode version string */ switch(lpVersionInformation->dwOSVersionInfoSize)
UNICODE_STRING wstrVerStr =
{
/*
gives extra work to RtlUnicodeStringToAnsiString, but spares us an
RtlInitUnicodeString round
*/
0,
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion),
oviVerInfo.szCSDVersion
};
/* ANSI_STRING descriptor of the ANSI version string buffer */
ANSI_STRING strVerStr =
{
0,
sizeof(((LPOSVERSIONINFOA)NULL)->szCSDVersion),
lpVersionInformation->szCSDVersion
};
switch(lpVersionInformation->dwOSVersionInfoSize)
{
case sizeof(OSVERSIONINFOEXA):
{ {
oviVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); case sizeof(OSVERSIONINFOA):
break; viw.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
} break;
case sizeof(OSVERSIONINFOA): case sizeof(OSVERSIONINFOEXA):
viw.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
break;
default:
/* for some reason win sets ERROR_INSUFFICIENT_BUFFER even if it is large
enough but doesn't match the exact sizes supported, ERROR_INVALID_PARAMETER
would've been much more appropriate... */
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
if(GetVersionExW((LPOSVERSIONINFOW)&viw))
{ {
oviVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); ANSI_STRING CSDVersionA;
break; UNICODE_STRING CSDVersionW;
/* copy back fields that match both supported structures */
lpVersionInformation->dwMajorVersion = viw.dwMajorVersion;
lpVersionInformation->dwMinorVersion = viw.dwMinorVersion;
lpVersionInformation->dwBuildNumber = viw.dwBuildNumber;
lpVersionInformation->dwPlatformId = viw.dwPlatformId;
RtlInitUnicodeString(&CSDVersionW, viw.szCSDVersion);
CSDVersionA.Length = 0;
CSDVersionA.MaximumLength = sizeof(lpVersionInformation->szCSDVersion);
CSDVersionA.Buffer = lpVersionInformation->szCSDVersion;
RtlUnicodeStringToAnsiString(&CSDVersionA, &CSDVersionW, FALSE);
/* copy back the extended fields */
if(viw.dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXW))
{
((LPOSVERSIONINFOEXA)lpVersionInformation)->wServicePackMajor = viw.wServicePackMajor;
((LPOSVERSIONINFOEXA)lpVersionInformation)->wServicePackMinor = viw.wServicePackMinor;
((LPOSVERSIONINFOEXA)lpVersionInformation)->wSuiteMask = viw.wSuiteMask;
((LPOSVERSIONINFOEXA)lpVersionInformation)->wProductType = viw.wProductType;
((LPOSVERSIONINFOEXA)lpVersionInformation)->wReserved = viw.wReserved;
}
return TRUE;
} }
default:
{
/* unknown version information revision */
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
}
if(!GetVersionExW((LPOSVERSIONINFOW)&oviVerInfo))
return FALSE; return FALSE;
/* null-terminate, just in case */
oviVerInfo.szCSDVersion
[
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion) /
sizeof(((LPOSVERSIONINFOW)NULL)->szCSDVersion[0]) -
1
] = 0;
wstrVerStr.Length = wcslen(wstrVerStr.Buffer) * sizeof(WCHAR);
/* convert the win version string */
nErrCode = RtlUnicodeStringToAnsiString(&strVerStr, &wstrVerStr, FALSE);
if(!NT_SUCCESS(nErrCode))
{
/* failure */
SetLastErrorByStatus(nErrCode);
return FALSE;
}
wstrVerStr.Buffer = oviVerInfo.szCSDVersion + wstrVerStr.Length / sizeof(WCHAR) + 1;
wstrVerStr.MaximumLength = sizeof(oviVerInfo.szCSDVersion) - (wstrVerStr.Length + sizeof(WCHAR));
wstrVerStr.Length = wcslen(wstrVerStr.Buffer) * sizeof(WCHAR);
strVerStr.Buffer = lpVersionInformation->szCSDVersion + strVerStr.Length + 1;
strVerStr.MaximumLength = sizeof(lpVersionInformation->szCSDVersion) - (strVerStr.Length + 1);
strVerStr.Length = 0;
/* convert the ReactOS 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;
} }

View file

@ -207,10 +207,9 @@ LoadCompatibilitySettings(PPEB Peb)
Peb->OSPlatformId = (ULONG)PlatformId; Peb->OSPlatformId = (ULONG)PlatformId;
/* optional service pack version numbers */ /* optional service pack version numbers */
if(ReadCompatibilitySetting(SubKeyHandle, L"SPMajorVersion", ValueInfo, &SPMajorVersion)) if(ReadCompatibilitySetting(SubKeyHandle, L"SPMajorVersion", ValueInfo, &SPMajorVersion) &&
Peb->SPMajorVersion = (UCHAR)SPMajorVersion; ReadCompatibilitySetting(SubKeyHandle, L"SPMinorVersion", ValueInfo, &SPMinorVersion))
if(ReadCompatibilitySetting(SubKeyHandle, L"SPMinorVersion", ValueInfo, &SPMinorVersion)) Peb->OSCSDVersion = ((SPMajorVersion & 0xFF) << 8) | (SPMinorVersion & 0xFF);
Peb->SPMinorVersion = (UCHAR)SPMinorVersion;
finish: finish:
/* we're finished */ /* we're finished */

View file

@ -569,7 +569,7 @@ PsCreatePeb(HANDLE ProcessHandle,
Peb->OSMinorVersion = 0; Peb->OSMinorVersion = 0;
Peb->OSBuildNumber = 1381; Peb->OSBuildNumber = 1381;
Peb->OSPlatformId = 2; //VER_PLATFORM_WIN32_NT; Peb->OSPlatformId = 2; //VER_PLATFORM_WIN32_NT;
Peb->SPMajorVersion = 6; Peb->OSCSDVersion = 6 << 8;
Peb->AnsiCodePageData = (char*)TableBase + NlsAnsiTableOffset; Peb->AnsiCodePageData = (char*)TableBase + NlsAnsiTableOffset;
Peb->OemCodePageData = (char*)TableBase + NlsOemTableOffset; Peb->OemCodePageData = (char*)TableBase + NlsOemTableOffset;