Fixes for the plugin and Android keys (help still needs adding)

This commit is contained in:
Apprentice Harper 2015-03-18 19:12:01 +00:00 committed by Apprentice Alf
parent 39c9d57b15
commit 6b2672ff7c
5 changed files with 43 additions and 30 deletions

View File

@ -479,7 +479,7 @@ class DeDRM(FileTypePlugin):
dedrmprefs = prefs.DeDRM_Prefs() dedrmprefs = prefs.DeDRM_Prefs()
pids = dedrmprefs['pids'] pids = dedrmprefs['pids']
serials = dedrmprefs['serials'] serials = dedrmprefs['serials']
serials.append(dedrmprefs['androidserials']) serials.extend(dedrmprefs['androidserials'])
kindleDatabases = dedrmprefs['kindlekeys'].items() kindleDatabases = dedrmprefs['kindlekeys'].items()
try: try:

View File

@ -256,14 +256,14 @@ def get_serials(path=STORAGE):
tar = tarfile.open(fileobj=output) tar = tarfile.open(fileobj=output)
for member in tar.getmembers(): for member in tar.getmembers():
if member.name.strip().endswith(STORAGE1): if member.name.strip().endswith(STORAGE1):
write = tempfile.NamedTemporaryFile(mode='w', delete=False) write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
write.write(tar.extractfile(member).read()) write.write(tar.extractfile(member).read())
write.close() write.close()
write_path = os.path.abspath(write.name) write_path = os.path.abspath(write.name)
serials.extend(get_serials1(write_path)) serials.extend(get_serials1(write_path))
os.remove(write_path) os.remove(write_path)
elif member.name.strip().endswith(STORAGE2): elif member.name.strip().endswith(STORAGE2):
write = tempfile.NamedTemporaryFile(mode='w', delete=False) write = tempfile.NamedTemporaryFile(mode='wb', delete=False)
write.write(tar.extractfile(member).read()) write.write(tar.extractfile(member).read())
write.close() write.close()
write_path = os.path.abspath(write.name) write_path = os.path.abspath(write.name)

View File

@ -34,6 +34,7 @@ from calibre.constants import iswindows, isosx
from calibre_plugins.dedrm.__init__ import PLUGIN_NAME, PLUGIN_VERSION from calibre_plugins.dedrm.__init__ import PLUGIN_NAME, PLUGIN_VERSION
from calibre_plugins.dedrm.__init__ import RESOURCE_NAME as help_file_name from calibre_plugins.dedrm.__init__ import RESOURCE_NAME as help_file_name
from calibre_plugins.dedrm.utilities import uStrCmp from calibre_plugins.dedrm.utilities import uStrCmp
from calibre_plugins.dedrm.androidkindlekey import get_serials
import calibre_plugins.dedrm.prefs as prefs import calibre_plugins.dedrm.prefs as prefs
@ -199,6 +200,7 @@ class ManageKeysDialog(QDialog):
self.import_key = (keyfile_ext != u"") self.import_key = (keyfile_ext != u"")
self.binary_file = (keyfile_ext == u"der") self.binary_file = (keyfile_ext == u"der")
self.json_file = (keyfile_ext == u"k4i") self.json_file = (keyfile_ext == u"k4i")
self.android_file = (keyfile_ext == u"ab")
self.wineprefix = wineprefix self.wineprefix = wineprefix
self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name)) self.setWindowTitle("{0} {1}: Manage {2}s".format(PLUGIN_NAME, PLUGIN_VERSION, self.key_type_name))
@ -381,31 +383,42 @@ class ManageKeysDialog(QDialog):
for filename in files: for filename in files:
fpath = os.path.join(config_dir, filename) fpath = os.path.join(config_dir, filename)
filename = os.path.basename(filename) filename = os.path.basename(filename)
new_key_name = os.path.splitext(os.path.basename(filename))[0] if type(self.plugin_keys) != dict:
with open(fpath,'rb') as keyfile: # must be the new Kindle for Android section
new_key_value = keyfile.read() print u"Getting keys from "+fpath
if self.binary_file: new_keys = get_serials(fpath)
new_key_value = new_key_value.encode('hex') for key in new_keys:
elif self.json_file: if key in self.plugin_keys:
new_key_value = json.loads(new_key_value) skipped += 1
match = False else:
for key in self.plugin_keys.keys(): counter += 1
if uStrCmp(new_key_name, key, True): self.plugin_keys.append(key)
skipped += 1 else:
msg = u"A key with the name <strong>{0}</strong> already exists!\nSkipping key file <strong>{1}</strong>.\nRename the existing key and import again".format(new_key_name,filename) new_key_name = os.path.splitext(os.path.basename(filename))[0]
inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), with open(fpath,'rb') as keyfile:
_(msg), show_copy_button=False, show=True) new_key_value = keyfile.read()
match = True if self.binary_file:
break new_key_value = new_key_value.encode('hex')
if not match: elif self.json_file:
if new_key_value in self.plugin_keys.values(): new_key_value = json.loads(new_key_value)
old_key_name = [name for name, value in self.plugin_keys.iteritems() if value == new_key_value][0] match = False
skipped += 1 for key in self.plugin_keys.keys():
info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION), if uStrCmp(new_key_name, key, True):
u"The key in file {0} is the same as the existing key <strong>{1}</strong> and has been skipped.".format(filename,old_key_name), show_copy_button=False, show=True) skipped += 1
else: msg = u"A key with the name <strong>{0}</strong> already exists!\nSkipping key file <strong>{1}</strong>.\nRename the existing key and import again".format(new_key_name,filename)
counter += 1 inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
self.plugin_keys[new_key_name] = new_key_value _(msg), show_copy_button=False, show=True)
match = True
break
if not match:
if new_key_value in self.plugin_keys.values():
old_key_name = [name for name, value in self.plugin_keys.iteritems() if value == new_key_value][0]
skipped += 1
info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
u"The key in file {0} is the same as the existing key <strong>{1}</strong> and has been skipped.".format(filename,old_key_name), show_copy_button=False, show=True)
else:
counter += 1
self.plugin_keys[new_key_name] = new_key_value
msg = u"" msg = u""
if counter+skipped > 1: if counter+skipped > 1:

View File

@ -91,6 +91,6 @@ These instructions have been tested with Wine 1.4 on Ubuntu.
Instructions for getting Kindle for PC and Adobe Digital Editions default decryption keys Instructions for getting Kindle for PC and Adobe Digital Editions default decryption keys
----------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------
If everything has been installed in wine as above, the keys will be retrieve automatically. If everything has been installed in wine as above, the keys will be retrieved automatically.
If you have a more complex wine installation, you may enter the appropriate WINEPREFIX in the configuration dialogs for Kindle for PC and Adobe Digital Editions. You can also test that you have entered the WINEPREFIX correctly by trying to add the default keys to the preferences by clicking on the green plus button in the configuration dialogs. If you have a more complex wine installation, you may enter the appropriate WINEPREFIX in the configuration dialogs for Kindle for PC and Adobe Digital Editions. You can also test that you have entered the WINEPREFIX correctly by trying to add the default keys to the preferences by clicking on the green plus button in the configuration dialogs.