Skip to content

Commit

Permalink
Close lib and fall back to legacy lib version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister committed Jan 6, 2021
1 parent cbdd2e8 commit 5d417cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 23 additions & 2 deletions lib/inputstreamhelper/widevine/widevine.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,41 @@ def ia_cdm_path():
return cdm_path


def get_legacy_lib_version(path):
"""
Determines version of the Widevine library in binary mode using a regular expression.
Returns empty string if not possible, which might indicate a problematic file/arch mismatch, so this can be used as a check.
"""
if not path or not exists(path):
return '(Not found)'
import re
with open(compat_path(path), 'rb') as library:
match = re.search(br'[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+', library.read())
if not match:
return '(Undetected)'
return to_unicode(match.group(0))


def get_lib_version(path):
"""
Determines version of the Widevine library.
Determines version of the Widevine library using the python ctypes module.
Returns empty string if not possible, which might indicate a problematic file/arch mismatch, so this can be used as a check.
"""
from ctypes import CDLL, c_char_p
from _ctypes import dlclose

lib_version = ''
try:
lib = CDLL(compat_path(path))
lib.GetCdmVersion.restype = c_char_p
lib_version = to_unicode(lib.GetCdmVersion())
dlclose(lib._handle) # pylint: disable=protected-access
except (OSError, AttributeError) as exc:
log(4, 'Failed to determine lib version: ' + str(exc))
if 'wrong ELF class' in str(exc):
log(4, 'Wrong elf class, falling back to legacy lib version detection')
lib_version = get_legacy_lib_version(path)
else:
log(4, 'Failed to determine lib version: ' + str(exc))

return lib_version

Expand Down
8 changes: 4 additions & 4 deletions tests/xbmcvfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def rmdir(path):
def translatePath(path):
"""A stub implementation of the xbmc translatePath() function"""
if path.startswith('special://home'):
return path.replace('special://home', os.path.join(os.getcwd(), 'tests/'))
return path.replace('special://home', os.path.join(os.getcwd(), 'tests'))
if path.startswith('special://masterprofile'):
return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata/'))
return path.replace('special://masterprofile', os.path.join(os.getcwd(), 'tests/userdata'))
if path.startswith('special://profile'):
return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata/'))
return path.replace('special://profile', os.path.join(os.getcwd(), 'tests/userdata'))
if path.startswith('special://userdata'):
return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata/'))
return path.replace('special://userdata', os.path.join(os.getcwd(), 'tests/userdata'))
return path

0 comments on commit 5d417cc

Please sign in to comment.