Package winappdbg :: Package win32 :: Module version
[hide private]
[frames] | no frames]

Source Code for Module winappdbg.win32.version

  1  # Copyright (c) 2009, Mario Vilas 
  2  # All rights reserved. 
  3  # 
  4  # Redistribution and use in source and binary forms, with or without 
  5  # modification, are permitted provided that the following conditions are met: 
  6  # 
  7  #     * Redistributions of source code must retain the above copyright notice, 
  8  #       this list of conditions and the following disclaimer. 
  9  #     * Redistributions in binary form must reproduce the above copyright 
 10  #       notice,this list of conditions and the following disclaimer in the 
 11  #       documentation and/or other materials provided with the distribution. 
 12  #     * Neither the name of the copyright holder nor the names of its 
 13  #       contributors may be used to endorse or promote products derived from 
 14  #       this software without specific prior written permission. 
 15  # 
 16  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 17  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 18  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 19  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 20  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 21  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 22  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 23  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 24  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 25  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 26  # POSSIBILITY OF SUCH DAMAGE. 
 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  #--- OSVERSIONINFO and OSVERSIONINFOEX structures and constants --------------- 
 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  # typedef struct _OSVERSIONINFO { 
 80  #   DWORD dwOSVersionInfoSize; 
 81  #   DWORD dwMajorVersion; 
 82  #   DWORD dwMinorVersion; 
 83  #   DWORD dwBuildNumber; 
 84  #   DWORD dwPlatformId; 
 85  #   TCHAR szCSDVersion[128]; 
 86  # }OSVERSIONINFO; 
