summaryrefslogtreecommitdiffstats
path: root/DeDRM_plugin
diff options
context:
space:
mode:
authorNoDRM <[email protected]>2022-07-13 17:31:14 +0200
committerNoDRM <[email protected]>2022-07-13 17:31:57 +0200
commitfed8bb716befd2a6f9715dce3d6bda2f1dec5eba (patch)
tree43696e92adb099d1d19a73f9e0eb01b664c67fed /DeDRM_plugin
parentc12d214b5900db99f147848e046be758fb963070 (diff)
Add some Python2 compat code I forgot to add earlier
Diffstat (limited to 'DeDRM_plugin')
-rwxr-xr-xDeDRM_plugin/ineptpdf.py21
-rw-r--r--DeDRM_plugin/utilities.py10
2 files changed, 19 insertions, 12 deletions
diff --git a/DeDRM_plugin/ineptpdf.py b/DeDRM_plugin/ineptpdf.py
index 310ab1e..24fc150 100755
--- a/DeDRM_plugin/ineptpdf.py
+++ b/DeDRM_plugin/ineptpdf.py
@@ -50,13 +50,14 @@
# 9.1.0 - Support for decrypting with owner password, support for V=5, R=5 and R=6 PDF files, support for AES256-encrypted PDFs.
# 9.1.1 - Only support PyCryptodome; clean up the code
# 10.0.0 - Add support for "hardened" Adobe DRM (RMSDK >= 10)
+# 10.0.2 - Fix some Python2 stuff
"""
Decrypts Adobe ADEPT-encrypted PDF files.
"""
__license__ = 'GPL v3'
-__version__ = "10.0.0"
+__version__ = "10.0.2"
import codecs
import hashlib
@@ -65,6 +66,8 @@ import os
import re
import zlib
import struct
+import binascii
+import base64
from io import BytesIO
from decimal import Decimal
import itertools
@@ -1369,7 +1372,7 @@ class PDFDocument(object):
return file_key
- def process_with_aes(self, key: bytes, encrypt: bool, data: bytes, repetitions: int = 1, iv: bytes = None):
+ def process_with_aes(self, key, encrypt, data, repetitions = 1, iv = None):
if iv is None:
keylen = len(key)
iv = bytes([0x00]*keylen)
@@ -1601,19 +1604,17 @@ class PDFDocument(object):
def initialize_ebx_ignoble(self, keyb64, docid, param):
self.is_printable = self.is_modifiable = self.is_extractable = True
- try:
- key = keyb64.decode('base64')[:16]
- # This will probably always error, but I'm not 100% sure, so lets leave the old code in.
- except AttributeError:
- key = codecs.decode(keyb64.encode("ascii"), 'base64')[:16]
+ key = keyb64.decode('base64')[:16]
length = int_value(param.get('Length', 0)) / 8
- rights = str_value(param.get('ADEPT_LICENSE')).decode('base64')
+ rights = codecs.decode(str_value(param.get('ADEPT_LICENSE')), "base64")
rights = zlib.decompress(rights, -15)
rights = etree.fromstring(rights)
expr = './/{http://ns.adobe.com/adept}encryptedKey'
- bookkey = ''.join(rights.findtext(expr)).decode('base64')
- bookkey = unpad(AES.new(key, AES.MODE_CBC, b'\x00'*16).decrypt(bookkey), 16) # PKCS#7
+ bookkey = ''.join(rights.findtext(expr))
+ bookkey = base64.b64decode(bookkey)
+ bookkey = AES.new(key, AES.MODE_CBC, b'\x00'*16).decrypt(bookkey)
+ bookkey = unpad(bookkey, 16) # PKCS#7
if len(bookkey) > 16:
bookkey = bookkey[-16:]
ebx_V = int_value(param.get('V', 4))
diff --git a/DeDRM_plugin/utilities.py b/DeDRM_plugin/utilities.py
index bd008b5..cd08a66 100644
--- a/DeDRM_plugin/utilities.py
+++ b/DeDRM_plugin/utilities.py
@@ -4,6 +4,7 @@
#@@CALIBRE_COMPAT_CODE@@
from ignoblekeyGenPassHash import generate_key
+import sys
__license__ = 'GPL v3'
@@ -21,8 +22,13 @@ DETAILED_MESSAGE = \
def uStrCmp (s1, s2, caseless=False):
import unicodedata as ud
- str1 = s1 if isinstance(s1, str) else str(s1)
- str2 = s2 if isinstance(s2, str) else str(s2)
+ if sys.version_info[0] == 2:
+ str1 = s1 if isinstance(s1, unicode) else unicode(s1)
+ str2 = s2 if isinstance(s2, unicode) else unicode(s2)
+ else:
+ str1 = s1 if isinstance(s1, str) else str(s1)
+ str2 = s2 if isinstance(s2, str) else str(s2)
+
if caseless:
return ud.normalize('NFC', str1.lower()) == ud.normalize('NFC', str2.lower())
else: