Compare commits

...

6 Commits

Author SHA1 Message Date
Apprentice Harper 52bdbe95c9
Merge pull request #1522 from lkcv/patch-1
Add detection for Kobo directory location on Linux
3 years ago
Apprentice Harper 495dda3809
Merge pull request #1502 from ableeker/python3
Fix for broken book keys
3 years ago
Apprentice Harper 52e83922c0
Merge pull request #1499 from xxyzz/kfx
encode serialnum before returning it, close #1479
3 years ago
lkcv 6cbc5285cb
Update obok.py 3 years ago
Aldo Bleeker 33b9630ca5 Fix for broken book keys 3 years ago
xxyzz 9346f86f73
encode serialnum before returning it, close #1479 3 years ago

@ -415,12 +415,12 @@ def decryptBook(userkey, inpath, outpath):
return 1
bookkey = rsa.decrypt(codecs.decode(bookkey.encode('ascii'), 'base64'))
# Padded as per RSAES-PKCS1-v1_5
if len(bookkey) != 16:
if bookkey[-17] != '\x00' and bookkey[-17] != 0:
if len(bookkey) > 16:
if bookkey[-17] == '\x00' or bookkey[-17] == 0:
bookkey = bookkey[-16:]
else:
print("Could not decrypt {0:s}. Wrong key".format(os.path.basename(inpath)))
return 2
else:
bookkey = bookkey[-16:]
encryption = inf.read('META-INF/encryption.xml')
decryptor = Decryptor(bookkey, encryption)
kwds = dict(compression=ZIP_DEFLATED, allowZip64=False)

@ -1599,11 +1599,10 @@ class PDFDocument(object):
bookkey = rsa.decrypt(bookkey)
#if bookkey[0] != 2:
# raise ADEPTError('error decrypting book session key')
try:
index = bookkey.index(b'\0') + 1
bookkey = bookkey[index:]
except ValueError:
pass
if len(bookkey) > 16:
if bookkey[-17] == '\x00' or bookkey[-17] == 0:
bookkey = bookkey[-16:]
length = 16
ebx_V = int_value(param.get('V', 4))
ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6))
# added because of improper booktype / decryption book session key errors

@ -174,14 +174,14 @@ def pidFromSerial(s, l):
# Parse the EXTH header records and use the Kindle serial number to calculate the book pid.
def getKindlePids(rec209, token, serialnum):
if isinstance(serialnum,str):
serialnum = serialnum.encode('utf-8')
if rec209 is None:
return [serialnum]
pids=[]
if isinstance(serialnum,str):
serialnum = serialnum.encode('utf-8')
# Compute book PID
pidHash = SHA1(serialnum+rec209+token)
bookPID = encodePID(pidHash)

@ -1,6 +1,9 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Version 4.1.0 February 2021
# Add detection for Kobo directory location on Linux
# Version 4.0.0 September 2020
# Python 3.0
#
@ -365,9 +368,33 @@ class KoboLibrary(object):
self.kobodir = os.path.join(self.kobodir, "Kobo", "Kobo Desktop Edition")
elif sys.platform.startswith('darwin'):
self.kobodir = os.path.join(os.environ['HOME'], "Library", "Application Support", "Kobo", "Kobo Desktop Edition")
#elif linux_path != None:
# Probably Linux, let's get the wine prefix and path to Kobo.
# self.kobodir = os.path.join(linux_path, "Local Settings", "Application Data", "Kobo", "Kobo Desktop Edition")
elif sys.platform.startswith('linux'):
#sets ~/.config/calibre as the location to store the kobodir location info file and creates this directory if necessary
kobodir_cache_dir = os.path.join(os.environ['HOME'], ".config", "calibre")
if not os.path.isdir(kobodir_cache_dir):
os.mkdir(kobodir_cache_dir)
#appends the name of the file we're storing the kobodir location info to the above path
kobodir_cache_file = str(kobodir_cache_dir) + "/" + "kobo location"
"""if the above file does not exist, recursively searches from the root
of the filesystem until kobodir is found and stores the location of kobodir
in that file so this loop can be skipped in the future"""
original_stdout = sys.stdout
if not os.path.isfile(kobodir_cache_file):
for root, dirs, files in os.walk('/'):
for file in files:
if file == 'Kobo.sqlite':
kobo_linux_path = str(root)
with open(kobodir_cache_file, 'w') as f:
sys.stdout = f
print(kobo_linux_path, end='')
sys.stdout = original_stdout
f = open(kobodir_cache_file, 'r' )
self.kobodir = f.read()
# desktop versions use Kobo.sqlite
kobodb = os.path.join(self.kobodir, "Kobo.sqlite")
# check for existence of file

Loading…
Cancel
Save