From 5d10420422addaeeb20556c13d45d0285b1d7f43 Mon Sep 17 00:00:00 2001 From: NoDRM Date: Tue, 16 Nov 2021 20:09:24 +0100 Subject: [PATCH] Fix font deobfuscation for Python 2 --- DeDRM_plugin/epubfontdecrypt.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DeDRM_plugin/epubfontdecrypt.py b/DeDRM_plugin/epubfontdecrypt.py index 858f25e..de40b52 100644 --- a/DeDRM_plugin/epubfontdecrypt.py +++ b/DeDRM_plugin/epubfontdecrypt.py @@ -15,6 +15,8 @@ Decrypts / deobfuscates font files in EPUB files """ +from __future__ import print_function + __license__ = 'GPL v3' __version__ = "1" @@ -132,7 +134,11 @@ class Decryptor(object): return 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 @@ -308,6 +314,7 @@ def decryptFontsBook(inpath, outpath): outf.writestr(zi, decryptor.decrypt(path, data)) except: 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 0