Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

version.c File Reference

#include <stdio.h>
#include <ntrtlp.h>
#include <winerror.h>

Go to the source code of this file.

Defines

#define NEW_STYLE_BIT_MASK   0x8000000000000000
#define OLD_CONDITION(_m_, _t_)   (ULONG)((_m_&(0xff<<(1<<_t_)))>>(1<<_t_))
#define OLD_STYLE_CONDITION_MASK(_m_)   (((_m_) & NEW_STYLE_BIT_MASK) == 0)
#define RTL_GET_CONDITION(_m_, _t_)
#define LEXICAL_COMPARISON   1 /* Do string comparison. Used for minor numbers */
#define MAX_STRING_LENGTH   20 /* Maximum number of digits for sprintf */

Functions

ULONG RtlpVerGetConditionMask (ULONGLONG ConditionMask, ULONG TypeMask)
NTSTATUS RtlGetVersion (OUT PRTL_OSVERSIONINFOW lpVersionInformation)
BOOLEAN RtlpVerCompare (LONG Condition, LONG Value1, LONG Value2, BOOLEAN *Equal, int Flags)
NTSTATUS RtlVerifyVersionInfo (IN PRTL_OSVERSIONINFOEXW VersionInfo, IN ULONG TypeMask, IN ULONGLONG ConditionMask)
ULONGLONG VerSetConditionMask (ULONGLONG ConditionMask, ULONG TypeMask, UCHAR Condition)


Define Documentation

#define LEXICAL_COMPARISON   1 /* Do string comparison. Used for minor numbers */
 

Definition at line 77 of file version.c.

Referenced by RtlpVerCompare(), and RtlVerifyVersionInfo().

#define MAX_STRING_LENGTH   20 /* Maximum number of digits for sprintf */
 

Definition at line 78 of file version.c.

Referenced by RtlpVerCompare().

#define NEW_STYLE_BIT_MASK   0x8000000000000000
 

Definition at line 60 of file version.c.

Referenced by VerSetConditionMask().

#define OLD_CONDITION _m_,
_t_   )     (ULONG)((_m_&(0xff<<(1<<_t_)))>>(1<<_t_))
 

Definition at line 66 of file version.c.

#define OLD_STYLE_CONDITION_MASK _m_   )     (((_m_) & NEW_STYLE_BIT_MASK) == 0)
 

Definition at line 71 of file version.c.

#define RTL_GET_CONDITION _m_,
_t_   ) 
 

Value:

(OLD_STYLE_CONDITION_MASK(_m_) ? (OLD_CONDITION(_m_,_t_)) : \ RtlpVerGetConditionMask((_m_), (_t_)))

Definition at line 73 of file version.c.

Referenced by RtlVerifyVersionInfo().


Function Documentation

NTSTATUS RtlGetVersion OUT PRTL_OSVERSIONINFOW  lpVersionInformation  ) 
 

Definition at line 132 of file version.c.

References RtlGetNtProductType(), and USHORT.

Referenced by RtlVerifyVersionInfo().

00135 { 00136 PPEB Peb; 00137 NT_PRODUCT_TYPE NtProductType; 00138 00139 Peb = NtCurrentPeb(); 00140 lpVersionInformation->dwMajorVersion = Peb->OSMajorVersion; 00141 lpVersionInformation->dwMinorVersion = Peb->OSMinorVersion; 00142 lpVersionInformation->dwBuildNumber = Peb->OSBuildNumber; 00143 lpVersionInformation->dwPlatformId = Peb->OSPlatformId; 00144 if (lpVersionInformation->dwOSVersionInfoSize == sizeof( OSVERSIONINFOEXW )) 00145 { 00146 ((POSVERSIONINFOEXW)lpVersionInformation)->wServicePackMajor = (Peb->OSCSDVersion >> 8) & 0xFF; 00147 ((POSVERSIONINFOEXW)lpVersionInformation)->wServicePackMinor = Peb->OSCSDVersion & 0xFF; 00148 ((POSVERSIONINFOEXW)lpVersionInformation)->wSuiteMask = (USHORT)(USER_SHARED_DATA->SuiteMask&0xffff); 00149 ((POSVERSIONINFOEXW)lpVersionInformation)->wProductType = 0; 00150 if (RtlGetNtProductType( &NtProductType )) { 00151 ((POSVERSIONINFOEXW)lpVersionInformation)->wProductType = (UCHAR)NtProductType; 00152 } 00153 } 00154 00155 return STATUS_SUCCESS; 00156 }

BOOLEAN RtlpVerCompare LONG  Condition,
LONG  Value1,
LONG  Value2,
BOOLEAN *  Equal,
int  Flags
 

Definition at line 161 of file version.c.

References FALSE, LEXICAL_COMPARISON, MAX_STRING_LENGTH, sprintf(), String1, and String2.

