ยปCore Development>Code coverage>PC/validate_ucrtbase.py

Python code coverage for PC/validate_ucrtbase.py

#countcontent
1n/a'''
2n/aThis script gets the version number from ucrtbased.dll and checks
3n/awhether it is a version with a known issue.
4n/a'''
5n/a
6n/aimport sys
7n/a
8n/afrom ctypes import (c_buffer, POINTER, byref, create_unicode_buffer,
9n/a Structure, WinDLL)
10n/afrom ctypes.wintypes import DWORD, HANDLE
11n/a
12n/aclass VS_FIXEDFILEINFO(Structure):
13n/a _fields_ = [
14n/a ("dwSignature", DWORD),
15n/a ("dwStrucVersion", DWORD),
16n/a ("dwFileVersionMS", DWORD),
17n/a ("dwFileVersionLS", DWORD),
18n/a ("dwProductVersionMS", DWORD),
19n/a ("dwProductVersionLS", DWORD),
20n/a ("dwFileFlagsMask", DWORD),
21n/a ("dwFileFlags", DWORD),
22n/a ("dwFileOS", DWORD),
23n/a ("dwFileType", DWORD),
24n/a ("dwFileSubtype", DWORD),
25n/a ("dwFileDateMS", DWORD),
26n/a ("dwFileDateLS", DWORD),
27n/a ]
28n/a
29n/akernel32 = WinDLL('kernel32')
30n/aversion = WinDLL('version')
31n/a
32n/aif len(sys.argv) < 2:
33n/a print('Usage: validate_ucrtbase.py <ucrtbase|ucrtbased>')
34n/a sys.exit(2)
35n/a
36n/atry:
37n/a ucrtbased = WinDLL(sys.argv[1])
38n/aexcept OSError:
39n/a print('Cannot find ucrtbased.dll')
40n/a # This likely means that VS is not installed, but that is an
41n/a # obvious enough problem if you're trying to produce a debug
42n/a # build that we don't need to fail here.
43n/a sys.exit(0)
44n/a
45n/a# We will immediately double the length up to MAX_PATH, but the
46n/a# path may be longer, so we retry until the returned string is
47n/a# shorter than our buffer.
48n/aname_len = actual_len = 130
49n/awhile actual_len == name_len:
50n/a name_len *= 2
51n/a name = create_unicode_buffer(name_len)
52n/a actual_len = kernel32.GetModuleFileNameW(HANDLE(ucrtbased._handle),
53n/a name, len(name))
54n/a if not actual_len:
55n/a print('Failed to get full module name.')
56n/a sys.exit(2)
57n/a
58n/asize = version.GetFileVersionInfoSizeW(name, None)
59n/aif not size:
60n/a print('Failed to get size of version info.')
61n/a sys.exit(2)
62n/a
63n/aver_block = c_buffer(size)
64n/aif (not version.GetFileVersionInfoW(name, None, size, ver_block) or
65n/a not ver_block):
66n/a print('Failed to get version info.')
67n/a sys.exit(2)
68n/a
69n/apvi = POINTER(VS_FIXEDFILEINFO)()
70n/aif not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())):
71n/a print('Failed to get version value from info.')
72n/a sys.exit(2)
73n/a
74n/aver = (
75n/a pvi.contents.dwProductVersionMS >> 16,
76n/a pvi.contents.dwProductVersionMS & 0xFFFF,
77n/a pvi.contents.dwProductVersionLS >> 16,
78n/a pvi.contents.dwProductVersionLS & 0xFFFF,
79n/a)
80n/a
81n/aprint('{} is version {}.{}.{}.{}'.format(name.value, *ver))
82n/a
83n/aif ver < (10, 0, 10586):
84n/a print('WARN: ucrtbased contains known issues. '
85n/a 'Please update the Windows 10 SDK.')
86n/a print('See:')
87n/a print(' http://bugs.python.org/issue27705')
88n/a print(' https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk')
89n/a sys.exit(1)