mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2024-11-05 13:36:10 +06:00
Add UUID to adobekey DER file names
This commit is contained in:
parent
14947cd10c
commit
066e613cee
|
@ -355,12 +355,12 @@ class DeDRM(FileTypePlugin):
|
||||||
if iswindows or isosx:
|
if iswindows or isosx:
|
||||||
from calibre_plugins.dedrm.adobekey import adeptkeys
|
from calibre_plugins.dedrm.adobekey import adeptkeys
|
||||||
|
|
||||||
defaultkeys = adeptkeys()
|
defaultkeys, defaultnames = adeptkeys()
|
||||||
else: # linux
|
else: # linux
|
||||||
from .wineutils import WineGetKeys
|
from .wineutils import WineGetKeys
|
||||||
|
|
||||||
scriptpath = os.path.join(self.alfdir,"adobekey.py")
|
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]
|
self.default_key = defaultkeys[0]
|
||||||
except:
|
except:
|
||||||
|
@ -369,9 +369,13 @@ class DeDRM(FileTypePlugin):
|
||||||
self.default_key = ""
|
self.default_key = ""
|
||||||
|
|
||||||
newkeys = []
|
newkeys = []
|
||||||
|
newnames = []
|
||||||
|
idx = 0
|
||||||
for keyvalue in defaultkeys:
|
for keyvalue in defaultkeys:
|
||||||
if codecs.encode(keyvalue, 'hex').decode('ascii') not in dedrmprefs['adeptkeys'].values():
|
if codecs.encode(keyvalue, 'hex').decode('ascii') not in dedrmprefs['adeptkeys'].values():
|
||||||
newkeys.append(keyvalue)
|
newkeys.append(keyvalue)
|
||||||
|
newnames.append(defaultnames[idx])
|
||||||
|
idx += 1
|
||||||
|
|
||||||
if len(newkeys) > 0:
|
if len(newkeys) > 0:
|
||||||
try:
|
try:
|
||||||
|
@ -394,7 +398,7 @@ class DeDRM(FileTypePlugin):
|
||||||
# Store the new successful key in the defaults
|
# Store the new successful key in the defaults
|
||||||
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
|
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
|
||||||
try:
|
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()
|
dedrmprefs.writeprefs()
|
||||||
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
|
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
|
||||||
except:
|
except:
|
||||||
|
@ -458,12 +462,12 @@ class DeDRM(FileTypePlugin):
|
||||||
if iswindows or isosx:
|
if iswindows or isosx:
|
||||||
from calibre_plugins.dedrm.adobekey import adeptkeys
|
from calibre_plugins.dedrm.adobekey import adeptkeys
|
||||||
|
|
||||||
defaultkeys = adeptkeys()
|
defaultkeys, defaultnames = adeptkeys()
|
||||||
else: # linux
|
else: # linux
|
||||||
from .wineutils import WineGetKeys
|
from .wineutils import WineGetKeys
|
||||||
|
|
||||||
scriptpath = os.path.join(self.alfdir,"adobekey.py")
|
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]
|
self.default_key = defaultkeys[0]
|
||||||
except:
|
except:
|
||||||
|
@ -472,9 +476,13 @@ class DeDRM(FileTypePlugin):
|
||||||
self.default_key = ""
|
self.default_key = ""
|
||||||
|
|
||||||
newkeys = []
|
newkeys = []
|
||||||
|
newnames = []
|
||||||
|
idx = 0
|
||||||
for keyvalue in defaultkeys:
|
for keyvalue in defaultkeys:
|
||||||
if codecs.encode(keyvalue,'hex') not in dedrmprefs['adeptkeys'].values():
|
if codecs.encode(keyvalue,'hex') not in dedrmprefs['adeptkeys'].values():
|
||||||
newkeys.append(keyvalue)
|
newkeys.append(keyvalue)
|
||||||
|
newnames.append(defaultnames[idx])
|
||||||
|
idx += 1
|
||||||
|
|
||||||
if len(newkeys) > 0:
|
if len(newkeys) > 0:
|
||||||
try:
|
try:
|
||||||
|
@ -497,7 +505,7 @@ class DeDRM(FileTypePlugin):
|
||||||
# Store the new successful key in the defaults
|
# Store the new successful key in the defaults
|
||||||
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
|
print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
|
||||||
try:
|
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()
|
dedrmprefs.writeprefs()
|
||||||
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
|
print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -362,6 +362,7 @@ if iswindows:
|
||||||
keykey = CryptUnprotectData(device, entropy)
|
keykey = CryptUnprotectData(device, entropy)
|
||||||
userkey = None
|
userkey = None
|
||||||
keys = []
|
keys = []
|
||||||
|
names = []
|
||||||
try:
|
try:
|
||||||
plkroot = winreg.OpenKey(cuser, PRIVATE_LICENCE_KEY_PATH)
|
plkroot = winreg.OpenKey(cuser, PRIVATE_LICENCE_KEY_PATH)
|
||||||
except WindowsError:
|
except WindowsError:
|
||||||
|
@ -374,12 +375,15 @@ if iswindows:
|
||||||
ktype = winreg.QueryValueEx(plkparent, None)[0]
|
ktype = winreg.QueryValueEx(plkparent, None)[0]
|
||||||
if ktype != 'credentials':
|
if ktype != 'credentials':
|
||||||
continue
|
continue
|
||||||
|
uuid_name = "Unknown"
|
||||||
for j in range(0, 16):
|
for j in range(0, 16):
|
||||||
try:
|
try:
|
||||||
plkkey = winreg.OpenKey(plkparent, "%04d" % (j,))
|
plkkey = winreg.OpenKey(plkparent, "%04d" % (j,))
|
||||||
except WindowsError:
|
except WindowsError:
|
||||||
break
|
break
|
||||||
ktype = winreg.QueryValueEx(plkkey, None)[0]
|
ktype = winreg.QueryValueEx(plkkey, None)[0]
|
||||||
|
if ktype == 'user':
|
||||||
|
uuid_name = winreg.QueryValueEx(plkkey, 'value')[0]
|
||||||
if ktype != 'privateLicenseKey':
|
if ktype != 'privateLicenseKey':
|
||||||
continue
|
continue
|
||||||
userkey = winreg.QueryValueEx(plkkey, 'value')[0]
|
userkey = winreg.QueryValueEx(plkkey, 'value')[0]
|
||||||
|
@ -387,12 +391,13 @@ if iswindows:
|
||||||
aes = AES(keykey)
|
aes = AES(keykey)
|
||||||
userkey = aes.decrypt(userkey)
|
userkey = aes.decrypt(userkey)
|
||||||
userkey = userkey[26:-ord(userkey[-1:])]
|
userkey = userkey[26:-ord(userkey[-1:])]
|
||||||
#print "found key:",userkey.encode('hex')
|
# print ("found " + uuid_name + " key: " + str(userkey))
|
||||||
keys.append(userkey)
|
keys.append(userkey)
|
||||||
|
names.append(uuid_name[9:])
|
||||||
if len(keys) == 0:
|
if len(keys) == 0:
|
||||||
raise ADEPTError('Could not locate privateLicenseKey')
|
raise ADEPTError('Could not locate privateLicenseKey')
|
||||||
print("Found {0:d} keys".format(len(keys)))
|
print("Found {0:d} keys".format(len(keys)))
|
||||||
return keys
|
return keys, names
|
||||||
|
|
||||||
|
|
||||||
elif isosx:
|
elif isosx:
|
||||||
|
@ -431,19 +436,25 @@ elif isosx:
|
||||||
tree = etree.parse(actpath)
|
tree = etree.parse(actpath)
|
||||||
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
|
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
|
||||||
expr = '//%s/%s' % (adept('credentials'), adept('privateLicenseKey'))
|
expr = '//%s/%s' % (adept('credentials'), adept('privateLicenseKey'))
|
||||||
|
exprUUID = '//%s/%s' % (adept('credentials'), adept('user'))
|
||||||
userkey = tree.findtext(expr)
|
userkey = tree.findtext(expr)
|
||||||
|
userUUID = "Unknown"
|
||||||
|
try:
|
||||||
|
userUUID = tree.findtext(exprUUID)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
userkey = b64decode(userkey)
|
userkey = b64decode(userkey)
|
||||||
userkey = userkey[26:]
|
userkey = userkey[26:]
|
||||||
return [userkey]
|
return [userkey], [userUUID[9:]]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
def adeptkeys():
|
def adeptkeys():
|
||||||
raise ADEPTError("This script only supports Windows and Mac OS X.")
|
raise ADEPTError("This script only supports Windows and Mac OS X.")
|
||||||
return []
|
return [], []
|
||||||
|
|
||||||
# interface for Python DeDRM
|
# interface for Python DeDRM
|
||||||
def getkey(outpath):
|
def getkey(outpath):
|
||||||
keys = adeptkeys()
|
keys, names = adeptkeys()
|
||||||
if len(keys) > 0:
|
if len(keys) > 0:
|
||||||
if not os.path.isdir(outpath):
|
if not os.path.isdir(outpath):
|
||||||
outfile = outpath
|
outfile = outpath
|
||||||
|
@ -452,15 +463,17 @@ def getkey(outpath):
|
||||||
print("Saved a key to {0}".format(outfile))
|
print("Saved a key to {0}".format(outfile))
|
||||||
else:
|
else:
|
||||||
keycount = 0
|
keycount = 0
|
||||||
|
name_index = 0
|
||||||
for key in keys:
|
for key in keys:
|
||||||
while True:
|
while True:
|
||||||
keycount += 1
|
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):
|
if not os.path.exists(outfile):
|
||||||
break
|
break
|
||||||
with open(outfile, 'wb') as keyfileout:
|
with open(outfile, 'wb') as keyfileout:
|
||||||
keyfileout.write(key)
|
keyfileout.write(key)
|
||||||
print("Saved a key to {0}".format(outfile))
|
print("Saved a key to {0}".format(outfile))
|
||||||
|
name_index += 1
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -506,7 +519,7 @@ def cli_main():
|
||||||
# make sure the outpath is the
|
# make sure the outpath is the
|
||||||
outpath = os.path.realpath(os.path.normpath(outpath))
|
outpath = os.path.realpath(os.path.normpath(outpath))
|
||||||
|
|
||||||
keys = adeptkeys()
|
keys, names = adeptkeys()
|
||||||
if len(keys) > 0:
|
if len(keys) > 0:
|
||||||
if not os.path.isdir(outpath):
|
if not os.path.isdir(outpath):
|
||||||
outfile = outpath
|
outfile = outpath
|
||||||
|
@ -515,15 +528,17 @@ def cli_main():
|
||||||
print("Saved a key to {0}".format(outfile))
|
print("Saved a key to {0}".format(outfile))
|
||||||
else:
|
else:
|
||||||
keycount = 0
|
keycount = 0
|
||||||
|
name_index = 0
|
||||||
for key in keys:
|
for key in keys:
|
||||||
while True:
|
while True:
|
||||||
keycount += 1
|
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):
|
if not os.path.exists(outfile):
|
||||||
break
|
break
|
||||||
with open(outfile, 'wb') as keyfileout:
|
with open(outfile, 'wb') as keyfileout:
|
||||||
keyfileout.write(key)
|
keyfileout.write(key)
|
||||||
print("Saved a key to {0}".format(outfile))
|
print("Saved a key to {0}".format(outfile))
|
||||||
|
name_index += 1
|
||||||
else:
|
else:
|
||||||
print("Could not retrieve Adobe Adept key.")
|
print("Could not retrieve Adobe Adept key.")
|
||||||
return 0
|
return 0
|
||||||
|
@ -556,12 +571,15 @@ def gui_main():
|
||||||
progpath, progname = os.path.split(argv[0])
|
progpath, progname = os.path.split(argv[0])
|
||||||
success = False
|
success = False
|
||||||
try:
|
try:
|
||||||
keys = adeptkeys()
|
keys, names = adeptkeys()
|
||||||
|
print(keys)
|
||||||
|
print(names)
|
||||||
keycount = 0
|
keycount = 0
|
||||||
|
name_index = 0
|
||||||
for key in keys:
|
for key in keys:
|
||||||
while True:
|
while True:
|
||||||
keycount += 1
|
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):
|
if not os.path.exists(outfile):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -569,6 +587,7 @@ def gui_main():
|
||||||
keyfileout.write(key)
|
keyfileout.write(key)
|
||||||
success = True
|
success = True
|
||||||
tkinter.messagebox.showinfo(progname, "Key successfully retrieved to {0}".format(outfile))
|
tkinter.messagebox.showinfo(progname, "Key successfully retrieved to {0}".format(outfile))
|
||||||
|
name_index += 1
|
||||||
except ADEPTError as e:
|
except ADEPTError as e:
|
||||||
tkinter.messagebox.showerror(progname, "Error: {0}".format(str(e)))
|
tkinter.messagebox.showerror(progname, "Error: {0}".format(str(e)))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -93,6 +93,7 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
|
||||||
|
|
||||||
# try finding winekeys anyway, even if above code errored
|
# try finding winekeys anyway, even if above code errored
|
||||||
winekeys = []
|
winekeys = []
|
||||||
|
winekey_names = []
|
||||||
# get any files with extension in the output dir
|
# get any files with extension in the output dir
|
||||||
files = [f for f in os.listdir(outdirpath) if f.endswith(extension)]
|
files = [f for f in os.listdir(outdirpath) if f.endswith(extension)]
|
||||||
for filename in files:
|
for filename in files:
|
||||||
|
@ -104,9 +105,10 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
|
||||||
else:
|
else:
|
||||||
new_key_value = keyfile.read()
|
new_key_value = keyfile.read()
|
||||||
winekeys.append(new_key_value)
|
winekeys.append(new_key_value)
|
||||||
|
winekey_names.append(filename)
|
||||||
except:
|
except:
|
||||||
print("{0} v{1}: Error loading file {2}".format(PLUGIN_NAME, PLUGIN_VERSION, filename))
|
print("{0} v{1}: Error loading file {2}".format(PLUGIN_NAME, PLUGIN_VERSION, filename))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
os.remove(fpath)
|
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"))
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user