Referenced by RtlVerifyVersionInfo().

00168 { 00169 char String1[MAX_STRING_LENGTH]; 00170 char String2[MAX_STRING_LENGTH]; 00171 LONG Comparison; 00172 00173 if (Flags & LEXICAL_COMPARISON) { 00174 sprintf(String1, "%d", Value1); 00175 sprintf(String2, "%d", Value2); 00176 Comparison = strcmp(String2, String1); 00177 Value1 = 0; 00178 Value2 = Comparison; 00179 } 00180 *Equal = (Value1 == Value2); 00181 switch (Condition) { 00182 case VER_EQUAL: 00183 return (Value2 == Value1); 00184 00185 case VER_GREATER: 00186 return (Value2 > Value1); 00187 00188 case VER_LESS: 00189 return (Value2 < Value1); 00190 00191 case VER_GREATER_EQUAL: 00192 return (Value2 >= Value1); 00193 00194 case VER_LESS_EQUAL: 00195 return (Value2 <= Value1); 00196 00197 default: 00198 break; 00199 } 00200 00201 return FALSE; 00202 }

ULONG RtlpVerGetConditionMask ULONGLONG  ConditionMask,
ULONG  TypeMask
 

Definition at line 397 of file version.c.

Referenced by RtlVerifyVersionInfo().

00401 { 00402 ULONG NumBitsToShift; 00403 ULONG Condition = 0; 00404 00405 if (!TypeMask) { 00406 return 0; 00407 } 00408 00409 for (NumBitsToShift = 0; TypeMask; NumBitsToShift++) { 00410 TypeMask >>= 1; 00411 } 00412 00413 Condition |= (ConditionMask) >> ((NumBitsToShift - 1) 00414 * VER_NUM_BITS_PER_CONDITION_MASK); 00415 Condition &= VER_CONDITION_MASK; 00416 return Condition; 00417 }

NTSTATUS RtlVerifyVersionInfo IN PRTL_OSVERSIONINFOEXW  VersionInfo,
IN ULONG  TypeMask,
IN ULONGLONG  ConditionMask
 

Definition at line 207 of file version.c.

References ASSERT, FALSE, LEXICAL_COMPARISON, NTSTATUS(), RTL_GET_CONDITION, RtlGetVersion(), RtlpVerCompare(), RtlpVerGetConditionMask(), Status, and TRUE.

