1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 """
29 Debugging API wrappers in ctypes.
30
31 @see: U{http://apps.sourceforge.net/trac/winappdbg/wiki/Win32APIWrappers}
32 """
33
34 __revision__ = "$Id: version.py 441 2009-11-11 01:36:44Z QvasiModo $"
35
36 from defines import *
37
38
39
40 VER_PLATFORM_WIN32s = 0
41 VER_PLATFORM_WIN32_WINDOWS = 1
42 VER_PLATFORM_WIN32_NT = 2
43
44 VER_SUITE_BACKOFFICE = 0x00000004
45 VER_SUITE_BLADE = 0x00000400
46 VER_SUITE_COMPUTE_SERVER = 0x00004000
47 VER_SUITE_DATACENTER = 0x00000080
48 VER_SUITE_ENTERPRISE = 0x00000002
49 VER_SUITE_EMBEDDEDNT = 0x00000040
50 VER_SUITE_PERSONAL = 0x00000200
51 VER_SUITE_SINGLEUSERTS = 0x00000100
52 VER_SUITE_SMALLBUSINESS = 0x00000001
53 VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
54 VER_SUITE_STORAGE_SERVER = 0x00002000
55 VER_SUITE_TERMINAL = 0x00000010
56 VER_SUITE_WH_SERVER = 0x00008000
57
58 VER_NT_DOMAIN_CONTROLLER = 0x0000002
59 VER_NT_SERVER = 0x0000003
60 VER_NT_WORKSTATION = 0x0000001
61
62 VER_BUILDNUMBER = 0x0000004
63 VER_MAJORVERSION = 0x0000002
64 VER_MINORVERSION = 0x0000001
65 VER_PLATFORMID = 0x0000008
66 VER_PRODUCT_TYPE = 0x0000080
67 VER_SERVICEPACKMAJOR = 0x0000020
68 VER_SERVICEPACKMINOR = 0x0000010
69 VER_SUITENAME = 0x0000040
70
71 VER_EQUAL = 1
72 VER_GREATER = 2
73 VER_GREATER_EQUAL = 3
74 VER_LESS = 4
75 VER_LESS_EQUAL = 5
76 VER_AND = 6
77 VER_OR = 7
78
79
80
81
82
83
84
85
86
88 _fields_ = [
89 ("dwOSVersionInfoSize", DWORD),
90 ("dwMajorVersion", DWORD),
91 ("dwMinorVersion", DWORD),
92 ("dwBuildNumber", DWORD),
93 ("dwPlatformId", DWORD),
94 ("szCSDVersion", CHAR * 128),
95 ]
97 _fields_ = [
98 ("dwOSVersionInfoSize", DWORD),
99 ("dwMajorVersion", DWORD),
100 ("dwMinorVersion", DWORD),
101 ("dwBuildNumber", DWORD),
102 ("dwPlatformId", DWORD),
103 ("szCSDVersion", WCHAR * 128),
104 ]
105
106
107
108
109
110
111
112
113
114
115
116
117
118
120 _fields_ = [
121 ("dwOSVersionInfoSize", DWORD),
122 ("dwMajorVersion", DWORD),
123 ("dwMinorVersion", DWORD),
124 ("dwBuildNumber", DWORD),
125 ("dwPlatformId", DWORD),
126 ("szCSDVersion", CHAR * 128),
127 ("wServicePackMajor", WORD),
128 ("wServicePackMinor", WORD),
129 ("wSuiteMask", WORD),
130 ("wProductType", BYTE),
131 ("wReserved", BYTE),
132 ]
134 _fields_ = [
135 ("dwOSVersionInfoSize", DWORD),
136 ("dwMajorVersion", DWORD),
137 ("dwMinorVersion", DWORD),
138 ("dwBuildNumber", DWORD),
139 ("dwPlatformId", DWORD),
140 ("szCSDVersion", WCHAR * 128),
141 ("wServicePackMajor", WORD),
142 ("wServicePackMinor", WORD),
143 ("wSuiteMask", WORD),
144 ("wProductType", BYTE),
145 ("wReserved", BYTE),
146 ]
147
148 LPOSVERSIONINFOA = POINTER(OSVERSIONINFOA)
149 LPOSVERSIONINFOW = POINTER(OSVERSIONINFOW)
150 LPOSVERSIONINFOEXA = POINTER(OSVERSIONINFOEXA)
151 LPOSVERSIONINFOEXW = POINTER(OSVERSIONINFOEXW)
152 POSVERSIONINFOA = LPOSVERSIONINFOA
153 POSVERSIONINFOW = LPOSVERSIONINFOW
154 POSVERSIONINFOEXA = LPOSVERSIONINFOEXA
155 POSVERSIONINFOEXW = LPOSVERSIONINFOA
156
157
158
159 SM_CXSCREEN = 0
160 SM_CYSCREEN = 1
161 SM_CXVSCROLL = 2
162 SM_CYHSCROLL = 3
163 SM_CYCAPTION = 4
164 SM_CXBORDER = 5
165 SM_CYBORDER = 6
166 SM_CXDLGFRAME = 7
167 SM_CYDLGFRAME = 8
168 SM_CYVTHUMB = 9
169 SM_CXHTHUMB = 10
170 SM_CXICON = 11
171 SM_CYICON = 12
172 SM_CXCURSOR = 13
173 SM_CYCURSOR = 14
174 SM_CYMENU = 15
175 SM_CXFULLSCREEN = 16
176 SM_CYFULLSCREEN = 17
177 SM_CYKANJIWINDOW = 18
178 SM_MOUSEPRESENT = 19
179 SM_CYVSCROLL = 20
180 SM_CXHSCROLL = 21
181 SM_DEBUG = 22
182 SM_SWAPBUTTON = 23
183 SM_RESERVED1 = 24
184 SM_RESERVED2 = 25
185 SM_RESERVED3 = 26
186 SM_RESERVED4 = 27
187 SM_CXMIN = 28
188 SM_CYMIN = 29
189 SM_CXSIZE = 30
190 SM_CYSIZE = 31
191 SM_CXFRAME = 32
192 SM_CYFRAME = 33
193 SM_CXMINTRACK = 34
194 SM_CYMINTRACK = 35
195 SM_CXDOUBLECLK = 36
196 SM_CYDOUBLECLK = 37
197 SM_CXICONSPACING = 38
198 SM_CYICONSPACING = 39
199 SM_MENUDROPALIGNMENT = 40
200 SM_PENWINDOWS = 41
201 SM_DBCSENABLED = 42
202 SM_CMOUSEBUTTONS = 43
203
204 SM_CXFIXEDFRAME = SM_CXDLGFRAME
205 SM_CYFIXEDFRAME = SM_CYDLGFRAME
206 SM_CXSIZEFRAME = SM_CXFRAME
207 SM_CYSIZEFRAME = SM_CYFRAME
208
209 SM_SECURE = 44
210 SM_CXEDGE = 45
211 SM_CYEDGE = 46
212 SM_CXMINSPACING = 47
213 SM_CYMINSPACING = 48
214 SM_CXSMICON = 49
215 SM_CYSMICON = 50
216 SM_CYSMCAPTION = 51
217 SM_CXSMSIZE = 52
218 SM_CYSMSIZE = 53
219 SM_CXMENUSIZE = 54
220 SM_CYMENUSIZE = 55
221 SM_ARRANGE = 56
222 SM_CXMINIMIZED = 57
223 SM_CYMINIMIZED = 58
224 SM_CXMAXTRACK = 59
225 SM_CYMAXTRACK = 60
226 SM_CXMAXIMIZED = 61
227 SM_CYMAXIMIZED = 62
228 SM_NETWORK = 63
229 SM_CLEANBOOT = 67
230 SM_CXDRAG = 68
231 SM_CYDRAG = 69
232 SM_SHOWSOUNDS = 70
233 SM_CXMENUCHECK = 71
234 SM_CYMENUCHECK = 72
235 SM_SLOWMACHINE = 73
236 SM_MIDEASTENABLED = 74
237 SM_MOUSEWHEELPRESENT = 75
238 SM_XVIRTUALSCREEN = 76
239 SM_YVIRTUALSCREEN = 77
240 SM_CXVIRTUALSCREEN = 78
241 SM_CYVIRTUALSCREEN = 79
242 SM_CMONITORS = 80
243 SM_SAMEDISPLAYFORMAT = 81
244 SM_IMMENABLED = 82
245 SM_CXFOCUSBORDER = 83
246 SM_CYFOCUSBORDER = 84
247 SM_TABLETPC = 86
248 SM_MEDIACENTER = 87
249 SM_STARTER = 88
250 SM_SERVERR2 = 89
251 SM_MOUSEHORIZONTALWHEELPRESENT = 91
252 SM_CXPADDEDBORDER = 92
253
254 SM_CMETRICS = 93
255
256 SM_REMOTESESSION = 0x1000
257 SM_SHUTTINGDOWN = 0x2000
258 SM_REMOTECONTROL = 0x2001
259 SM_CARETBLINKINGENABLED = 0x2002
260
261
262
263 PROCESSOR_ARCHITECTURE_INTEL = 0
264 PROCESSOR_ARCHITECTURE_IA64 = 6
265 PROCESSOR_ARCHITECTURE_AMD64 = 9
266 PROCESSOR_ARCHITECTURE_UNKNOWN = 0xffff
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
288 _fields_ = [
289 ("wProcessorArchitecture", WORD),
290 ("wReserved", WORD),
291 ]
292
298
300 _fields_ = [
301 ("id", _SYSTEM_INFO_OEM_ID),
302 ("dwPageSize", DWORD),
303 ("lpMinimumApplicationAddress", LPVOID),
304 ("lpMaximumApplicationAddress", LPVOID),
305 ("dwActiveProcessorMask", DWORD_PTR),
306 ("dwNumberOfProcessors", DWORD),
307 ("dwProcessorType", DWORD),
308 ("dwAllocationGranularity", DWORD),
309 ("wProcessorLevel", WORD),
310 ("wProcessorRevision", WORD),
311 ]
312
317 dwOemId = property(__get_dwOemId, __set_dwOemId)
318
323 wProcessorArchitecture = property(__get_wProcessorArchitecture, __set_wProcessorArchitecture)
324
325 LPSYSTEM_INFO = ctypes.POINTER(SYSTEM_INFO)
326
327
328
329
338
339
340
341
350
351
352
353
355 _GetSystemMetrics = windll.user32.GetSystemMetrics
356 _GetSystemMetrics.argtypes = [ctypes.c_int]
357 _GetSystemMetrics.restype = ctypes.c_int
358 return _GetSystemMetrics(nIndex)
359
360
362 _GetVersion = windll.kernel32.GetVersion
363 _GetVersion.argtypes = []
364 _GetVersion.restype = DWORD
365 _GetVersion.errcheck = RaiseIfZero
366
367
368
369
370 dwVersion = _GetVersion()
371 dwMajorVersion = dwVersion & 0x000000FF
372 dwMinorVersion = (dwVersion & 0x0000FF00) >> 8
373 if (dwVersion & 0x80000000) == 0:
374 dwBuild = (dwVersion & 0x7FFF0000) >> 16
375 else:
376 dwBuild = None
377 return int(dwMajorVersion), int(dwMinorVersion), int(dwBuild)
378
379
380
381
397
413
414 GetVersionEx = GuessStringType(GetVersionExA, GetVersionExW)
415
416
417
418
419
420
421
422
423 -def GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion):
424 _GetProductInfo = windll.kernel32.GetProductInfo
425 _GetProductInfo.argtypes = [DWORD, DWORD, DWORD, DWORD, PDWORD]
426 _GetProductInfo.restype = BOOL
427 _GetProductInfo.errcheck = RaiseIfZero
428
429 dwReturnedProductType = DWORD(0)
430 _GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, byref(dwReturnedProductType))
431 return dwReturnedProductType.value
432
433
434
435
436
437
444
446 _VerifyVersionInfoA = windll.kernel32.VerifyVersionInfoA
447 _VerifyVersionInfoA.argtypes = [LPOSVERSIONINFOEXA, DWORD, DWORDLONG]
448 _VerifyVersionInfoA.restype = bool
449 return _VerifyVersionInfoA(ctypes.byref(lpVersionInfo), dwTypeMask, dwlConditionMask)
450
452 _VerifyVersionInfoW = windll.kernel32.VerifyVersionInfoW
453 _VerifyVersionInfoW.argtypes = [LPOSVERSIONINFOEXW, DWORD, DWORDLONG]
454 _VerifyVersionInfoW.restype = bool
455 return _VerifyVersionInfoW(ctypes.byref(lpVersionInfo), dwTypeMask, dwlConditionMask)
456
457
458
459
460
461
463 _VerSetConditionMask = windll.kernel32.VerSetConditionMask
464 _VerSetConditionMask.argtypes = [ULONGLONG, DWORD, BYTE]
465 _VerSetConditionMask.restype = ULONGLONG
466 return _VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask)
467
468
469
471 """
472 Determines the current integer size in bits.
473
474 This is useful to know if we're running in a 32 bits or a 64 bits machine.
475
476 @rtype: int
477 @return: Returns the size of L{SIZE_T} in bits.
478 """
479 return sizeof(SIZE_T) * 8
480
505
506
508 """
509 Determines the current operating system.
510
511 This function allows you to quickly tell apart major OS differences.
512 For more detailed information call L{kernel32.GetVersionEx} instead.
513
514 @note:
515 Wine reports itself as Windows XP 32 bits (even if the Linux host is 64 bits).
516 ReactOS reports itself as Windows 2000.
517
518 @rtype: str
519 @return:
520 One of the following values:
521 - C{"Unknown"}
522 - C{"Windows NT"}
523 - C{"Windows 2000"}
524 - C{"Windows XP"}
525 - C{"Windows XP (64 bits)"}
526 - C{"Windows 2003"}
527 - C{"Windows 2003 (64 bits)"}
528 - C{"Windows 2003 R2"}
529 - C{"Windows 2003 R2 (64 bits)"}
530 - C{"Windows 2008"}
531 - C{"Windows 2008 (64 bits)"}
532 - C{"Windows 2008 R2"}
533 - C{"Windows 2008 R2 (64 bits)"}
534 - C{"Windows Vista"}
535 - C{"Windows Vista (64 bits)"}
536 - C{"Windows 7"}
537 - C{"Windows 7 (64 bits)"}
538 """
539
540 osvi = GetVersionEx()
541 if osvi.dwPlatformId == VER_PLATFORM_WIN32_NT and osvi.dwMajorVersion > 4:
542 if osvi.dwMajorVersion == 6:
543 if osvi.dwMinorVersion == 0:
544 if osvi.wProductType == VER_NT_WORKSTATION:
545 if sizeof(SIZE_T) == 8:
546 return 'Windows Vista (64 bits)'
547 return 'Windows Vista'
548 else:
549 if sizeof(SIZE_T) == 8:
550 return 'Windows 2008 (64 bits)'
551 return 'Windows 2008'
552 if osvi.dwMinorVersion == 1:
553 if osvi.wProductType == VER_NT_WORKSTATION:
554 if sizeof(SIZE_T) == 8:
555 return 'Windows 7 (64 bits)'
556 return 'Windows 7'
557 else:
558 if sizeof(SIZE_T) == 8:
559 return 'Windows 2008 R2 (64 bits)'
560 return 'Windows 2008 R2'
561 if osvi.dwMajorVersion == 5:
562 if osvi.dwMinorVersion == 2:
563 if GetSystemMetrics(SM_SERVERR2):
564 if sizeof(SIZE_T) == 8:
565 return 'Windows 2003 R2 (64 bits)'
566 return 'Windows 2003 R2'
567 if osvi.wSuiteMask in (VER_SUITE_STORAGE_SERVER, VER_SUITE_WH_SERVER):
568 if sizeof(SIZE_T) == 8:
569 return 'Windows 2003 (64 bits)'
570 return 'Windows 2003'
571 try:
572 si = GetNativeSystemInfo()
573 except Exception:
574 si = GetSystemInfo()
575 if osvi.wProductType == VER_NT_WORKSTATION and si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64:
576 return 'Windows XP (64 bits)'
577 else:
578 if sizeof(SIZE_T) == 8:
579 return 'Windows 2003 (64 bits)'
580 return 'Windows 2003'
581 if osvi.dwMinorVersion == 1:
582 return 'Windows XP'
583 if osvi.dwMinorVersion == 0:
584 return 'Windows 2000'
585 if osvi.dwMajorVersion == 4:
586 return 'Windows NT'
587 return 'Unknown'
588
589
590 arch = get_arch()
591
592
593 bits = get_bits()
594
595
596 os = get_os()
597