Skip to content

Commit 5d417cc

Browse files
committed
Close lib and fall back to legacy lib version detection
1 parent cbdd2e8 commit 5d417cc

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lib/inputstreamhelper/widevine/widevine.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,41 @@ def ia_cdm_path():
125125
return cdm_path
126126

127127

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+
128143
def get_lib_version(path):
129144
"""
130-
Determines version of the Widevine library.
145+
Determines version of the Widevine library using the python ctypes module.
131146
Returns empty string if not possible, which might indicate a problematic file/arch mismatch, so this can be used as a check.
132147
"""
133148
from ctypes import CDLL, c_char_p
149+
from _ctypes import dlclose
134150

135151
lib_version = ''
136152
try:
137153
lib = CDLL(compat_path(path))
138154
lib.GetCdmVersion.restype = c_char_p
139155
lib_version = to_unicode(lib.GetCdmVersion())
156+
dlclose(lib._handle) # pylint: disable=protected-access
140157
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))
142163

143164
return lib_version
144165

tests/xbmcvfs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ def rmdir(path):
8787
def translatePath(path):
8888
"""A stub implementation of the xbmc translatePath() function"""
8989
if path.startswith('special://home'):
90-
return path.replace('special://home', os.path.join(os.getcwd(), 'tests/'))
90+
return path.replace('special://home', os.path.join(os.getcwd(), 'tests'))
9191
if path.startswith('special://masterprofile'):
92-
return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata/'))
92+
return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata'))
9393
if path.startswith('special://profile'):
94-
return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata/'))
94+
return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata'))
9595
if path.startswith('special://userdata'):
96-
return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata/'))
96+
return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata'))
9797
return path

0 commit comments

Comments
 (0)