Fix PowerPC assembler syntax mistakes.
[wine] / dlls / ntdll / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1998 Patrik Stridvall
6  * Copyright 1998, 2003 Andreas Mohr
7  * Copyright 1997, 2003 Alexandre Julliard
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winreg.h"
37 #include "winternl.h"
38 #include "winerror.h"
39 #include "module.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
42 #include "ntdll_misc.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(ver);
45
46 typedef enum
47 {
48     WIN20,   /* Windows 2.0 */
49     WIN30,   /* Windows 3.0 */
50     WIN31,   /* Windows 3.1 */
51     WIN95,   /* Windows 95 */
52     WIN98,   /* Windows 98 */
53     WINME,   /* Windows Me */
54     NT351,   /* Windows NT 3.51 */
55     NT40,    /* Windows NT 4.0 */
56     NT2K,    /* Windows 2000 */
57     WINXP,   /* Windows XP */
58     WIN2K3,  /* Windows 2003 */
59     NB_WINDOWS_VERSIONS
60 } WINDOWS_VERSION;
61
62 /* FIXME: compare values below with original and fix.
63  * An *excellent* win9x version page (ALL versions !)
64  * can be found at members.aol.com/axcel216/ver.htm */
65 static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
66 {
67     /* WIN20 FIXME: verify values */
68     {
69         sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
70         {'W','i','n','3','2','s',' ','1','.','3',0},
71         0, 0, 0, 0, 0
72     },
73     /* WIN30 FIXME: verify values */
74     {
75         sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
76         {'W','i','n','3','2','s',' ','1','.','3',0},
77         0, 0, 0, 0, 0
78     },
79     /* WIN31 */
80     {
81         sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
82         {'W','i','n','3','2','s',' ','1','.','3',0},
83         0, 0, 0, 0, 0
84     },
85     /* WIN95 */
86     {
87         /* Win95:       4, 0, 0x40003B6, ""
88          * Win95sp1:    4, 0, 0x40003B6, " A " (according to doc)
89          * Win95osr2:   4, 0, 0x4000457, " B " (according to doc)
90          * Win95osr2.1: 4, 3, 0x40304BC, " B " (according to doc)
91          * Win95osr2.5: 4, 3, 0x40304BE, " C " (according to doc)
92          * Win95a/b can be discerned via regkey SubVersionNumber
93          * See also:
94          * http://support.microsoft.com/support/kb/articles/q158/2/38.asp
95          */
96         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
97         {0},
98         0, 0, 0, 0, 0
99     },
100     /* WIN98 (second edition) */
101     {
102         /* Win98:   4, 10, 0x40A07CE, " "   4.10.1998
103          * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
104          */
105         sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
106         {' ','A',' ',0},
107         0, 0, 0, 0, 0
108     },
109     /* WINME */
110     {
111         sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
112         {' ',0},
113         0, 0, 0, 0, 0
114     },
115     /* NT351 */
116     {
117         sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
118         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
119         0, 0, 0, 0, 0
120     },
121     /* NT40 */
122     {
123         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
124         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6',0},
125         6, 0, 0, VER_NT_WORKSTATION, 0
126     },
127     /* NT2K */
128     {
129         sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
130         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
131         3, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
132     },
133     /* WINXP */
134     {
135         sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
136         {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
137         1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
138     },
139     /* WIN2K3 */
140     {
141         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
142         {0},
143         0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
144     }
145 };
146
147 static const char * const WinVersionNames[NB_WINDOWS_VERSIONS] =
148 { /* no spaces in here ! */
149     "win20",                      /* WIN20 */
150     "win30",                      /* WIN30 */
151     "win31",                      /* WIN31 */
152     "win95",                      /* WIN95 */
153     "win98",                      /* WIN98 */
154     "winme",                      /* WINME */
155     "nt351",                      /* NT351 */
156     "nt40",                       /* NT40 */
157     "win2000,win2k,nt2k,nt2000",  /* NT2K */
158     "winxp",                      /* WINXP */
159     "win2003,win2k3"              /* WIN2K3 */
160 };
161
162 /* names to print out in debug traces */
163 static const char * const debug_names[NB_WINDOWS_VERSIONS] =
164 {
165     "Windows 2.0",       /* WIN20 */
166     "Windows 3.0",       /* WIN30 */
167     "Windows 3.1",       /* WIN31 */
168     "Windows 95",        /* WIN95 */
169     "Windows 98",        /* WIN98 */
170     "Windows Me",        /* WINME */
171     "Windows NT 3.51",   /* NT351 */
172     "Windows NT 4.0",    /* NT40 */
173     "Windows 2000",      /* NT2K */
174     "Windows XP",        /* WINXP */
175     "Windows 2003"       /* WIN2K3 */
176 };
177
178 /* if one of the following dlls is importing ntdll the windows
179 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
180 static const WCHAR special_dlls[][16] =
181 {
182     {'c','o','m','d','l','g','3','2','.','d','l','l',0},
183     {'c','o','m','c','t','l','3','2','.','d','l','l',0},
184     {'s','h','e','l','l','3','2','.','d','l','l',0},
185     {'o','l','e','3','2','.','d','l','l',0},
186     {'r','p','c','r','t','4','.','d','l','l',0}
187 };
188
189 /* the current version has not been autodetected but forced via cmdline */
190 static BOOL versionForced = FALSE;
191 static WINDOWS_VERSION forcedWinVersion; /* init value irrelevant */
192
193 /**********************************************************************
194  *         parse_win_version
195  *
196  * Parse the contents of the Version key.
197  */
198 static BOOL parse_win_version( HKEY hkey )
199 {
200     static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
201
202     UNICODE_STRING valueW;
203     char tmp[64], buffer[50];
204     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
205     DWORD count, len;
206     int i;
207
208     RtlInitUnicodeString( &valueW, WindowsW );
209     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
210         return FALSE;
211
212     RtlUnicodeToMultiByteN( buffer, sizeof(buffer)-1, &len, (WCHAR *)info->Data, info->DataLength );
213     buffer[len] = 0;
214
215     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
216     {
217         const char *p, *pCurr = WinVersionNames[i];
218         /* iterate through all winver aliases separated by comma */
219         do {
220             p = strchr(pCurr, ',');
221             len = p ? p - pCurr : strlen(pCurr);
222             if ( (!strncmp( pCurr, buffer, len )) && (buffer[len] == 0) )
223             {
224                 forcedWinVersion = i;
225                 versionForced = TRUE;
226                 TRACE( "got win version %s\n", WinVersionNames[forcedWinVersion] );
227                 return TRUE;
228             }
229             pCurr = p+1;
230         } while (p);
231     }
232
233     MESSAGE("Invalid Windows version value '%s' specified in config file.\n", buffer );
234     MESSAGE("Valid versions are:" );
235     for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
236     {
237         /* only list the first, "official" alias in case of aliases */
238         const char *pCurr = WinVersionNames[i];
239         const char *p = strchr(pCurr, ',');
240         len = (p) ? p - pCurr : strlen(pCurr);
241
242         MESSAGE(" '%.*s'%c", (int)len, pCurr, (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
243     }
244     return FALSE;
245 }
246
247
248 /**********************************************************************
249  *         VERSION_Init
250  */
251 void VERSION_Init( const WCHAR *appname )
252 {
253     OBJECT_ATTRIBUTES attr;
254     UNICODE_STRING nameW;
255     HKEY hkey, config_key;
256     static const WCHAR configW[] = {'M','a','c','h','i','n','e','\\',
257                                     'S','o','f','t','w','a','r','e','\\',
258                                     'W','i','n','e','\\',
259                                     'W','i','n','e','\\',
260                                     'C','o','n','f','i','g',0};
261     static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
262     static const WCHAR versionW[] = {'\\','V','e','r','s','i','o','n',0};
263
264     attr.Length = sizeof(attr);
265     attr.RootDirectory = 0;
266     attr.ObjectName = &nameW;
267     attr.Attributes = 0;
268     attr.SecurityDescriptor = NULL;
269     attr.SecurityQualityOfService = NULL;
270     RtlInitUnicodeString( &nameW, configW );
271
272     if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) return;
273     attr.RootDirectory = config_key;
274
275     /* open AppDefaults\\appname\\Version key */
276     if (appname && *appname)
277     {
278         const WCHAR *p;
279         WCHAR appversion[MAX_PATH+20];
280         BOOL got_win_ver = FALSE;
281
282         if ((p = strrchrW( appname, '/' ))) appname = p + 1;
283         if ((p = strrchrW( appname, '\\' ))) appname = p + 1;
284
285         strcpyW( appversion, appdefaultsW );
286         strcatW( appversion, appname );
287         strcatW( appversion, versionW );
288         TRACE( "getting version from %s\n", debugstr_w(appversion) );
289         RtlInitUnicodeString( &nameW, appversion );
290
291         if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
292         {
293             got_win_ver = parse_win_version( hkey );
294             NtClose( hkey );
295         }
296         if (got_win_ver) goto done;
297     }
298
299     TRACE( "getting default version\n" );
300     RtlInitUnicodeString( &nameW, versionW + 1 );
301     if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
302     {
303         parse_win_version( hkey );
304         NtClose( hkey );
305     }
306
307  done:
308     NtClose( config_key );
309 }
310
311
312 /**********************************************************************
313  *      VERSION_GetSystemDLLVersion
314  *
315  * This function tries to figure out if a given (native) dll comes from
316  * win95/98 or winnt. Since all values in the OptionalHeader are not a
317  * usable hint, we test if a dll imports the ntdll.
318  * This is at least working for all system dlls like comctl32, comdlg32 and
319  * shell32.
320  * If you have a better idea to figure this out...
321  */
322 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
323 {
324     DWORD size;
325     IMAGE_IMPORT_DESCRIPTOR *pe_imp;
326
327     if ((pe_imp = RtlImageDirectoryEntryToData( hmod, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size )))
328     {
329         for ( ; pe_imp->Name; pe_imp++)
330         {
331             char * name = (char *)hmod + (unsigned int)pe_imp->Name;
332             TRACE("%s\n", name);
333
334             if (!strncasecmp(name, "ntdll", 5))
335             {
336               switch(RtlImageNtHeader(hmod)->OptionalHeader.MajorOperatingSystemVersion) {
337                   case 3:
338                           MESSAGE("WARNING: very old native DLL (NT 3.x) used, might cause instability.\n");
339                           return NT351;
340                   case 4: return NT40;
341                   case 5: return NT2K;
342                   case 6: return WINXP;
343                   case 7: return WIN2K3; /* FIXME: Not sure, should be verified with a Win2K3 dll */
344                   default:
345                           FIXME("Unknown DLL OS version, please report !!\n");
346                           return WIN2K3;
347               }
348             }
349         }
350     }
351     return WIN95;
352 }
353
354
355 /**********************************************************************
356  *      VERSION_GetLinkedDllVersion
357  *
358  * Some version data (not reliable!):
359  * linker/OS/image/subsys
360  *
361  * x.xx/1.00/0.00/3.10  Win32s          (any version ?)
362  * 2.39/1.00/0.00/3.10  Win32s          freecell.exe (any version)
363  * 2.50/1.00/4.00/4.00  Win32s 1.30     winhlp32.exe
364  * 2.60/3.51/3.51/3.51  NT351SP5        system dlls
365  * 2.60/3.51/3.51/4.00  NT351SP5        comctl32 dll
366  * 2.xx/1.00/0.00/4.00  Win95           system files
367  * x.xx/4.00/0.00/4.00  Win95           most applications
368  * 3.10/4.00/0.00/4.00  Win98           notepad
369  * x.xx/5.00/5.00/4.00  Win98           system dlls (e.g. comctl32.dll)
370  * x.xx/4.00/4.00/4.00  NT 4            most apps
371  * 5.12/5.00/5.00/4.00  NT4+IE5         comctl32.dll
372  * 5.12/5.00/5.00/4.00  Win98           calc
373  * x.xx/5.00/5.00/4.00  win95/win98/NT4 IE5 files
374  */
375 static DWORD VERSION_GetLinkedDllVersion(void)
376 {
377     WINDOWS_VERSION WinVersion = NB_WINDOWS_VERSIONS;
378     PIMAGE_OPTIONAL_HEADER ophd;
379     IMAGE_NT_HEADERS *nt;
380     const WCHAR *name;
381     PLIST_ENTRY mark, entry;
382     PLDR_MODULE mod;
383     int i;
384
385     /* First check the native dlls provided. These have to be
386        from one windows version */
387
388     mark = &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList;
389     for (entry = mark->Flink; entry != mark; entry = entry->Flink)
390     {
391         mod = CONTAINING_RECORD(entry, LDR_MODULE, InLoadOrderModuleList);
392         if (mod->Flags & LDR_WINE_INTERNAL) continue;
393         nt = RtlImageNtHeader(mod->BaseAddress);
394         ophd = &nt->OptionalHeader;
395         name = strrchrW( mod->FullDllName.Buffer, '\\' );
396         if (name) name++;
397         else name = mod->FullDllName.Buffer;
398
399         TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
400               debugstr_w(name), ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
401               ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
402               ophd->MajorImageVersion, ophd->MinorImageVersion,
403               ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
404
405         for (i = 0; i < sizeof(special_dlls)/sizeof(special_dlls[0]); i++)
406         {
407             /* test if it is a special dll */
408             if (!strcmpiW(name, special_dlls[i]))
409             {
410                 DWORD DllVersion = VERSION_GetSystemDLLVersion(mod->BaseAddress);
411                 if (WinVersion == NB_WINDOWS_VERSIONS) WinVersion = DllVersion;
412                 else if (WinVersion != DllVersion)
413                 {
414                     ERR("You mixed system DLLs from different windows versions! Expect a crash! (%s: expected version %s, but is %s)\n",
415                         debugstr_w(name),
416                         debugstr_w(VersionData[WinVersion].szCSDVersion),
417                         debugstr_w(VersionData[DllVersion].szCSDVersion));
418                     return WIN20; /* this may let the exe exit */
419                 }
420                 break;
421             }
422         }
423     }
424
425     if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
426
427     /* we are using no external system dlls, look at the exe */
428     nt = RtlImageNtHeader(NtCurrentTeb()->Peb->ImageBaseAddress);
429     ophd = &nt->OptionalHeader;
430
431     TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
432           ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
433           ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
434           ophd->MajorImageVersion, ophd->MinorImageVersion,
435           ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
436
437     /* special nt 3.51 */
438     if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
439     {
440         return NT351;
441     }
442
443     /* the MajorSubsystemVersion is the only usable sign */
444     if (ophd->MajorSubsystemVersion < 4)
445     {
446         if ( ophd->MajorOperatingSystemVersion == 1
447              && ophd->MinorOperatingSystemVersion == 0)
448         {
449             return WIN31; /* win32s */
450         }
451
452         if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
453             return NT351; /* FIXME: NT 3.1, not tested */
454         else
455             return WIN95;
456     }
457
458     return WIN95;
459 }
460
461 /**********************************************************************
462  *         VERSION_GetVersion
463  *
464  * WARNING !!!
465  * Don't call this function too early during the Wine init,
466  * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
467  * be NULL in such cases, which causes the winver to ALWAYS be detected
468  * as WIN31.
469  * And as we cache the winver once it has been determined, this is bad.
470  * This can happen much easier than you might think, as this function
471  * is called by EVERY GetVersion*() API !
472  *
473  */
474 static const RTL_OSVERSIONINFOEXW *VERSION_GetVersion(void)
475 {
476     static WORD winver = 0xffff;
477
478     if (versionForced)
479         return &VersionData[forcedWinVersion];  /* user has overridden any sensible checks */
480
481     if (winver == 0xffff) /* to be determined */
482     {
483         WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion();
484
485         /* cache determined value, but do not store in case of WIN31 */
486         if (retver != WIN31) winver = retver;
487         return &VersionData[retver];
488     }
489     return &VersionData[winver];
490 }
491
492
493 /***********************************************************************
494  *         RtlGetVersion   (NTDLL.@)
495  */
496 NTSTATUS WINAPI RtlGetVersion( RTL_OSVERSIONINFOEXW *info )
497 {
498     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
499
500     info->dwMajorVersion = current->dwMajorVersion;
501     info->dwMinorVersion = current->dwMinorVersion;
502     info->dwBuildNumber  = current->dwBuildNumber;
503     info->dwPlatformId   = current->dwPlatformId;
504     strcpyW( info->szCSDVersion, current->szCSDVersion );
505     if(info->dwOSVersionInfoSize == sizeof(RTL_OSVERSIONINFOEXW))
506     {
507         info->wServicePackMajor = current->wServicePackMajor;
508         info->wServicePackMinor = current->wServicePackMinor;
509         info->wSuiteMask        = current->wSuiteMask;
510         info->wProductType      = current->wProductType;
511     }
512     TRACE("<-- %s (%s)\n", debug_names[current - VersionData], debugstr_w(current->szCSDVersion) );
513     return STATUS_SUCCESS;
514 }
515
516
517 /******************************************************************************
518  *  RtlGetNtVersionNumbers   (NTDLL.@)
519  *
520  * Get the version numbers of the run time library.
521  *
522  * PARAMS
523  *  major [O] Destination for the Major version
524  *  minor [O] Destination for the Minor version
525  *  build [O] Destination for the Build version
526  *
527  * RETURNS
528  *  Nothing.
529  *
530  * NOTES
531  * Introduced in Windows XP (NT5.1)
532  */
533 void WINAPI RtlGetNtVersionNumbers( LPDWORD major, LPDWORD minor, LPDWORD build )
534 {
535     const RTL_OSVERSIONINFOEXW * const current = VERSION_GetVersion();
536
537     if (major) *major = current->dwMajorVersion;
538     if (minor) *minor = current->dwMinorVersion;
539     /* FIXME: Does anybody know the real formula? */
540     if (build) *build = (0xF0000000 | current->dwBuildNumber);
541 }
542
543
544 /******************************************************************************
545  *        VerifyVersionInfoW   (KERNEL32.@)
546  */
547 NTSTATUS WINAPI RtlVerifyVersionInfo( const RTL_OSVERSIONINFOEXW *info,
548                                       DWORD dwTypeMask, DWORDLONG dwlConditionMask )
549 {
550     RTL_OSVERSIONINFOEXW ver;
551     NTSTATUS status;
552
553     FIXME("(%p,%lu,%llx): Not all cases correctly implemented yet\n",
554           info, dwTypeMask, dwlConditionMask);
555
556     /* FIXME:
557         - Check the following special case on Windows (various versions):
558           o lp->wSuiteMask == 0 and ver.wSuiteMask != 0 and VER_AND/VER_OR
559           o lp->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW)
560         - MSDN talks about some tests being impossible. Check what really happens.
561      */
562
563     ver.dwOSVersionInfoSize = sizeof(ver);
564     if ((status = RtlGetVersion( &ver )) != STATUS_SUCCESS) return status;
565
566     if(!(dwTypeMask && dwlConditionMask)) return STATUS_INVALID_PARAMETER;
567
568     if(dwTypeMask & VER_PRODUCT_TYPE)
569         switch(dwlConditionMask >> 7*3 & 0x07) {
570             case VER_EQUAL:
571                 if(ver.wProductType != info->wProductType) return STATUS_REVISION_MISMATCH;
572                 break;
573             case VER_GREATER:
574                 if(ver.wProductType <= info->wProductType) return STATUS_REVISION_MISMATCH;
575                 break;
576             case VER_GREATER_EQUAL:
577                 if(ver.wProductType < info->wProductType) return STATUS_REVISION_MISMATCH;
578                 break;
579             case VER_LESS:
580                 if(ver.wProductType >= info->wProductType) return STATUS_REVISION_MISMATCH;
581                 break;
582             case VER_LESS_EQUAL:
583                 if(ver.wProductType > info->wProductType) return STATUS_REVISION_MISMATCH;
584                 break;
585             default:
586                 return STATUS_INVALID_PARAMETER;
587         }
588     if(dwTypeMask & VER_SUITENAME)
589         switch(dwlConditionMask >> 6*3 & 0x07)
590         {
591             case VER_AND:
592                 if((info->wSuiteMask & ver.wSuiteMask) != info->wSuiteMask)
593                     return STATUS_REVISION_MISMATCH;
594                 break;
595             case VER_OR:
596                 if(!(info->wSuiteMask & ver.wSuiteMask) && info->wSuiteMask)
597                     return STATUS_REVISION_MISMATCH;
598                 break;
599             default:
600                 return STATUS_INVALID_PARAMETER;
601         }
602     if(dwTypeMask & VER_PLATFORMID)
603         switch(dwlConditionMask >> 3*3 & 0x07)
604         {
605             case VER_EQUAL:
606                 if(ver.dwPlatformId != info->dwPlatformId) return STATUS_REVISION_MISMATCH;
607                 break;
608             case VER_GREATER:
609                 if(ver.dwPlatformId <= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
610                 break;
611             case VER_GREATER_EQUAL:
612                 if(ver.dwPlatformId < info->dwPlatformId) return STATUS_REVISION_MISMATCH;
613                 break;
614             case VER_LESS:
615                 if(ver.dwPlatformId >= info->dwPlatformId) return STATUS_REVISION_MISMATCH;
616                 break;
617             case VER_LESS_EQUAL:
618                 if(ver.dwPlatformId > info->dwPlatformId) return STATUS_REVISION_MISMATCH;
619                 break;
620             default:
621                 return STATUS_INVALID_PARAMETER;
622         }
623     if(dwTypeMask & VER_BUILDNUMBER)
624         switch(dwlConditionMask >> 2*3 & 0x07)
625         {
626             case VER_EQUAL:
627                 if(ver.dwBuildNumber != info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
628                 break;
629             case VER_GREATER:
630                 if(ver.dwBuildNumber <= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
631                 break;
632             case VER_GREATER_EQUAL:
633                 if(ver.dwBuildNumber < info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
634                 break;
635             case VER_LESS:
636                 if(ver.dwBuildNumber >= info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
637                 break;
638             case VER_LESS_EQUAL:
639                 if(ver.dwBuildNumber > info->dwBuildNumber) return STATUS_REVISION_MISMATCH;
640                 break;
641             default:
642                 return STATUS_INVALID_PARAMETER;
643         }
644     if(dwTypeMask & VER_MAJORVERSION)
645         switch(dwlConditionMask >> 1*3 & 0x07)
646         {
647             case VER_EQUAL:
648                 if(ver.dwMajorVersion != info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
649                 break;
650             case VER_GREATER:
651                 if(ver.dwMajorVersion <= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
652                 break;
653             case VER_GREATER_EQUAL:
654                 if(ver.dwMajorVersion < info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
655                 break;
656             case VER_LESS:
657                 if(ver.dwMajorVersion >= info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
658                 break;
659             case VER_LESS_EQUAL:
660                 if(ver.dwMajorVersion > info->dwMajorVersion) return STATUS_REVISION_MISMATCH;
661                 break;
662             default:
663                 return STATUS_INVALID_PARAMETER;
664         }
665     if(dwTypeMask & VER_MINORVERSION)
666         switch(dwlConditionMask >> 0*3 & 0x07)
667         {
668             case VER_EQUAL:
669                 if(ver.dwMinorVersion != info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
670                 break;
671             case VER_GREATER:
672                 if(ver.dwMinorVersion <= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
673                 break;
674             case VER_GREATER_EQUAL:
675                 if(ver.dwMinorVersion < info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
676                 break;
677             case VER_LESS:
678                 if(ver.dwMinorVersion >= info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
679                 break;
680             case VER_LESS_EQUAL:
681                 if(ver.dwMinorVersion > info->dwMinorVersion) return STATUS_REVISION_MISMATCH;
682                 break;
683             default:
684                 return STATUS_INVALID_PARAMETER;
685         }
686     if(dwTypeMask & VER_SERVICEPACKMAJOR)
687         switch(dwlConditionMask >> 5*3 & 0x07)
688         {
689             case VER_EQUAL:
690                 if(ver.wServicePackMajor != info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
691                 break;
692             case VER_GREATER:
693                 if(ver.wServicePackMajor <= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
694                 break;
695             case VER_GREATER_EQUAL:
696                 if(ver.wServicePackMajor < info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
697                 break;
698             case VER_LESS:
699                 if(ver.wServicePackMajor >= info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
700                 break;
701             case VER_LESS_EQUAL:
702                 if(ver.wServicePackMajor > info->wServicePackMajor) return STATUS_REVISION_MISMATCH;
703                 break;
704             default:
705                 return STATUS_INVALID_PARAMETER;
706         }
707     if(dwTypeMask & VER_SERVICEPACKMINOR)
708         switch(dwlConditionMask >> 4*3 & 0x07)
709         {
710             case VER_EQUAL:
711                 if(ver.wServicePackMinor != info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
712                 break;
713             case VER_GREATER:
714                 if(ver.wServicePackMinor <= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
715                 break;
716             case VER_GREATER_EQUAL:
717                 if(ver.wServicePackMinor < info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
718                 break;
719             case VER_LESS:
720                 if(ver.wServicePackMinor >= info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
721                 break;
722             case VER_LESS_EQUAL:
723                 if(ver.wServicePackMinor > info->wServicePackMinor) return STATUS_REVISION_MISMATCH;
724                 break;
725             default:
726                 return STATUS_INVALID_PARAMETER;
727         }
728
729     return STATUS_SUCCESS;
730 }