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