mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2025-02-11 20:48:16 +01:00
Python 3 fix
This commit is contained in:
parent
4bab58e0fa
commit
bda647bd5b
2 changed files with 13 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -172,6 +172,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")
|
||||
|
@ -315,6 +317,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
|
||||
|
@ -346,7 +350,7 @@ class TopazBook:
|
|||
# use 8 digit pids here
|
||||
pid = pid[0:8]
|
||||
if isinstance(pid, str):
|
||||
pid = pid.encode('utf-8')
|
||||
pid = pid.encode('latin-1')
|
||||
print("Trying: {0}".format(pid))
|
||||
bookKeys = []
|
||||
data = keydata
|
||||
|
@ -417,6 +421,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(" ")
|
||||
|
|
Loading…
Add table
Reference in a new issue