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
30
31 """
32 Detect the current architecture and operating system.
33
34 Some functions here are really from kernel32.dll, others from version.dll.
35 """
36
37 __revision__ = "$Id: version.py 1307 2013-12-20 16:51:25Z qvasimodo $"
38
39 from defines import *
40
41
42
43 _all = None
44 _all = set(vars().keys())
45
46
47
48
49 NTDDI_WIN8 = 0x06020000
50 NTDDI_WIN7SP1 = 0x06010100
51 NTDDI_WIN7 = 0x06010000
52 NTDDI_WS08 = 0x06000100
53 NTDDI_VISTASP1 = 0x06000100
54 NTDDI_VISTA = 0x06000000
55 NTDDI_LONGHORN = NTDDI_VISTA
56 NTDDI_WS03SP2 = 0x05020200
57 NTDDI_WS03SP1 = 0x05020100
58 NTDDI_WS03 = 0x05020000
59 NTDDI_WINXPSP3 = 0x05010300
60 NTDDI_WINXPSP2 = 0x05010200
61 NTDDI_WINXPSP1 = 0x05010100
62 NTDDI_WINXP = 0x05010000
63 NTDDI_WIN2KSP4 = 0x05000400
64 NTDDI_WIN2KSP3 = 0x05000300
65 NTDDI_WIN2KSP2 = 0x05000200
66 NTDDI_WIN2KSP1 = 0x05000100
67 NTDDI_WIN2K = 0x05000000
68 NTDDI_WINNT4 = 0x04000000
69
70 OSVERSION_MASK = 0xFFFF0000
71 SPVERSION_MASK = 0x0000FF00
72 SUBVERSION_MASK = 0x000000FF
73
74
75
76 VER_PLATFORM_WIN32s = 0
77 VER_PLATFORM_WIN32_WINDOWS = 1
78 VER_PLATFORM_WIN32_NT = 2
79
80 VER_SUITE_BACKOFFICE = 0x00000004
81 VER_SUITE_BLADE = 0x00000400
82 VER_SUITE_COMPUTE_SERVER = 0x00004000
83 VER_SUITE_DATACENTER = 0x00000080
84 VER_SUITE_ENTERPRISE = 0x00000002
85 VER_SUITE_EMBEDDEDNT = 0x00000040
86 VER_SUITE_PERSONAL = 0x00000200
87 VER_SUITE_SINGLEUSERTS = 0x00000100
88 VER_SUITE_SMALLBUSINESS = 0x00000001
89 VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020
90 VER_SUITE_STORAGE_SERVER = 0x00002000
91 VER_SUITE_TERMINAL = 0x00000010
92 VER_SUITE_WH_SERVER = 0x00008000
93
94 VER_NT_DOMAIN_CONTROLLER = 0x0000002
95 VER_NT_SERVER = 0x0000003
96 VER_NT_WORKSTATION = 0x0000001
97
98 VER_BUILDNUMBER = 0x0000004
99 VER_MAJORVERSION = 0x0000002
100 VER_MINORVERSION = 0x0000001
101 VER_PLATFORMID = 0x0000008
102 VER_PRODUCT_TYPE = 0x0000080
103 VER_SERVICEPACKMAJOR = 0x0000020
104 VER_SERVICEPACKMINOR = 0x0000010
105 VER_SUITENAME = 0x0000040
106
107 VER_EQUAL = 1
108 VER_GREATER = 2
109 VER_GREATER_EQUAL = 3
110 VER_LESS = 4
111 VER_LESS_EQUAL = 5
112 VER_AND = 6
113 VER_OR = 7
114
115
116
117
118
119
120
121
122
124 _fields_ = [
125 ("dwOSVersionInfoSize", DWORD),
126 ("dwMajorVersion", DWORD),
127 ("dwMinorVersion", DWORD),
128 ("dwBuildNumber", DWORD),
129 ("dwPlatformId", DWORD),
130 ("szCSDVersion", CHAR * 128),
131 ]
133 _fields_ = [
134 ("dwOSVersionInfoSize", DWORD),
135 ("dwMajorVersion", DWORD),
136 ("dwMinorVersion", DWORD),
137 ("dwBuildNumber", DWORD),
138 ("dwPlatformId", DWORD),
139 ("szCSDVersion", WCHAR * 128),
140 ]
141
142
143
144
145
146
147
148
149
150
151
152
153
154
156 _fields_ = [
157 ("dwOSVersionInfoSize", DWORD),
158 ("dwMajorVersion", DWORD),
159 ("dwMinorVersion", DWORD),
160 ("dwBuildNumber", DWORD),
161 ("dwPlatformId", DWORD),
162 ("szCSDVersion", CHAR * 128),
163 ("wServicePackMajor", WORD),
164 ("wServicePackMinor", WORD),
165 ("wSuiteMask", WORD),
166 ("wProductType", BYTE),
167 ("wReserved", BYTE),
168 ]
170 _fields_ = [
171 ("dwOSVersionInfoSize", DWORD),
172 ("dwMajorVersion", DWORD),
173 ("dwMinorVersion", DWORD),
174 ("dwBuildNumber", DWORD),
175 ("dwPlatformId", DWORD),
176 ("szCSDVersion", WCHAR * 128),
177 ("wServicePackMajor", WORD),
178 ("wServicePackMinor", WORD),
179 ("wSuiteMask", WORD),
180 ("wProductType", BYTE),
181 ("wReserved", BYTE),
182 ]
183
184 LPOSVERSIONINFOA = POINTER(OSVERSIONINFOA)
185 LPOSVERSIONINFOW = POINTER(OSVERSIONINFOW)
186 LPOSVERSIONINFOEXA = POINTER(OSVERSIONINFOEXA)
187 LPOSVERSIONINFOEXW = POINTER(OSVERSIONINFOEXW)
188 POSVERSIONINFOA = LPOSVERSIONINFOA
189 POSVERSIONINFOW = LPOSVERSIONINFOW
190 POSVERSIONINFOEXA = LPOSVERSIONINFOEXA
191 POSVERSIONINFOEXW = LPOSVERSIONINFOA
192
193
194
195 SM_CXSCREEN = 0
196 SM_CYSCREEN = 1
197 SM_CXVSCROLL = 2
198 SM_CYHSCROLL = 3
199 SM_CYCAPTION = 4
200 SM_CXBORDER = 5
201 SM_CYBORDER = 6
202 SM_CXDLGFRAME = 7
203 SM_CYDLGFRAME = 8
204 SM_CYVTHUMB = 9
205 SM_CXHTHUMB = 10
206 SM_CXICON = 11
207 SM_CYICON = 12
208 SM_CXCURSOR = 13
209 SM_CYCURSOR = 14
210 SM_CYMENU = 15
211 SM_CXFULLSCREEN = 16
212 SM_CYFULLSCREEN = 17
213 SM_CYKANJIWINDOW = 18
214 SM_MOUSEPRESENT = 19
215 SM_CYVSCROLL = 20
216 SM_CXHSCROLL = 21
217 SM_DEBUG = 22
218 SM_SWAPBUTTON = 23
219 SM_RESERVED1 = 24
220 SM_RESERVED2 = 25
221 SM_RESERVED3 = 26
222 SM_RESERVED4 = 27
223 SM_CXMIN = 28
224 SM_CYMIN = 29
225 SM_CXSIZE = 30
226 SM_CYSIZE = 31
227 SM_CXFRAME = 32
228 SM_CYFRAME = 33
229 SM_CXMINTRACK = 34
230 SM_CYMINTRACK = 35
231 SM_CXDOUBLECLK = 36
232 SM_CYDOUBLECLK = 37
233 SM_CXICONSPACING = 38
234 SM_CYICONSPACING = 39
235 SM_MENUDROPALIGNMENT = 40
236 SM_PENWINDOWS = 41
237 SM_DBCSENABLED = 42
238 SM_CMOUSEBUTTONS = 43
239
240 SM_CXFIXEDFRAME = SM_CXDLGFRAME
241 SM_CYFIXEDFRAME = SM_CYDLGFRAME
242 SM_CXSIZEFRAME = SM_CXFRAME
243 SM_CYSIZEFRAME = SM_CYFRAME
244
245 SM_SECURE = 44
246 SM_CXEDGE = 45
247 SM_CYEDGE = 46
248 SM_CXMINSPACING = 47
249 SM_CYMINSPACING = 48
250 SM_CXSMICON = 49
251 SM_CYSMICON = 50
252 SM_CYSMCAPTION = 51
253 SM_CXSMSIZE = 52
254 SM_CYSMSIZE = 53
255 SM_CXMENUSIZE = 54
256 SM_CYMENUSIZE = 55
257 SM_ARRANGE = 56
258 SM_CXMINIMIZED = 57
259 SM_CYMINIMIZED = 58
260 SM_CXMAXTRACK = 59
261 SM_CYMAXTRACK = 60
262 SM_CXMAXIMIZED = 61
263 SM_CYMAXIMIZED = 62
264 SM_NETWORK = 63
265 SM_CLEANBOOT = 67
266 SM_CXDRAG = 68
267 SM_CYDRAG = 69
268 SM_SHOWSOUNDS = 70
269 SM_CXMENUCHECK = 71
270 SM_CYMENUCHECK = 72
271 SM_SLOWMACHINE = 73
272 SM_MIDEASTENABLED = 74
273 SM_MOUSEWHEELPRESENT = 75
274 SM_XVIRTUALSCREEN = 76
275 SM_YVIRTUALSCREEN = 77
276 SM_CXVIRTUALSCREEN = 78
277 SM_CYVIRTUALSCREEN = 79
278 SM_CMONITORS = 80
279 SM_SAMEDISPLAYFORMAT = 81
280 SM_IMMENABLED = 82
281 SM_CXFOCUSBORDER = 83
282 SM_CYFOCUSBORDER = 84
283 SM_TABLETPC = 86
284 SM_MEDIACENTER = 87
285 SM_STARTER = 88
286 SM_SERVERR2 = 89
287 SM_MOUSEHORIZONTALWHEELPRESENT = 91
288 SM_CXPADDEDBORDER = 92
289
290 SM_CMETRICS = 93
291
292 SM_REMOTESESSION = 0x1000
293 SM_SHUTTINGDOWN = 0x2000
294 SM_REMOTECONTROL = 0x2001
295 SM_CARETBLINKINGENABLED = 0x2002
296
297
298
299
300
301 PROCESSOR_ARCHITECTURE_UNKNOWN = 0xFFFF;
302 PROCESSOR_ARCHITECTURE_INTEL = 0
303 PROCESSOR_ARCHITECTURE_MIPS = 1
304 PROCESSOR_ARCHITECTURE_ALPHA = 2
305 PROCESSOR_ARCHITECTURE_PPC = 3
306 PROCESSOR_ARCHITECTURE_SHX = 4
307 PROCESSOR_ARCHITECTURE_ARM = 5
308 PROCESSOR_ARCHITECTURE_IA64 = 6
309 PROCESSOR_ARCHITECTURE_ALPHA64 = 7
310 PROCESSOR_ARCHITECTURE_MSIL = 8
311 PROCESSOR_ARCHITECTURE_AMD64 = 9
312 PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 = 10
313 PROCESSOR_ARCHITECTURE_SPARC = 20
314
315
316
317
318 PROCESSOR_INTEL_386 = 386
319 PROCESSOR_INTEL_486 = 486
320 PROCESSOR_INTEL_PENTIUM = 586
321 PROCESSOR_INTEL_IA64 = 2200
322 PROCESSOR_AMD_X8664 = 8664
323 PROCESSOR_MIPS_R4000 = 4000
324 PROCESSOR_ALPHA_21064 = 21064
325 PROCESSOR_PPC_601 = 601
326 PROCESSOR_PPC_603 = 603
327 PROCESSOR_PPC_604 = 604
328 PROCESSOR_PPC_620 = 620
329 PROCESSOR_HITACHI_SH3 = 10003
330 PROCESSOR_HITACHI_SH3E = 10004
331 PROCESSOR_HITACHI_SH4 = 10005
332 PROCESSOR_MOTOROLA_821 = 821
333 PROCESSOR_SHx_SH3 = 103
334 PROCESSOR_SHx_SH4 = 104
335 PROCESSOR_STRONGARM = 2577
336 PROCESSOR_ARM720 = 1824
337 PROCESSOR_ARM820 = 2080
338 PROCESSOR_ARM920 = 2336
339 PROCESSOR_ARM_7TDMI = 70001
340 PROCESSOR_OPTIL = 0x494F
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
362 _fields_ = [
363 ("wProcessorArchitecture", WORD),
364 ("wReserved", WORD),
365 ]
366
372
374 _fields_ = [
375 ("id", _SYSTEM_INFO_OEM_ID),
376 ("dwPageSize", DWORD),
377 ("lpMinimumApplicationAddress", LPVOID),
378 ("lpMaximumApplicationAddress", LPVOID),
379 ("dwActiveProcessorMask", DWORD_PTR),
380 ("dwNumberOfProcessors", DWORD),
381 ("dwProcessorType", DWORD),
382 ("dwAllocationGranularity", DWORD),
383 ("wProcessorLevel", WORD),
384 ("wProcessorRevision", WORD),
385 ]
386
391 dwOemId = property(__get_dwOemId, __set_dwOemId)
392
397 wProcessorArchitecture = property(__get_wProcessorArchitecture, __set_wProcessorArchitecture)
398
399 LPSYSTEM_INFO = ctypes.POINTER(SYSTEM_INFO)
400
401
402
403
412
413
414
415
424
425
426
427
429 _GetSystemMetrics = windll.user32.GetSystemMetrics
430 _GetSystemMetrics.argtypes = [ctypes.c_int]
431 _GetSystemMetrics.restype = ctypes.c_int
432 return _GetSystemMetrics(nIndex)
433
434
436 _GetLargePageMinimum = windll.user32.GetLargePageMinimum
437 _GetLargePageMinimum.argtypes = []
438 _GetLargePageMinimum.restype = SIZE_T
439 return _GetLargePageMinimum()
440
441
443
444 _GetCurrentProcess = windll.kernel32.GetCurrentProcess
445 _GetCurrentProcess.argtypes = []
446 _GetCurrentProcess.restype = HANDLE
447 return _GetCurrentProcess()
448
449
451
452 _GetCurrentThread = windll.kernel32.GetCurrentThread
453 _GetCurrentThread.argtypes = []
454 _GetCurrentThread.restype = HANDLE
455 return _GetCurrentThread()
456
457
458
459
460
462 _IsWow64Process = windll.kernel32.IsWow64Process
463 _IsWow64Process.argtypes = [HANDLE, PBOOL]
464 _IsWow64Process.restype = bool
465 _IsWow64Process.errcheck = RaiseIfZero
466
467 Wow64Process = BOOL(FALSE)
468 _IsWow64Process(hProcess, byref(Wow64Process))
469 return bool(Wow64Process)
470
471
473 _GetVersion = windll.kernel32.GetVersion
474 _GetVersion.argtypes = []
475 _GetVersion.restype = DWORD
476 _GetVersion.errcheck = RaiseIfZero
477
478
479
480
481 dwVersion = _GetVersion()
482 dwMajorVersion = dwVersion & 0x000000FF
483 dwMinorVersion = (dwVersion & 0x0000FF00) >> 8
484 if (dwVersion & 0x80000000) == 0:
485 dwBuild = (dwVersion & 0x7FFF0000) >> 16
486 else:
487 dwBuild = None
488 return int(dwMajorVersion), int(dwMinorVersion), int(dwBuild)
489
490
491
492
509
526
527 GetVersionEx = GuessStringType(GetVersionExA, GetVersionExW)
528
529
530
531
532
533
534
535
536 -def GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion):
537 _GetProductInfo = windll.kernel32.GetProductInfo
538 _GetProductInfo.argtypes = [DWORD, DWORD, DWORD, DWORD, PDWORD]
539 _GetProductInfo.restype = BOOL
540 _GetProductInfo.errcheck = RaiseIfZero
541
542 dwReturnedProductType = DWORD(0)
543 _GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, byref(dwReturnedProductType))
544 return dwReturnedProductType.value
545
546
547
548
549
550
557
559 _VerifyVersionInfoA = windll.kernel32.VerifyVersionInfoA
560 _VerifyVersionInfoA.argtypes = [LPOSVERSIONINFOEXA, DWORD, DWORDLONG]
561 _VerifyVersionInfoA.restype = bool
562 return _VerifyVersionInfoA(byref(lpVersionInfo), dwTypeMask, dwlConditionMask)
563
565 _VerifyVersionInfoW = windll.kernel32.VerifyVersionInfoW
566 _VerifyVersionInfoW.argtypes = [LPOSVERSIONINFOEXW, DWORD, DWORDLONG]
567 _VerifyVersionInfoW.restype = bool
568 return _VerifyVersionInfoW(byref(lpVersionInfo), dwTypeMask, dwlConditionMask)
569
570
571
572
573
574
576 _VerSetConditionMask = windll.kernel32.VerSetConditionMask
577 _VerSetConditionMask.argtypes = [ULONGLONG, DWORD, BYTE]
578 _VerSetConditionMask.restype = ULONGLONG
579 return _VerSetConditionMask(dwlConditionMask, dwTypeBitMask, dwConditionMask)
580
581
582
583 ARCH_UNKNOWN = "unknown"
584 ARCH_I386 = "i386"
585 ARCH_MIPS = "mips"
586 ARCH_ALPHA = "alpha"
587 ARCH_PPC = "ppc"
588 ARCH_SHX = "shx"
589 ARCH_ARM = "arm"
590 ARCH_ARM64 = "arm64"
591 ARCH_THUMB = "thumb"
592 ARCH_IA64 = "ia64"
593 ARCH_ALPHA64 = "alpha64"
594 ARCH_MSIL = "msil"
595 ARCH_AMD64 = "amd64"
596 ARCH_SPARC = "sparc"
597
598
599 ARCH_IA32 = ARCH_I386
600 ARCH_X86 = ARCH_I386
601 ARCH_X64 = ARCH_AMD64
602 ARCH_ARM7 = ARCH_ARM
603 ARCH_ARM8 = ARCH_ARM64
604 ARCH_T32 = ARCH_THUMB
605 ARCH_AARCH32 = ARCH_ARM7
606 ARCH_AARCH64 = ARCH_ARM8
607 ARCH_POWERPC = ARCH_PPC
608 ARCH_HITACHI = ARCH_SHX
609 ARCH_ITANIUM = ARCH_IA64
610
611
612 _arch_map = {
613 PROCESSOR_ARCHITECTURE_INTEL : ARCH_I386,
614 PROCESSOR_ARCHITECTURE_MIPS : ARCH_MIPS,
615 PROCESSOR_ARCHITECTURE_ALPHA : ARCH_ALPHA,
616 PROCESSOR_ARCHITECTURE_PPC : ARCH_PPC,
617 PROCESSOR_ARCHITECTURE_SHX : ARCH_SHX,
618 PROCESSOR_ARCHITECTURE_ARM : ARCH_ARM,
619 PROCESSOR_ARCHITECTURE_IA64 : ARCH_IA64,
620 PROCESSOR_ARCHITECTURE_ALPHA64 : ARCH_ALPHA64,
621 PROCESSOR_ARCHITECTURE_MSIL : ARCH_MSIL,
622 PROCESSOR_ARCHITECTURE_AMD64 : ARCH_AMD64,
623 PROCESSOR_ARCHITECTURE_SPARC : ARCH_SPARC,
624 }
625
626 OS_UNKNOWN = "Unknown"
627 OS_NT = "Windows NT"
628 OS_W2K = "Windows 2000"
629 OS_XP = "Windows XP"
630 OS_XP_64 = "Windows XP (64 bits)"
631 OS_W2K3 = "Windows 2003"
632 OS_W2K3_64 = "Windows 2003 (64 bits)"
633 OS_W2K3R2 = "Windows 2003 R2"
634 OS_W2K3R2_64 = "Windows 2003 R2 (64 bits)"
635 OS_W2K8 = "Windows 2008"
636 OS_W2K8_64 = "Windows 2008 (64 bits)"
637 OS_W2K8R2 = "Windows 2008 R2"
638 OS_W2K8R2_64 = "Windows 2008 R2 (64 bits)"
639 OS_VISTA = "Windows Vista"
640 OS_VISTA_64 = "Windows Vista (64 bits)"
641 OS_W7 = "Windows 7"
642 OS_W7_64 = "Windows 7 (64 bits)"
643
644 OS_SEVEN = OS_W7
645 OS_SEVEN_64 = OS_W7_64
646
647 OS_WINDOWS_NT = OS_NT
648 OS_WINDOWS_2000 = OS_W2K
649 OS_WINDOWS_XP = OS_XP
650 OS_WINDOWS_XP_64 = OS_XP_64
651 OS_WINDOWS_2003 = OS_W2K3
652 OS_WINDOWS_2003_64 = OS_W2K3_64
653 OS_WINDOWS_2003_R2 = OS_W2K3R2
654 OS_WINDOWS_2003_R2_64 = OS_W2K3R2_64
655 OS_WINDOWS_2008 = OS_W2K8
656 OS_WINDOWS_2008_64 = OS_W2K8_64
657 OS_WINDOWS_2008_R2 = OS_W2K8R2
658 OS_WINDOWS_2008_R2_64 = OS_W2K8R2_64
659 OS_WINDOWS_VISTA = OS_VISTA
660 OS_WINDOWS_VISTA_64 = OS_VISTA_64
661 OS_WINDOWS_SEVEN = OS_W7
662 OS_WINDOWS_SEVEN_64 = OS_W7_64
663
665 """
666 Determines the current integer size in bits.
667
668 This is useful to know if we're running in a 32 bits or a 64 bits machine.
669
670 @rtype: int
671 @return: Returns the size of L{SIZE_T} in bits.
672 """
673 return sizeof(SIZE_T) * 8
674
676 """
677 Determines the current processor architecture.
678
679 @rtype: str
680 @return:
681 On error, returns:
682
683 - L{ARCH_UNKNOWN} (C{"unknown"}) meaning the architecture could not be detected or is not known to WinAppDbg.
684
685 On success, returns one of the following values:
686
687 - L{ARCH_I386} (C{"i386"}) for Intel 32-bit x86 processor or compatible.
688 - L{ARCH_AMD64} (C{"amd64"}) for Intel 64-bit x86_64 processor or compatible.
689
690 May also return one of the following values if you get both Python and
691 WinAppDbg to work in such machines... let me know if you do! :)
692
693 - L{ARCH_MIPS} (C{"mips"}) for MIPS compatible processors.
694 - L{ARCH_ALPHA} (C{"alpha"}) for Alpha processors.
695 - L{ARCH_PPC} (C{"ppc"}) for PowerPC compatible processors.
696 - L{ARCH_SHX} (C{"shx"}) for Hitachi SH processors.
697 - L{ARCH_ARM} (C{"arm"}) for ARM compatible processors.
698 - L{ARCH_IA64} (C{"ia64"}) for Intel Itanium processor or compatible.
699 - L{ARCH_ALPHA64} (C{"alpha64"}) for Alpha64 processors.
700 - L{ARCH_MSIL} (C{"msil"}) for the .NET virtual machine.
701 - L{ARCH_SPARC} (C{"sparc"}) for Sun Sparc processors.
702
703 Probably IronPython returns C{ARCH_MSIL} but I haven't tried it. Python
704 on Windows CE and Windows Mobile should return C{ARCH_ARM}. Python on
705 Solaris using Wine would return C{ARCH_SPARC}. Python in an Itanium
706 machine should return C{ARCH_IA64} both on Wine and proper Windows.
707 All other values should only be returned on Linux using Wine.
708 """
709 try:
710 si = GetNativeSystemInfo()
711 except Exception:
712 si = GetSystemInfo()
713 try:
714 return _arch_map[si.id.w.wProcessorArchitecture]
715 except KeyError:
716 return ARCH_UNKNOWN
717
719 """
720 Determines if the current process is running in Windows-On-Windows 64 bits.
721
722 @rtype: bool
723 @return: C{True} of the current process is a 32 bit program running in a
724 64 bit version of Windows, C{False} if it's either a 32 bit program
725 in a 32 bit Windows or a 64 bit program in a 64 bit Windows.
726 """
727
728
729 if bits == 64:
730 wow64 = False
731 else:
732 try:
733 wow64 = IsWow64Process( GetCurrentProcess() )
734 except Exception:
735 wow64 = False
736 return wow64
737
739 """
740 Determines the current operating system.
741
742 This function allows you to quickly tell apart major OS differences.
743 For more detailed information call L{GetVersionEx} instead.
744
745 @note:
746 Wine reports itself as Windows XP 32 bits
747 (even if the Linux host is 64 bits).
748 ReactOS may report itself as Windows 2000 or Windows XP,
749 depending on the version of ReactOS.
750
751 @type osvi: L{OSVERSIONINFOEXA}
752 @param osvi: Optional. The return value from L{GetVersionEx}.
753
754 @rtype: str
755 @return:
756 One of the following values:
757 - L{OS_UNKNOWN} (C{"Unknown"})
758 - L{OS_NT} (C{"Windows NT"})
759 - L{OS_W2K} (C{"Windows 2000"})
760 - L{OS_XP} (C{"Windows XP"})
761 - L{OS_XP_64} (C{"Windows XP (64 bits)"})
762 - L{OS_W2K3} (C{"Windows 2003"})
763 - L{OS_W2K3_64} (C{"Windows 2003 (64 bits)"})
764 - L{OS_W2K3R2} (C{"Windows 2003 R2"})
765 - L{OS_W2K3R2_64} (C{"Windows 2003 R2 (64 bits)"})
766 - L{OS_W2K8} (C{"Windows 2008"})
767 - L{OS_W2K8_64} (C{"Windows 2008 (64 bits)"})
768 - L{OS_W2K8R2} (C{"Windows 2008 R2"})
769 - L{OS_W2K8R2_64} (C{"Windows 2008 R2 (64 bits)"})
770 - L{OS_VISTA} (C{"Windows Vista"})
771 - L{OS_VISTA_64} (C{"Windows Vista (64 bits)"})
772 - L{OS_W7} (C{"Windows 7"})
773 - L{OS_W7_64} (C{"Windows 7 (64 bits)"})
774 """
775
776 if not osvi:
777 osvi = GetVersionEx()
778 if osvi.dwPlatformId == VER_PLATFORM_WIN32_NT and osvi.dwMajorVersion > 4:
779 if osvi.dwMajorVersion == 6:
780 if osvi.dwMinorVersion == 0:
781 if osvi.wProductType == VER_NT_WORKSTATION:
782 if bits == 64 or wow64:
783 return 'Windows Vista (64 bits)'
784 return 'Windows Vista'
785 else:
786 if bits == 64 or wow64:
787 return 'Windows 2008 (64 bits)'
788 return 'Windows 2008'
789 if osvi.dwMinorVersion == 1:
790 if osvi.wProductType == VER_NT_WORKSTATION:
791 if bits == 64 or wow64:
792 return 'Windows 7 (64 bits)'
793 return 'Windows 7'
794 else:
795 if bits == 64 or wow64:
796 return 'Windows 2008 R2 (64 bits)'
797 return 'Windows 2008 R2'
798 if osvi.dwMajorVersion == 5:
799 if osvi.dwMinorVersion == 2:
800 if GetSystemMetrics(SM_SERVERR2):
801 if bits == 64 or wow64:
802 return 'Windows 2003 R2 (64 bits)'
803 return 'Windows 2003 R2'
804 if osvi.wSuiteMask in (VER_SUITE_STORAGE_SERVER, VER_SUITE_WH_SERVER):
805 if bits == 64 or wow64:
806 return 'Windows 2003 (64 bits)'
807 return 'Windows 2003'
808 if osvi.wProductType == VER_NT_WORKSTATION and arch == ARCH_AMD64:
809 return 'Windows XP (64 bits)'
810 else:
811 if bits == 64 or wow64:
812 return 'Windows 2003 (64 bits)'
813 return 'Windows 2003'
814 if osvi.dwMinorVersion == 1:
815 return 'Windows XP'
816 if osvi.dwMinorVersion == 0:
817 return 'Windows 2000'
818 if osvi.dwMajorVersion == 4:
819 return 'Windows NT'
820 return 'Unknown'
821
823 """
824 Determines the current operating system.
825
826 This function allows you to quickly tell apart major OS differences.
827 For more detailed information call L{kernel32.GetVersionEx} instead.
828
829 @note:
830 Wine reports itself as Windows XP 32 bits
831 (even if the Linux host is 64 bits).
832 ReactOS may report itself as Windows 2000 or Windows XP,
833 depending on the version of ReactOS.
834
835 @type osvi: L{OSVERSIONINFOEXA}
836 @param osvi: Optional. The return value from L{kernel32.GetVersionEx}.
837
838 @rtype: int
839 @return: NTDDI version number.
840 """
841 if not osvi:
842 osvi = GetVersionEx()
843 ntddi = 0
844 ntddi += (osvi.dwMajorVersion & 0xFF) << 24
845 ntddi += (osvi.dwMinorVersion & 0xFF) << 16
846 ntddi += (osvi.wServicePackMajor & 0xFF) << 8
847 ntddi += (osvi.wServicePackMinor & 0xFF)
848 return ntddi
849
850
851
852
853 bits = _get_bits()
854
855
856 arch = _get_arch()
857
858
859 wow64 = _get_wow64()
860
861 _osvi = GetVersionEx()
862
863
864 os = _get_os(_osvi)
865
866
867 NTDDI_VERSION = _get_ntddi(_osvi)
868
869
870 WINVER = NTDDI_VERSION >> 16
871
872
873
874 VS_FF_DEBUG = 0x00000001
875 VS_FF_PRERELEASE = 0x00000002
876 VS_FF_PATCHED = 0x00000004
877 VS_FF_PRIVATEBUILD = 0x00000008
878 VS_FF_INFOINFERRED = 0x00000010
879 VS_FF_SPECIALBUILD = 0x00000020
880
881 VOS_UNKNOWN = 0x00000000
882 VOS__WINDOWS16 = 0x00000001
883 VOS__PM16 = 0x00000002
884 VOS__PM32 = 0x00000003
885 VOS__WINDOWS32 = 0x00000004
886 VOS_DOS = 0x00010000
887 VOS_OS216 = 0x00020000
888 VOS_OS232 = 0x00030000
889 VOS_NT = 0x00040000
890
891 VOS_DOS_WINDOWS16 = 0x00010001
892 VOS_DOS_WINDOWS32 = 0x00010004
893 VOS_NT_WINDOWS32 = 0x00040004
894 VOS_OS216_PM16 = 0x00020002
895 VOS_OS232_PM32 = 0x00030003
896
897 VFT_UNKNOWN = 0x00000000
898 VFT_APP = 0x00000001
899 VFT_DLL = 0x00000002
900 VFT_DRV = 0x00000003
901 VFT_FONT = 0x00000004
902 VFT_VXD = 0x00000005
903 VFT_RESERVED = 0x00000006
904 VFT_STATIC_LIB = 0x00000007
905
906 VFT2_UNKNOWN = 0x00000000
907
908 VFT2_DRV_PRINTER = 0x00000001
909 VFT2_DRV_KEYBOARD = 0x00000002
910 VFT2_DRV_LANGUAGE = 0x00000003
911 VFT2_DRV_DISPLAY = 0x00000004
912 VFT2_DRV_MOUSE = 0x00000005
913 VFT2_DRV_NETWORK = 0x00000006
914 VFT2_DRV_SYSTEM = 0x00000007
915 VFT2_DRV_INSTALLABLE = 0x00000008
916 VFT2_DRV_SOUND = 0x00000009
917 VFT2_DRV_COMM = 0x0000000A
918 VFT2_DRV_RESERVED = 0x0000000B
919 VFT2_DRV_VERSIONED_PRINTER = 0x0000000C
920
921 VFT2_FONT_RASTER = 0x00000001
922 VFT2_FONT_VECTOR = 0x00000002
923 VFT2_FONT_TRUETYPE = 0x00000003
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
941 _fields_ = [
942 ("dwSignature", DWORD),
943 ("dwStrucVersion", DWORD),
944 ("dwFileVersionMS", DWORD),
945 ("dwFileVersionLS", DWORD),
946 ("dwProductVersionMS", DWORD),
947 ("dwProductVersionLS", DWORD),
948 ("dwFileFlagsMask", DWORD),
949 ("dwFileFlags", DWORD),
950 ("dwFileOS", DWORD),
951 ("dwFileType", DWORD),
952 ("dwFileSubtype", DWORD),
953 ("dwFileDateMS", DWORD),
954 ("dwFileDateLS", DWORD),
955 ]
956 PVS_FIXEDFILEINFO = POINTER(VS_FIXEDFILEINFO)
957 LPVS_FIXEDFILEINFO = PVS_FIXEDFILEINFO
958
959
960
961
962
963
964
965
966
967
968
970 _GetFileVersionInfoA = windll.version.GetFileVersionInfoA
971 _GetFileVersionInfoA.argtypes = [LPSTR, DWORD, DWORD, LPVOID]
972 _GetFileVersionInfoA.restype = bool
973 _GetFileVersionInfoA.errcheck = RaiseIfZero
974
975 _GetFileVersionInfoSizeA = windll.version.GetFileVersionInfoSizeA
976 _GetFileVersionInfoSizeA.argtypes = [LPSTR, LPVOID]
977 _GetFileVersionInfoSizeA.restype = DWORD
978 _GetFileVersionInfoSizeA.errcheck = RaiseIfZero
979
980 dwLen = _GetFileVersionInfoSizeA(lptstrFilename, None)
981 lpData = ctypes.create_string_buffer(dwLen)
982 _GetFileVersionInfoA(lptstrFilename, 0, dwLen, byref(lpData))
983 return lpData
984
986 _GetFileVersionInfoW = windll.version.GetFileVersionInfoW
987 _GetFileVersionInfoW.argtypes = [LPWSTR, DWORD, DWORD, LPVOID]
988 _GetFileVersionInfoW.restype = bool
989 _GetFileVersionInfoW.errcheck = RaiseIfZero
990
991 _GetFileVersionInfoSizeW = windll.version.GetFileVersionInfoSizeW
992 _GetFileVersionInfoSizeW.argtypes = [LPWSTR, LPVOID]
993 _GetFileVersionInfoSizeW.restype = DWORD
994 _GetFileVersionInfoSizeW.errcheck = RaiseIfZero
995
996 dwLen = _GetFileVersionInfoSizeW(lptstrFilename, None)
997 lpData = ctypes.create_string_buffer(dwLen)
998 _GetFileVersionInfoW(lptstrFilename, 0, dwLen, byref(lpData))
999 return lpData
1000
1001 GetFileVersionInfo = GuessStringType(GetFileVersionInfoA, GetFileVersionInfoW)
1002
1003
1004
1005
1006
1007
1008
1010 _VerQueryValueA = windll.version.VerQueryValueA
1011 _VerQueryValueA.argtypes = [LPVOID, LPSTR, LPVOID, POINTER(UINT)]
1012 _VerQueryValueA.restype = bool
1013 _VerQueryValueA.errcheck = RaiseIfZero
1014
1015 lpBuffer = LPVOID(0)
1016 uLen = UINT(0)
1017 _VerQueryValueA(pBlock, lpSubBlock, byref(lpBuffer), byref(uLen))
1018 return lpBuffer, uLen.value
1019
1021 _VerQueryValueW = windll.version.VerQueryValueW
1022 _VerQueryValueW.argtypes = [LPVOID, LPWSTR, LPVOID, POINTER(UINT)]
1023 _VerQueryValueW.restype = bool
1024 _VerQueryValueW.errcheck = RaiseIfZero
1025
1026 lpBuffer = LPVOID(0)
1027 uLen = UINT(0)
1028 _VerQueryValueW(pBlock, lpSubBlock, byref(lpBuffer), byref(uLen))
1029 return lpBuffer, uLen.value
1030
1031 VerQueryValue = GuessStringType(VerQueryValueA, VerQueryValueW)
1032
1033
1034
1035 _all = set(vars().keys()).difference(_all)
1036 __all__ = [_x for _x in _all if not _x.startswith('_')]
1037 __all__.sort()
1038
1039