Fix Wine import for Python2

This commit is contained in:
Florian Bach 2022-01-16 19:00:29 +01:00
parent 05a302424c
commit 3a460ae1fd

View File

@ -3,7 +3,7 @@
#@@CALIBRE_COMPAT_CODE@@ #@@CALIBRE_COMPAT_CODE@@
import sys import sys, binascii
def unfuck(user): def unfuck(user):
# Wine uses a pretty nonstandard encoding in their registry file. # Wine uses a pretty nonstandard encoding in their registry file.
@ -175,7 +175,7 @@ def GetMasterKey(path_to_wine_prefix):
signature = struct.pack('>I', signature)[1:] signature = struct.pack('>I', signature)[1:]
if (verbose_logging): if (verbose_logging):
print("Signature: " + str(signature.hex())) print("Signature: " + str(binascii.hexlify(signature)))
# Search for the username in the registry: # Search for the username in the registry:
user = None user = None
@ -240,8 +240,8 @@ def GetMasterKey(path_to_wine_prefix):
# Now parse ... # Now parse ...
key_line = key_line.split(':', 1)[1] key_line = key_line.split(':', 1)[1]
key_line = key_line.replace('\t', '').replace(' ', '').replace(',', '') key_line = key_line.replace('\t', '').replace('\r', '').replace('\n', '').replace(' ', '').replace(',', '')
key_line = bytes.fromhex(key_line) key_line = binascii.unhexlify(key_line)
else: else:
if (line.startswith("[Software\\\\Adobe\\\\Adept\\\\Device]")): if (line.startswith("[Software\\\\Adobe\\\\Adept\\\\Device]")):
@ -261,13 +261,16 @@ def GetMasterKey(path_to_wine_prefix):
return None return None
if verbose_logging: if verbose_logging:
print("Encrypted key: " + str(key_line)) print("Encrypted key: " + binascii.hexlify(key_line))
# These should all be "bytes" or "bytearray" # These should all be "bytes" (Py3) or "str" (Py2)
#print(type(vendor)) #print(type(vendor))
#print(type(signature)) #print(type(signature))
#print(type(user)) #print(type(user))
if sys.version_info[0] == 2:
user = bytes(user)
entropy = struct.pack('>I12s3s13s', serial, vendor, signature, user) entropy = struct.pack('>I12s3s13s', serial, vendor, signature, user)
if verbose_logging: if verbose_logging:
@ -290,7 +293,7 @@ def GetMasterKey(path_to_wine_prefix):
keykey = data keykey = data
if verbose_logging: if verbose_logging:
print("Key key: ") print("Key key: ")
print(keykey) print(binascii.hexlify(keykey))
return keykey return keykey
else: else:
@ -347,8 +350,8 @@ def CryptUnprotectDataExecuteWine(wineprefix, data, entropy):
env_dict["WINEDEBUG"] = "+err,+fixme" env_dict["WINEDEBUG"] = "+err,+fixme"
# Use environment variables to get the input data to the application. # Use environment variables to get the input data to the application.
env_dict["X_DECRYPT_DATA"] = data.hex() env_dict["X_DECRYPT_DATA"] = binascii.hexlify(data)
env_dict["X_DECRYPT_ENTROPY"] = entropy.hex() env_dict["X_DECRYPT_ENTROPY"] = binascii.hexlify(entropy)
try: try:
from calibre.utils.config import config_dir from calibre.utils.config import config_dir
@ -372,7 +375,7 @@ def CryptUnprotectDataExecuteWine(wineprefix, data, entropy):
#print(prog_stderr.decode("utf-8")) #print(prog_stderr.decode("utf-8"))
else: else:
print("Successfully got encryption key from WINE.") print("Successfully got encryption key from WINE.")
master_key = bytes.fromhex(key_string) master_key = binascii.unhexlify(key_string)
return True, master_key return True, master_key