@@ -125,20 +125,41 @@ def ia_cdm_path():
125
125
return cdm_path
126
126
127
127
128
+ def get_legacy_lib_version (path ):
129
+ """
130
+ Determines version of the Widevine library in binary mode using a regular expression.
131
+ Returns empty string if not possible, which might indicate a problematic file/arch mismatch, so this can be used as a check.
132
+ """
133
+ if not path or not exists (path ):
134
+ return '(Not found)'
135
+ import re
136
+ with open (compat_path (path ), 'rb' ) as library :
137
+ match = re .search (br'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' , library .read ())
138
+ if not match :
139
+ return '(Undetected)'
140
+ return to_unicode (match .group (0 ))
141
+
142
+
128
143
def get_lib_version (path ):
129
144
"""
130
- Determines version of the Widevine library.
145
+ Determines version of the Widevine library using the python ctypes module .
131
146
Returns empty string if not possible, which might indicate a problematic file/arch mismatch, so this can be used as a check.
132
147
"""
133
148
from ctypes import CDLL , c_char_p
149
+ from _ctypes import dlclose
134
150
135
151
lib_version = ''
136
152
try :
137
153
lib = CDLL (compat_path (path ))
138
154
lib .GetCdmVersion .restype = c_char_p
139
155
lib_version = to_unicode (lib .GetCdmVersion ())
156
+ dlclose (lib ._handle ) # pylint: disable=protected-access
140
157
except (OSError , AttributeError ) as exc :
141
- log (4 , 'Failed to determine lib version: ' + str (exc ))
158
+ if 'wrong ELF class' in str (exc ):
159
+ log (4 , 'Wrong elf class, falling back to legacy lib version detection' )
160
+ lib_version = get_legacy_lib_version (path )
161
+ else :
162
+ log (4 , 'Failed to determine lib version: ' + str (exc ))
142
163
143
164
return lib_version
144
165
0 commit comments