]> xmof Git - DeDRM.git/commitdiff
More handling of difference between python2 and python3
authorRémi Vanicat <vanicat@debian.org>
Fri, 8 May 2020 15:57:28 +0000 (17:57 +0200)
committerRémi Vanicat <vanicat@debian.org>
Fri, 8 May 2020 16:09:27 +0000 (18:09 +0200)
Place where python3 use bytes/int and python2 str/str

DeDRM_plugin/ineptepub.py

index e3815e772f99be2cc499a48deab9bca3c228690a..839e0677982b1ba73eb4f3be858005da0ea8c62e 100644 (file)
@@ -210,7 +210,7 @@ def _load_crypto_libcrypto():
 
         def decrypt(self, data):
             out = create_string_buffer(len(data))
-            iv = ("\x00" * self._blocksize)
+            iv = (b"\x00" * self._blocksize)
             rv = AES_cbc_encrypt(data, out, len(data), self._key, iv, 0)
             if rv == 0:
                 raise ADEPTError('AES decryption failed')
@@ -371,7 +371,7 @@ class Decryptor(object):
     def decompress(self, bytes):
         dc = zlib.decompressobj(-15)
         bytes = dc.decompress(bytes)
-        ex = dc.decompress('Z') + dc.flush()
+        ex = dc.decompress(b'Z') + dc.flush()
         if ex:
             bytes = bytes + ex
         return bytes
@@ -379,7 +379,11 @@ class Decryptor(object):
     def decrypt(self, path, data):
         if path.encode('utf-8') in self._encrypted:
             data = self._aes.decrypt(data)[16:]
-            data = data[:-ord(data[-1])]
+            if type(data[-1]) != int:
+                place = ord(data[-1])
+            else:
+                place = data[-1]
+            data = data[:-place]
             data = self.decompress(data)
         return data