|
|
@ -124,7 +124,11 @@ def getSizeOfTrailingDataEntries(ptr, size, flags):
|
|
|
|
if size <= 0:
|
|
|
|
if size <= 0:
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
v = ptr[size-1]
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
|
|
|
|
v = ord(ptr[size-1])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
v = ptr[size-1]
|
|
|
|
|
|
|
|
|
|
|
|
result |= (v & 0x7F) << bitpos
|
|
|
|
result |= (v & 0x7F) << bitpos
|
|
|
|
bitpos += 7
|
|
|
|
bitpos += 7
|
|
|
|
size -= 1
|
|
|
|
size -= 1
|
|
|
@ -140,7 +144,10 @@ def getSizeOfTrailingDataEntries(ptr, size, flags):
|
|
|
|
# if multibyte data is included in the encryped data, we'll
|
|
|
|
# if multibyte data is included in the encryped data, we'll
|
|
|
|
# have already cleared this flag.
|
|
|
|
# have already cleared this flag.
|
|
|
|
if flags & 1:
|
|
|
|
if flags & 1:
|
|
|
|
num += (ptr[size - num - 1] & 0x3) + 1
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
|
|
|
|
num += (ord(ptr[size - num - 1]) & 0x3) + 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
num += (ptr[size - num - 1] & 0x3) + 1
|
|
|
|
return num
|
|
|
|
return num
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -299,7 +306,10 @@ class MobiBook:
|
|
|
|
for pid in pidlist:
|
|
|
|
for pid in pidlist:
|
|
|
|
bigpid = pid.encode('utf-8').ljust(16,b'\0')
|
|
|
|
bigpid = pid.encode('utf-8').ljust(16,b'\0')
|
|
|
|
temp_key = PC1(keyvec1, bigpid, False)
|
|
|
|
temp_key = PC1(keyvec1, bigpid, False)
|
|
|
|
temp_key_sum = sum(temp_key) & 0xff
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
|
|
|
|
temp_key_sum = sum(map(ord,temp_key)) & 0xff
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
temp_key_sum = sum(temp_key) & 0xff
|
|
|
|
found_key = None
|
|
|
|
found_key = None
|
|
|
|
for i in range(count):
|
|
|
|
for i in range(count):
|
|
|
|
verification, size, type, cksum, cookie = struct.unpack('>LLLBxxx32s', data[i*0x30:i*0x30+0x30])
|
|
|
|
verification, size, type, cksum, cookie = struct.unpack('>LLLBxxx32s', data[i*0x30:i*0x30+0x30])
|
|
|
@ -315,7 +325,11 @@ class MobiBook:
|
|
|
|
# Then try the default encoding that doesn't require a PID
|
|
|
|
# Then try the default encoding that doesn't require a PID
|
|
|
|
pid = '00000000'
|
|
|
|
pid = '00000000'
|
|
|
|
temp_key = keyvec1
|
|
|
|
temp_key = keyvec1
|
|
|
|
temp_key_sum = sum(temp_key) & 0xff
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
|
|
|
|
temp_key_sum = sum(map(ord,temp_key)) & 0xff
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
temp_key_sum = sum(temp_key) & 0xff
|
|
|
|
|
|
|
|
|
|
|
|
for i in range(count):
|
|
|
|
for i in range(count):
|
|
|
|
verification, size, type, cksum, cookie = struct.unpack('>LLLBxxx32s', data[i*0x30:i*0x30+0x30])
|
|
|
|
verification, size, type, cksum, cookie = struct.unpack('>LLLBxxx32s', data[i*0x30:i*0x30+0x30])
|
|
|
|
if cksum == temp_key_sum:
|
|
|
|
if cksum == temp_key_sum:
|
|
|
|