summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Bleeker <[email protected]>2021-12-28 18:34:11 +0100
committernoDRM <[email protected]>2021-12-29 12:18:06 +0000
commit5ace15e912a432c88d5fbb947fac53d397e45a5c (patch)
treef2df9857c4d0e4b3ed6e7446aff3249961b2b276
parente0fcd99bcb44adb648d5999b886f4a486decd84d (diff)
Python 3 fixes
-rw-r--r--DeDRM_plugin/alfcrypto.py10
-rw-r--r--DeDRM_plugin/flatxml2html.py10
-rw-r--r--DeDRM_plugin/topazextract.py8
3 files changed, 20 insertions, 8 deletions
diff --git a/DeDRM_plugin/alfcrypto.py b/DeDRM_plugin/alfcrypto.py
index 5c197a7..5a31d09 100644
--- a/DeDRM_plugin/alfcrypto.py
+++ b/DeDRM_plugin/alfcrypto.py
@@ -207,8 +207,9 @@ def _load_python_alfcrypto():
def ctx_init(self, key):
ctx1 = 0x0CAFFE19E
- for keyChar in key:
- keyByte = ord(keyChar)
+ if isinstance(key, str):
+ key = key.encode('latin-1')
+ for keyByte in key:
ctx2 = ctx1
ctx1 = ((((ctx1 >>2) * (ctx1 >>7))&0xFFFFFFFF) ^ (keyByte * keyByte * 0x0F902007)& 0xFFFFFFFF )
self._ctx = [ctx1, ctx2]
@@ -220,8 +221,9 @@ def _load_python_alfcrypto():
ctx1 = ctx[0]
ctx2 = ctx[1]
plainText = ""
- for dataChar in data:
- dataByte = ord(dataChar)
+ if isinstance(data, str):
+ data = data.encode('latin-1')
+ for dataByte in data:
m = (dataByte ^ ((ctx1 >> 3) &0xFF) ^ ((ctx2<<3) & 0xFF)) &0xFF
ctx2 = ctx1
ctx1 = (((ctx1 >> 2) * (ctx1 >> 7)) &0xFFFFFFFF) ^((m * m * 0x0F902007) &0xFFFFFFFF)
diff --git a/DeDRM_plugin/flatxml2html.py b/DeDRM_plugin/flatxml2html.py
index 2fe80c3..63cd8f6 100644
--- a/DeDRM_plugin/flatxml2html.py
+++ b/DeDRM_plugin/flatxml2html.py
@@ -473,8 +473,10 @@ class DocParser(object):
if (link > 0):
linktype = self.link_type[link-1]
title = self.link_title[link-1]
- if (title == b"") or (parares.rfind(title.decode('utf-8')) < 0):
- title=parares[lstart:].encode('utf-8')
+ if isinstance(title, bytes):
+ title = title.decode('utf-8')
+ if (title == "") or (parares.rfind(title) < 0):
+ title=parares[lstart:]
if linktype == 'external' :
linkhref = self.link_href[link-1]
linkhtml = '<a href="%s">' % linkhref
@@ -485,9 +487,9 @@ class DocParser(object):
else :
# just link to the current page
linkhtml = '<a href="#' + self.id + '">'
- linkhtml += title.decode('utf-8')
+ linkhtml += title
linkhtml += '</a>'
- pos = parares.rfind(title.decode('utf-8'))
+ pos = parares.rfind(title)
if pos >= 0:
parares = parares[0:pos] + linkhtml + parares[pos+len(title):]
else :
diff --git a/DeDRM_plugin/topazextract.py b/DeDRM_plugin/topazextract.py
index 8be96a2..f65d25a 100644
--- a/DeDRM_plugin/topazextract.py
+++ b/DeDRM_plugin/topazextract.py
@@ -175,6 +175,8 @@ def decryptRecord(data,PID):
# Try to decrypt a dkey record (contains the bookPID)
def decryptDkeyRecord(data,PID):
record = decryptRecord(data,PID)
+ if isinstance(record, str):
+ record = record.encode('latin-1')
fields = unpack('3sB8sB8s3s',record)
if fields[0] != b'PID' or fields[5] != b'pid' :
raise DrmException("Didn't find PID magic numbers in record")
@@ -318,6 +320,8 @@ class TopazBook:
raise DrmException("Error: Attempt to decrypt without bookKey")
if compressed:
+ if isinstance(record, str):
+ record = bytes(record, 'latin-1')
record = zlib.decompress(record)
return record
@@ -345,6 +349,8 @@ class TopazBook:
for pid in pidlst:
# use 8 digit pids here
pid = pid[0:8]
+ if isinstance(pid, str):
+ pid = pid.encode('latin-1')
print("Trying: {0}".format(pid))
bookKeys = []
data = keydata
@@ -412,6 +418,8 @@ class TopazBook:
outputFile = os.path.join(destdir,fname)
print(".", end=' ')
record = self.getBookPayloadRecord(name,index)
+ if isinstance(record, str):
+ record=bytes(record, 'latin-1')
if record != b'':
open(outputFile, 'wb').write(record)
print(" ")