87 -class OSVERSIONINFOA(Structure):
88 _fields_ = [ 89 ("dwOSVersionInfoSize", DWORD), 90 ("dwMajorVersion", DWORD), 91 ("dwMinorVersion", DWORD), 92 ("dwBuildNumber", DWORD), 93 ("dwPlatformId", DWORD), 94 ("szCSDVersion", CHAR * 128), 95 ]
96 -class OSVERSIONINFOW(Structure):
97 _fields_ = [ 98 ("dwOSVersionInfoSize", DWORD), 99 ("dwMajorVersion", DWORD), 100 ("dwMinorVersion", DWORD), 101 ("dwBuildNumber", DWORD), 102 ("dwPlatformId", DWORD), 103 ("szCSDVersion", WCHAR * 128), 104 ]
105 106 # typedef struct _OSVERSIONINFOEX { 107 # DWORD dwOSVersionInfoSize; 108 # DWORD dwMajorVersion; 109 # DWORD dwMinorVersion; 110 # DWORD dwBuildNumber; 111 # DWORD dwPlatformId; 112 # TCHAR szCSDVersion[128]; 113 # WORD wServicePackMajor; 114 # WORD wServicePackMinor; 115 # WORD wSuiteMask; 116 # BYTE wProductType; 117 # BYTE wReserved; 118 # }OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;
119 -class OSVERSIONINFOEXA(Structure):
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 ]
133 -class OSVERSIONINFOEXW(Structure):
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 #--- GetSystemMetrics constants ----------------------------------------------- 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 # ;win40 name change 205 SM_CYFIXEDFRAME = SM_CYDLGFRAME # ;win40 name change 206 SM_CXSIZEFRAME = SM_CXFRAME # ;win40 name change 207 SM_CYSIZEFRAME = SM_CYFRAME # ;win40 name change 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 # Use instead of GetMenuCheckMarkDimensions()! 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 #--- SYSTEM_INFO structure, GetSystemInfo() and GetNativeSystemInfo() --------- 262 263 PROCESSOR_ARCHITECTURE_INTEL = 0 264 PROCESSOR_ARCHITECTURE_IA64 = 6 265 PROCESSOR_ARCHITECTURE_AMD64 = 9 266 PROCESSOR_ARCHITECTURE_UNKNOWN = 0xffff 267 268 # typedef struct _SYSTEM_INFO { 269 # union { 270 # DWORD dwOemId; 271 # struct { 272 # WORD wProcessorArchitecture; 273 # WORD wReserved; 274 # } ; 275 # } ; 276 # DWORD dwPageSize; 277 # LPVOID lpMinimumApplicationAddress; 278 # LPVOID lpMaximumApplicationAddress; 279 # DWORD_PTR dwActiveProcessorMask; 280 # DWORD dwNumberOfProcessors; 281 # DWORD dwProcessorType; 282 # DWORD dwAllocationGranularity; 283 # WORD wProcessorLevel; 284 # WORD wProcessorRevision; 285 # } SYSTEM_INFO; 286
287 -class _SYSTEM_INFO_OEM_ID_STRUCT(Structure):
288 _fields_ = [ 289 ("wProcessorArchitecture", WORD), 290 ("wReserved", WORD), 291 ]
292
293 -class _SYSTEM_INFO_OEM_ID(Union):
294 _fields_ = [ 295 ("dwOemId", DWORD), 296 ("w", _SYSTEM_INFO_OEM_ID_STRUCT), 297 ]
298
299 -class SYSTEM_INFO(Structure):
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
313 - def __get_dwOemId(self):
314 return self.id.dwOemId
315 - def __set_dwOemId(self, value):
316 self.id.dwOemId = value
317 dwOemId = property(__get_dwOemId, __set_dwOemId) 318
320 return self.id.w.wProcessorArchitecture
321 - def __set_wProcessorArchitecture(self, value):
323 wProcessorArchitecture = property(__get_wProcessorArchitecture, __set_wProcessorArchitecture)
324 325 LPSYSTEM_INFO = ctypes.POINTER(SYSTEM_INFO) 326 327 # void WINAPI GetSystemInfo( 328 # __out LPSYSTEM_INFO lpSystemInfo 329 # );
330 -def GetSystemInfo():
331 _GetSystemInfo = windll.kernel32.GetSystemInfo 332 _GetSystemInfo.argtypes = [LPSYSTEM_INFO] 333 _GetSystemInfo.restype = None 334 335 sysinfo = SYSTEM_INFO() 336 _GetSystemInfo(ctypes.byref(sysinfo)) 337 return sysinfo
338 339 # void WINAPI GetNativeSystemInfo( 340 # __out LPSYSTEM_INFO lpSystemInfo 341 # );
342 -def GetNativeSystemInfo():
343 _GetNativeSystemInfo = windll.kernel32.GetNativeSystemInfo 344 _GetNativeSystemInfo.argtypes = [LPSYSTEM_INFO] 345 _GetNativeSystemInfo.restype = None 346 347 sysinfo = SYSTEM_INFO() 348 _GetNativeSystemInfo(ctypes.byref(sysinfo)) 349 return sysinfo
350 351 # int WINAPI GetSystemMetrics( 352 # __in int nIndex 353 # );
354 -def GetSystemMetrics(nIndex):
355 _GetSystemMetrics = windll.user32.GetSystemMetrics 356 _GetSystemMetrics.argtypes = [ctypes.c_int] 357 _GetSystemMetrics.restype = ctypes.c_int 358 return _GetSystemMetrics(nIndex)
359 360 # DWORD WINAPI GetVersion(void);
361 -def GetVersion():
362 _GetVersion = windll.kernel32.GetVersion 363 _GetVersion.argtypes = [] 364 _GetVersion.restype = DWORD 365 _GetVersion.errcheck = RaiseIfZero 366 367 # See the example code here: 368 # http://msdn.microsoft.com/en-us/library/ms724439(VS.85).aspx 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 # BOOL WINAPI GetVersionEx( 380 # __inout LPOSVERSIONINFO lpVersionInfo 381 # );
382 -def GetVersionExA():
383 _GetVersionExA = windll.kernel32.GetVersionExA 384 _GetVersionExA.argtypes = [LPVOID] 385 _GetVersionExA.restype = bool 386 _GetVersionExA.errcheck = RaiseIfZero 387 388 osi = OSVERSIONINFOEXA() 389 osi.dwOSVersionInfoSize = sizeof(osi) 390 try: 391 _GetVersionExA(ctypes.byref(osi)) 392 except WindowsError: 393 osi = OSVERSIONINFOA() 394 osi.dwOSVersionInfoSize = sizeof(osi) 395 _GetVersionExA(ctypes.byref(osi)) 396 return osi
397
398 -def GetVersionExW():
399 _GetVersionExW = windll.kernel32.GetVersionExW 400 _GetVersionExW.argtypes = [LPVOID] 401 _GetVersionExW.restype = bool 402 _GetVersionExW.errcheck = RaiseIfZero 403 404 osi = OSVERSIONINFOEXW() 405 osi.dwOSVersionInfoSize = sizeof(osi) 406 try: 407 _GetVersionExW(ctypes.byref(osi)) 408 except WindowsError: 409 osi = OSVERSIONINFOW() 410 osi.dwOSVersionInfoSize = sizeof(osi) 411 _GetVersionExW(ctypes.byref(osi)) 412 return osi
413 414 GetVersionEx = GuessStringType(GetVersionExA, GetVersionExW) 415 416 # BOOL WINAPI GetProductInfo( 417 # __in DWORD dwOSMajorVersion, 418 # __in DWORD dwOSMinorVersion, 419 # __in DWORD dwSpMajorVersion, 420 # __in DWORD dwSpMinorVersion, 421 # __out PDWORD pdwReturnedProductType 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 # BOOL WINAPI VerifyVersionInfo( 434 # __in LPOSVERSIONINFOEX lpVersionInfo, 435 # __in DWORD dwTypeMask, 436 # __in DWORDLONG dwlConditionMask 437 # );
438 -def VerifyVersionInfo(lpVersionInfo, dwTypeMask, dwlConditionMask):
439 if isinstance(lpVersionInfo, OSVERSIONINFOEXA): 440 return VerifyVersionInfoA(lpVersionInfo, dwTypeMask, dwlConditionMask) 441 if isinstance(lpVersionInfo, OSVERSIONINFOEXW): 442 return VerifyVersionInfoW(lpVersionInfo, dwTypeMask, dwlConditionMask) 443 raise TypeError, "Bad OSVERSIONINFOEX structure"
444
445 -def VerifyVersionInfoA(lpVersionInfo, dwTypeMask, dwlConditionMask):
446 _VerifyVersionInfoA = windll.kernel32.VerifyVersionInfoA 447 _VerifyVersionInfoA.argtypes = [LPOSVERSIONINFOEXA, DWORD, DWORDLONG] 448 _VerifyVersionInfoA.restype = bool 449 return _VerifyVersionInfoA(ctypes.byref(lpVersionInfo), dwTypeMask, dwlConditionMask)
450
451 -def VerifyVersionInfoW(lpVersionInfo, dwTypeMask, dwlConditionMask):
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 # ULONGLONG WINAPI VerSetConditionMask( 458 # __in ULONGLONG dwlConditionMask, 459 # __in DWORD dwTypeBitMask, 460 # __in BYTE dwConditionMask 461 # );
462 -def VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask):
463 _VerSetConditionMask = windll.kernel32.VerSetConditionMask 464 _VerSetConditionMask.argtypes = [ULONGLONG, DWORD, BYTE] 465 _VerSetConditionMask.restype = ULONGLONG 466 return _VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask)
467 468 #--- get_bits, get_arch and get_os -------------------------------------------- 469
470 -def get_bits():
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
481 -def get_arch():
482 """ 483 Determines the current processor architecture. 484 485 @rtype: str 486 @return: 487 One of the following values: 488 - C{"unknown"} 489 - C{"i386"} for Intel 32-bit x86 processor or compatible. 490 - C{"amd64"} for Intel 64-bit x86_64 processor or compatible. 491 - C{"ia64"} for Intel Itanium processor or compatible. 492 """ 493 try: 494 si = GetNativeSystemInfo() 495 except Exception: 496 si = GetSystemInfo() 497 wProcessorArchitecture = si.id.w.wProcessorArchitecture 498 if wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL: 499 return 'i386' 500 if wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64: 501 return 'amd64' 502 if wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64: 503 return 'ia64' 504 return 'unknown'
505 506 # XXX TODO
507 -def get_os():
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 # rough port of http://msdn.microsoft.com/en-us/library/ms724429%28VS.85%29.aspx 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 # Current processor architecture. See L{get_arch} for more details. 590 arch = get_arch() 591 592 # Current integer size in bits. See L{get_bits} for more details. 593 bits = get_bits() 594 595 # Current operating system. See L{get_os} for more details. 596 os = get_os() 597