00219 : 00220 00221 VersionInfo - a version structure containing the comparison data 00222 TypeMask - a mask comtaining the data types to look at 00223 ConditionMask - a mask containing conditionals for doing the comparisons 00224 00225 00226 Return Value: 00227 00228 STATUS_INVALID_PARAMETER if the parameters are not valid. 00229 STATUS_REVISION_MISMATCH if the versions don't match. 00230 STATUS_SUCCESS if the versions match. 00231 00232 --*/ 00233 00234 { 00235 ULONG i; 00236 OSVERSIONINFOEXW CurrVersion; 00237 BOOLEAN SuiteFound = FALSE; 00238 BOOLEAN Equal; 00239 NTSTATUS Status; 00240 ULONG Condition; 00241 00242 00243 if (TypeMask == 0) { 00244 return STATUS_INVALID_PARAMETER; 00245 } 00246 00247 RtlZeroMemory( &CurrVersion, sizeof(OSVERSIONINFOEXW) ); 00248 CurrVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); 00249 00250 Status = RtlGetVersion((PRTL_OSVERSIONINFOW)&CurrVersion); 00251 if (Status != STATUS_SUCCESS) 00252 return Status; 00253 00254 if (VersionInfo->wSuiteMask != 0) { 00255 for (i=0; i<16; i++) { 00256 if (VersionInfo->wSuiteMask&(1<<i)) { 00257 switch (RTL_GET_CONDITION(ConditionMask,VER_SUITENAME)) { 00258 case VER_AND: 00259 if (!(CurrVersion.wSuiteMask&(1<<i))) { 00260 return STATUS_REVISION_MISMATCH; 00261 } 00262 break; 00263 00264 case VER_OR: 00265 if (CurrVersion.wSuiteMask&(1<<i)) { 00266 SuiteFound = TRUE; 00267 } 00268 break; 00269 00270 default: 00271 return STATUS_INVALID_PARAMETER; 00272 } 00273 } 00274 } 00275 if ((RtlpVerGetConditionMask(ConditionMask,VER_SUITENAME) == VER_OR) && (SuiteFound == FALSE)) { 00276 return STATUS_REVISION_MISMATCH; 00277 } 00278 } 00279 00280 Equal = TRUE; 00281 Condition = VER_EQUAL; 00282 if (TypeMask & VER_MAJORVERSION) { 00283 Condition = RTL_GET_CONDITION( ConditionMask, VER_MAJORVERSION); 00284 if (RtlpVerCompare( 00285 Condition, 00286 VersionInfo->dwMajorVersion, 00287 CurrVersion.dwMajorVersion, 00288 &Equal, 00289 0 00290 ) == FALSE) 00291 { 00292 if (!Equal) { 00293 return STATUS_REVISION_MISMATCH; 00294 } 00295 } 00296 } 00297 00298 if (Equal) { 00299 ASSERT(Condition); 00300 if (TypeMask & VER_MINORVERSION) { 00301 if (Condition == VER_EQUAL) { 00302 Condition = RTL_GET_CONDITION(ConditionMask, VER_MINORVERSION); 00303 } 00304 if (RtlpVerCompare( 00305 Condition, 00306 VersionInfo->dwMinorVersion, 00307 CurrVersion.dwMinorVersion, 00308 &Equal, 00309 LEXICAL_COMPARISON 00310 ) == FALSE) 00311 { 00312 if (!Equal) { 00313 return STATUS_REVISION_MISMATCH; 00314 } 00315 } 00316 } 00317 00318 if (Equal) { 00319 if (TypeMask & VER_SERVICEPACKMAJOR) { 00320 if (Condition == VER_EQUAL) { 00321 Condition = RTL_GET_CONDITION(ConditionMask, VER_SERVICEPACKMAJOR); 00322 } 00323 if (RtlpVerCompare( 00324 Condition, 00325 VersionInfo->wServicePackMajor, 00326 CurrVersion.wServicePackMajor, 00327 &Equal, 00328 0 00329 ) == FALSE) 00330 { 00331 if (!Equal) { 00332 return STATUS_REVISION_MISMATCH; 00333 } 00334 } 00335 } 00336 if (Equal) { 00337 if (TypeMask & VER_SERVICEPACKMINOR) { 00338 if (Condition == VER_EQUAL) { 00339 Condition = RTL_GET_CONDITION(ConditionMask, VER_SERVICEPACKMINOR); 00340 } 00341 if (RtlpVerCompare( 00342 Condition, 00343 (ULONG)VersionInfo->wServicePackMinor, 00344 (ULONG)CurrVersion.wServicePackMinor, 00345 &Equal, 00346 LEXICAL_COMPARISON 00347 ) == FALSE) 00348 { 00349 return STATUS_REVISION_MISMATCH; 00350 } 00351 } 00352 } 00353 } 00354 } 00355 00356 if ((TypeMask & VER_BUILDNUMBER) && 00357 RtlpVerCompare( 00358 RTL_GET_CONDITION( ConditionMask, VER_BUILDNUMBER), 00359 VersionInfo->dwBuildNumber, 00360 CurrVersion.dwBuildNumber, 00361 &Equal, 00362 0 00363 ) == FALSE) 00364 { 00365 return STATUS_REVISION_MISMATCH; 00366 } 00367 00368 if ((TypeMask & VER_PLATFORMID) && 00369 RtlpVerCompare( 00370 RTL_GET_CONDITION( ConditionMask, VER_PLATFORMID), 00371 VersionInfo->dwPlatformId, 00372 CurrVersion.dwPlatformId, 00373 &Equal, 00374 0 00375 ) == FALSE) 00376 { 00377 return STATUS_REVISION_MISMATCH; 00378 } 00379 00380 00381 if ((TypeMask & VER_PRODUCT_TYPE) && 00382 RtlpVerCompare( 00383 RTL_GET_CONDITION( ConditionMask, VER_PRODUCT_TYPE), 00384 VersionInfo->wProductType, 00385 CurrVersion.wProductType, 00386 &Equal, 00387 0 00388 ) == FALSE) 00389 { 00390 return STATUS_REVISION_MISMATCH; 00391 } 00392 00393 return STATUS_SUCCESS; 00394 }

ULONGLONG VerSetConditionMask ULONGLONG  ConditionMask,
ULONG  TypeMask,
UCHAR  Condition
 

Definition at line 421 of file version.c.

References NEW_STYLE_BIT_MASK.

00426 { 00427 int NumBitsToShift; 00428 00429 Condition &= VER_CONDITION_MASK; 00430 00431 if (!TypeMask) { 00432 return 0; 00433 } 00434 00435 for (NumBitsToShift = 0; TypeMask; NumBitsToShift++) { 00436 TypeMask >>= 1; 00437 } 00438 00439 // 00440 // Mark that we are using a new style condition mask 00441 // 00442 ConditionMask |= NEW_STYLE_BIT_MASK; 00443 ConditionMask |= (Condition) << ((NumBitsToShift - 1) 00444 * VER_NUM_BITS_PER_CONDITION_MASK); 00445 00446 return ConditionMask; 00447 }


Generated on Sat May 15 19:46:08 2004 for test by doxygen 1.3.7