if iswindows or isosx:
from calibre_plugins.dedrm.adobekey import adeptkeys
- defaultkeys = adeptkeys()
+ defaultkeys, defaultnames = adeptkeys()
else: # linux
from .wineutils import WineGetKeys
scriptpath = os.path.join(self.alfdir,"adobekey.py")
- defaultkeys = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
+ defaultkeys, defaultnames = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
self.default_key = defaultkeys[0]
except:
self.default_key = ""
newkeys = []
+ newnames = []
+ idx = 0
for keyvalue in defaultkeys:
if codecs.encode(keyvalue, 'hex').decode('ascii') not in dedrmprefs['adeptkeys'].values():
newkeys.append(keyvalue)
+ newnames.append(defaultnames[idx])
+ idx += 1
if len(newkeys) > 0:
try:
# Store the new successful key in the defaults
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
try:
- dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key',codecs.encode(keyvalue, 'hex').decode('ascii'))
+ dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key_uuid_' + newnames[i], codecs.encode(userkey, 'hex').decode('ascii'))
dedrmprefs.writeprefs()
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
except:
if iswindows or isosx:
from calibre_plugins.dedrm.adobekey import adeptkeys
- defaultkeys = adeptkeys()
+ defaultkeys, defaultnames = adeptkeys()
else: # linux
from .wineutils import WineGetKeys
scriptpath = os.path.join(self.alfdir,"adobekey.py")
- defaultkeys = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
+ defaultkeys, defaultnames = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
self.default_key = defaultkeys[0]
except:
self.default_key = ""
newkeys = []
+ newnames = []
+ idx = 0
for keyvalue in defaultkeys:
if codecs.encode(keyvalue,'hex') not in dedrmprefs['adeptkeys'].values():
newkeys.append(keyvalue)
+ newnames.append(defaultnames[idx])
+ idx += 1
if len(newkeys) > 0:
try:
# Store the new successful key in the defaults
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
try:
- dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key',codecs.encode(keyvalue,'hex'))
+ dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key_uuid_' + newnames[i], codecs.encode(userkey,'hex').decode('ascii'))
dedrmprefs.writeprefs()
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
except:
keykey = CryptUnprotectData(device, entropy)
userkey = None
keys = []
+ names = []
try:
plkroot = winreg.OpenKey(cuser, PRIVATE_LICENCE_KEY_PATH)
except WindowsError:
ktype = winreg.QueryValueEx(plkparent, None)[0]
if ktype != 'credentials':
continue
+ uuid_name = "Unknown"
for j in range(0, 16):
try:
plkkey = winreg.OpenKey(plkparent, "%04d" % (j,))
except WindowsError:
break
ktype = winreg.QueryValueEx(plkkey, None)[0]
+ if ktype == 'user':
+ uuid_name = winreg.QueryValueEx(plkkey, 'value')[0]
if ktype != 'privateLicenseKey':
continue
userkey = winreg.QueryValueEx(plkkey, 'value')[0]
aes = AES(keykey)
userkey = aes.decrypt(userkey)
userkey = userkey[26:-ord(userkey[-1:])]
- #print "found key:",userkey.encode('hex')
+ # print ("found " + uuid_name + " key: " + str(userkey))
keys.append(userkey)
+ names.append(uuid_name[9:])
if len(keys) == 0:
raise ADEPTError('Could not locate privateLicenseKey')
print("Found {0:d} keys".format(len(keys)))
- return keys
+ return keys, names
elif isosx:
tree = etree.parse(actpath)
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
expr = '//%s/%s' % (adept('credentials'), adept('privateLicenseKey'))
+ exprUUID = '//%s/%s' % (adept('credentials'), adept('user'))
userkey = tree.findtext(expr)
+ userUUID = "Unknown"
+ try:
+ userUUID = tree.findtext(exprUUID)
+ except:
+ pass
userkey = b64decode(userkey)
userkey = userkey[26:]
- return [userkey]
+ return [userkey], [userUUID[9:]]
else:
def adeptkeys():
raise ADEPTError("This script only supports Windows and Mac OS X.")
- return []
+ return [], []
# interface for Python DeDRM
def getkey(outpath):
- keys = adeptkeys()
+ keys, names = adeptkeys()
if len(keys) > 0:
if not os.path.isdir(outpath):
outfile = outpath
print("Saved a key to {0}".format(outfile))
else:
keycount = 0
+ name_index = 0
for key in keys:
while True:
keycount += 1
- outfile = os.path.join(outpath,"adobekey_{0:d}.der".format(keycount))
+ outfile = os.path.join(outpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
if not os.path.exists(outfile):
break
with open(outfile, 'wb') as keyfileout:
keyfileout.write(key)
print("Saved a key to {0}".format(outfile))
+ name_index += 1
return True
return False
# make sure the outpath is the
outpath = os.path.realpath(os.path.normpath(outpath))
- keys = adeptkeys()
+ keys, names = adeptkeys()
if len(keys) > 0:
if not os.path.isdir(outpath):
outfile = outpath
print("Saved a key to {0}".format(outfile))
else:
keycount = 0
+ name_index = 0
for key in keys:
while True:
keycount += 1
- outfile = os.path.join(outpath,"adobekey_{0:d}.der".format(keycount))
+ outfile = os.path.join(outpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
if not os.path.exists(outfile):
break
with open(outfile, 'wb') as keyfileout:
keyfileout.write(key)
print("Saved a key to {0}".format(outfile))
+ name_index += 1
else:
print("Could not retrieve Adobe Adept key.")
return 0
progpath, progname = os.path.split(argv[0])
success = False
try:
- keys = adeptkeys()
+ keys, names = adeptkeys()
+ print(keys)
+ print(names)
keycount = 0
+ name_index = 0
for key in keys:
while True:
keycount += 1
- outfile = os.path.join(progpath,"adobekey_{0:d}.der".format(keycount))
+ outfile = os.path.join(progpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
if not os.path.exists(outfile):
break
keyfileout.write(key)
success = True
tkinter.messagebox.showinfo(progname, "Key successfully retrieved to {0}".format(outfile))
+ name_index += 1
except ADEPTError as e:
tkinter.messagebox.showerror(progname, "Error: {0}".format(str(e)))
except Exception:
# try finding winekeys anyway, even if above code errored
winekeys = []
+ winekey_names = []
# get any files with extension in the output dir
files = [f for f in os.listdir(outdirpath) if f.endswith(extension)]
for filename in files:
else:
new_key_value = keyfile.read()
winekeys.append(new_key_value)
+ winekey_names.append(filename)
except:
print("{0} v{1}: Error loading file {2}".format(PLUGIN_NAME, PLUGIN_VERSION, filename))
traceback.print_exc()
os.remove(fpath)
print("{0} v{1}: Found and decrypted {2} {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(winekeys), "key file" if len(winekeys) == 1 else "key files"))
- return winekeys
+ return winekeys, winekey_names