mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2026-03-20 04:58:56 +00:00
Compare commits
8 Commits
ed0a34cbff
...
d2808d83d9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2808d83d9 | ||
|
|
808dc7d29a | ||
|
|
2cd2792306 | ||
|
|
2e53d70e88 | ||
|
|
05fff5217b | ||
|
|
34c4c067e8 | ||
|
|
195ea69537 | ||
|
|
ad33aea18d |
@@ -255,7 +255,7 @@ class EreaderProcessor(object):
|
||||
encrypted_key = r[172:172+8]
|
||||
encrypted_key_sha = r[56:56+20]
|
||||
self.content_key = des.decrypt(encrypted_key)
|
||||
if sha1(self.content_key).digest() != encrypted_key_sha:
|
||||
if hashlib.sha1(self.content_key).digest() != encrypted_key_sha:
|
||||
raise ValueError('Incorrect Name and/or Credit Card')
|
||||
|
||||
def getNumImages(self):
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""ion.py: Decrypt Kindle KFX files.
|
||||
|
||||
# ion.py
|
||||
# Copyright © 2013-2020 Apprentice Harper et al.
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__version__ = '3.0'
|
||||
|
||||
# Revision history:
|
||||
# Pascal implementation by lulzkabulz.
|
||||
# BinaryIon.pas + DrmIon.pas + IonSymbols.pas
|
||||
# 1.0 - Python translation by apprenticenaomi.
|
||||
# 1.1 - DeDRM integration by anon.
|
||||
# 1.2 - Added pylzma import fallback
|
||||
# 1.3 - Fixed lzma support for calibre 4.6+
|
||||
# 2.0 - VoucherEnvelope v2/v3 support by apprenticesakuya.
|
||||
# 3.0 - Added Python 3 compatibility for calibre 5.0
|
||||
Revision history:
|
||||
Pascal implementation by lulzkabulz.
|
||||
BinaryIon.pas + DrmIon.pas + IonSymbols.pas
|
||||
1.0 - Python translation by apprenticenaomi.
|
||||
1.1 - DeDRM integration by anon.
|
||||
1.2 - Added pylzma import fallback
|
||||
1.3 - Fixed lzma support for calibre 4.6+
|
||||
2.0 - VoucherEnvelope v2/v3 support by apprenticesakuya.
|
||||
3.0 - Added Python 3 compatibility for calibre 5.0
|
||||
|
||||
Copyright © 2013-2020 Apprentice Harper et al.
|
||||
"""
|
||||
Decrypt Kindle KFX files.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import collections
|
||||
import hashlib
|
||||
@@ -30,6 +24,9 @@ import struct
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__version__ = '3.0'
|
||||
|
||||
#@@CALIBRE_COMPAT_CODE@@
|
||||
|
||||
|
||||
@@ -1349,7 +1346,7 @@ class DrmIonVoucher(object):
|
||||
process_V4648(shared), process_V5683(shared)]
|
||||
|
||||
decrypted=False
|
||||
ex=None
|
||||
lastexception: Exception | None = None
|
||||
for sharedsecret in sharedsecrets:
|
||||
key = hmac.new(sharedsecret, b"PIDv3", digestmod=hashlib.sha256).digest()
|
||||
aes = AES.new(key[:32], AES.MODE_CBC, self.cipheriv[:16])
|
||||
@@ -1366,9 +1363,10 @@ class DrmIonVoucher(object):
|
||||
print("Decryption succeeded")
|
||||
break
|
||||
except Exception as ex:
|
||||
lastexception = ex
|
||||
print("Decryption failed, trying next fallback ")
|
||||
if not decrypted:
|
||||
raise ex
|
||||
raise lastexception
|
||||
|
||||
self.drmkey.stepin()
|
||||
while self.drmkey.hasnext():
|
||||
|
||||
@@ -374,7 +374,11 @@ class InterfacePluginAction(InterfaceAction):
|
||||
result['success'] = False
|
||||
result['fileobj'] = None
|
||||
|
||||
zin = zipfile.ZipFile(book.filename, 'r')
|
||||
try:
|
||||
zin = zipfile.ZipFile(book.filename, 'r')
|
||||
except FileNotFoundError:
|
||||
print (_('{0} - File "{1}" not found. Make sure the eBook has been properly downloaded in the Kobo app.').format(PLUGIN_NAME, book.filename))
|
||||
return result
|
||||
#print ('Kobo library filename: {0}'.format(book.filename))
|
||||
for userkey in self.userkeys:
|
||||
print (_('Trying key: '), codecs.encode(userkey, 'hex'))
|
||||
|
||||
@@ -327,36 +327,50 @@ class KoboLibrary(object):
|
||||
elif sys.platform.startswith('darwin'):
|
||||
self.kobodir = os.path.join(os.environ['HOME'], "Library", "Application Support", "Kobo", "Kobo Desktop Edition")
|
||||
elif sys.platform.startswith('linux'):
|
||||
# Since on Linux, you have to run Kobo Desktop within Wine,
|
||||
# there is no guarantee where Kobo.sqlite (and the rest of
|
||||
# the kobo directory) might be.
|
||||
#
|
||||
# It should also be noted that Kobo Desktop will store all
|
||||
# of it files in the current directory where you run it,
|
||||
# meaning that a user might accidentally create several
|
||||
# Kobo.sqlite files which are all separate and then be
|
||||
# confused why Obok can't find any of the new books. Sadly
|
||||
# there isn't a trivial way to deal with this.
|
||||
|
||||
#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")
|
||||
# We cache the kobodir we find in ~/.config/calibre.
|
||||
kobodir_cache_dir = os.path.join(os.environ['HOME'], ".config", "calibre", "plugins", "obok")
|
||||
if not os.path.isdir(kobodir_cache_dir):
|
||||
os.mkdir(kobodir_cache_dir)
|
||||
kobodir_cache_file = os.path.join(kobodir_cache_dir, "kobo-location")
|
||||
|
||||
#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"
|
||||
try:
|
||||
# If the cached version exists and the path does really
|
||||
# contain Kobo.sqlite, use that.
|
||||
with open(kobodir_cache_file, "r") as f:
|
||||
cached_kobodir = f.read().strip()
|
||||
assert os.path.isfile(os.path.join(cached_kobodir, "Kobo.sqlite"))
|
||||
self.kobodir = cached_kobodir
|
||||
except (AssertionError, FileNotFoundError):
|
||||
# If there was no cached version, search the entire
|
||||
# filesystem tree for a directory containing
|
||||
# "Kobo.sqlite".
|
||||
#
|
||||
# We first search $HOME to avoid picking another user's
|
||||
# Kobo.sqlite file, but then fallback to / if there was
|
||||
# nothing in $HOME.
|
||||
for candidate_root in (os.environ["HOME"], "/"):
|
||||
for root, _, files in os.walk(candidate_root):
|
||||
if "Kobo.sqlite" in files:
|
||||
with open(kobodir_cache_file, "w") as f:
|
||||
f.write("%s/\n" % (root,))
|
||||
self.kobodir = root
|
||||
break
|
||||
|
||||
"""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
|
||||
# Desktop versions use Kobo.sqlite.
|
||||
kobodb = os.path.join(self.kobodir, "Kobo.sqlite")
|
||||
# check for existence of file
|
||||
if (not(os.path.isfile(kobodb))):
|
||||
if not os.path.isfile(kobodb):
|
||||
# give up here, we haven't found anything useful
|
||||
self.kobodir = u""
|
||||
kobodb = u""
|
||||
@@ -449,9 +463,15 @@ class KoboLibrary(object):
|
||||
for m in matches:
|
||||
# print "m:{0}".format(m[0])
|
||||
macaddrs.append(m[0].upper())
|
||||
elif sys.platform.startswith('linux'):
|
||||
for interface in os.listdir('/sys/class/net'):
|
||||
with open('/sys/class/net/' + interface + '/address', 'r') as f:
|
||||
mac = f.read().strip().upper()
|
||||
# some interfaces, like Tailscale's VPN interface, do not have a MAC address
|
||||
if mac != '':
|
||||
macaddrs.append(mac)
|
||||
else:
|
||||
# probably linux
|
||||
|
||||
# final fallback
|
||||
# let's try ip
|
||||
c = re.compile('\s(' + '[0-9a-f]{2}:' * 5 + '[0-9a-f]{2})(\s|$)', re.IGNORECASE)
|
||||
for line in os.popen('ip -br link'):
|
||||
|
||||
Reference in New Issue
Block a user