Python 3 fixes
This commit is contained in:
parent
e0fcd99bcb
commit
5ace15e912
|
@ -207,8 +207,9 @@ def _load_python_alfcrypto():
|
||||||
|
|
||||||
def ctx_init(self, key):
|
def ctx_init(self, key):
|
||||||
ctx1 = 0x0CAFFE19E
|
ctx1 = 0x0CAFFE19E
|
||||||
for keyChar in key:
|
if isinstance(key, str):
|
||||||
keyByte = ord(keyChar)
|
key = key.encode('latin-1')
|
||||||
|
for keyByte in key:
|
||||||
ctx2 = ctx1
|
ctx2 = ctx1
|
||||||
ctx1 = ((((ctx1 >>2) * (ctx1 >>7))&0xFFFFFFFF) ^ (keyByte * keyByte * 0x0F902007)& 0xFFFFFFFF )
|
ctx1 = ((((ctx1 >>2) * (ctx1 >>7))&0xFFFFFFFF) ^ (keyByte * keyByte * 0x0F902007)& 0xFFFFFFFF )
|
||||||
self._ctx = [ctx1, ctx2]
|
self._ctx = [ctx1, ctx2]
|
||||||
|
@ -220,8 +221,9 @@ def _load_python_alfcrypto():
|
||||||
ctx1 = ctx[0]
|
ctx1 = ctx[0]
|
||||||
ctx2 = ctx[1]
|
ctx2 = ctx[1]
|
||||||
plainText = ""
|
plainText = ""
|
||||||
for dataChar in data:
|
if isinstance(data, str):
|
||||||
dataByte = ord(dataChar)
|
data = data.encode('latin-1')
|
||||||
|
for dataByte in data:
|
||||||
m = (dataByte ^ ((ctx1 >> 3) &0xFF) ^ ((ctx2<<3) & 0xFF)) &0xFF
|
m = (dataByte ^ ((ctx1 >> 3) &0xFF) ^ ((ctx2<<3) & 0xFF)) &0xFF
|
||||||
ctx2 = ctx1
|
ctx2 = ctx1
|
||||||
ctx1 = (((ctx1 >> 2) * (ctx1 >> 7)) &0xFFFFFFFF) ^((m * m * 0x0F902007) &0xFFFFFFFF)
|
ctx1 = (((ctx1 >> 2) * (ctx1 >> 7)) &0xFFFFFFFF) ^((m * m * 0x0F902007) &0xFFFFFFFF)
|
||||||
|
|
|
@ -473,8 +473,10 @@ class DocParser(object):
|
||||||
if (link > 0):
|
if (link > 0):
|
||||||
linktype = self.link_type[link-1]
|
linktype = self.link_type[link-1]
|
||||||
title = self.link_title[link-1]
|
title = self.link_title[link-1]
|
||||||
if (title == b"") or (parares.rfind(title.decode('utf-8')) < 0):
|
if isinstance(title, bytes):
|
||||||
title=parares[lstart:].encode('utf-8')
|
title = title.decode('utf-8')
|
||||||
|
if (title == "") or (parares.rfind(title) < 0):
|
||||||
|
title=parares[lstart:]
|
||||||
if linktype == 'external' :
|
if linktype == 'external' :
|
||||||
linkhref = self.link_href[link-1]
|
linkhref = self.link_href[link-1]
|
||||||
linkhtml = '<a href="%s">' % linkhref
|
linkhtml = '<a href="%s">' % linkhref
|
||||||
|
@ -485,9 +487,9 @@ class DocParser(object):
|
||||||
else :
|
else :
|
||||||
# just link to the current page
|
# just link to the current page
|
||||||
linkhtml = '<a href="#' + self.id + '">'
|
linkhtml = '<a href="#' + self.id + '">'
|
||||||
linkhtml += title.decode('utf-8')
|
linkhtml += title
|
||||||
linkhtml += '</a>'
|
linkhtml += '</a>'
|
||||||
pos = parares.rfind(title.decode('utf-8'))
|
pos = parares.rfind(title)
|
||||||
if pos >= 0:
|
if pos >= 0:
|
||||||
parares = parares[0:pos] + linkhtml + parares[pos+len(title):]
|
parares = parares[0:pos] + linkhtml + parares[pos+len(title):]
|
||||||
else :
|
else :
|
||||||
|
|
|
@ -175,6 +175,8 @@ def decryptRecord(data,PID):
|
||||||
# Try to decrypt a dkey record (contains the bookPID)
|
# Try to decrypt a dkey record (contains the bookPID)
|
||||||
def decryptDkeyRecord(data,PID):
|
def decryptDkeyRecord(data,PID):
|
||||||
record = decryptRecord(data,PID)
|
record = decryptRecord(data,PID)
|
||||||
|
if isinstance(record, str):
|
||||||
|
record = record.encode('latin-1')
|
||||||
fields = unpack('3sB8sB8s3s',record)
|
fields = unpack('3sB8sB8s3s',record)
|
||||||
if fields[0] != b'PID' or fields[5] != b'pid' :
|
if fields[0] != b'PID' or fields[5] != b'pid' :
|
||||||
raise DrmException("Didn't find PID magic numbers in record")
|
raise DrmException("Didn't find PID magic numbers in record")
|
||||||
|
@ -318,6 +320,8 @@ class TopazBook:
|
||||||
raise DrmException("Error: Attempt to decrypt without bookKey")
|
raise DrmException("Error: Attempt to decrypt without bookKey")
|
||||||
|
|
||||||
if compressed:
|
if compressed:
|
||||||
|
if isinstance(record, str):
|
||||||
|
record = bytes(record, 'latin-1')
|
||||||
record = zlib.decompress(record)
|
record = zlib.decompress(record)
|
||||||
|
|
||||||
return record
|
return record
|
||||||
|
@ -345,6 +349,8 @@ class TopazBook:
|
||||||
for pid in pidlst:
|
for pid in pidlst:
|
||||||
# use 8 digit pids here
|
# use 8 digit pids here
|
||||||
pid = pid[0:8]
|
pid = pid[0:8]
|
||||||
|
if isinstance(pid, str):
|
||||||
|
pid = pid.encode('latin-1')
|
||||||
print("Trying: {0}".format(pid))
|
print("Trying: {0}".format(pid))
|
||||||
bookKeys = []
|
bookKeys = []
|
||||||
data = keydata
|
data = keydata
|
||||||
|
@ -412,6 +418,8 @@ class TopazBook:
|
||||||
outputFile = os.path.join(destdir,fname)
|
outputFile = os.path.join(destdir,fname)
|
||||||
print(".", end=' ')
|
print(".", end=' ')
|
||||||
record = self.getBookPayloadRecord(name,index)
|
record = self.getBookPayloadRecord(name,index)
|
||||||
|
if isinstance(record, str):
|
||||||
|
record=bytes(record, 'latin-1')
|
||||||
if record != b'':
|
if record != b'':
|
||||||
open(outputFile, 'wb').write(record)
|
open(outputFile, 'wb').write(record)
|
||||||
print(" ")
|
print(" ")
|
||||||
|
|
Loading…
Reference in New Issue