Fix font deobfuscation for Python 2

This commit is contained in:
NoDRM 2021-11-16 20:09:24 +01:00
parent f20bede242
commit 5d10420422
1 changed files with 8 additions and 1 deletions

View File

@ -15,6 +15,8 @@
Decrypts / deobfuscates font files in EPUB files Decrypts / deobfuscates font files in EPUB files
""" """
from __future__ import print_function
__license__ = 'GPL v3' __license__ = 'GPL v3'
__version__ = "1" __version__ = "1"
@ -132,7 +134,11 @@ class Decryptor(object):
return data return data
def deobfuscate_single_data(self, key, data): def deobfuscate_single_data(self, key, data):
msg = bytes([c^k for c,k in zip(data, itertools.cycle(key))]) try:
msg = bytes([c^k for c,k in zip(data, itertools.cycle(key))])
except TypeError:
# Python 2
msg = ''.join(chr(ord(c)^ord(k)) for c,k in itertools.izip(data, itertools.cycle(key)))
return msg return msg
@ -308,6 +314,7 @@ def decryptFontsBook(inpath, outpath):
outf.writestr(zi, decryptor.decrypt(path, data)) outf.writestr(zi, decryptor.decrypt(path, data))
except: except:
print("Could not decrypt fonts in {0:s} because of an exception:\n{1:s}".format(os.path.basename(inpath), traceback.format_exc())) print("Could not decrypt fonts in {0:s} because of an exception:\n{1:s}".format(os.path.basename(inpath), traceback.format_exc()))
traceback.print_exc()
return 2 return 2
return 0 return 0