def eReaderDecrypt(self,path_to_ebook): import calibre_plugins.dedrm.prefs as prefs import calibre_plugins.dedrm.erdr2pml dedrmprefs = prefs.DeDRM_Prefs() # Attempt to decrypt epub with each encryption key (generated or provided). for keyname, userkey in dedrmprefs['ereaderkeys'].items(): keyname_masked = u"".join((u'X' if (x.isdigit()) else x) for x in keyname) print u"{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname_masked) of = self.temporary_file(u".pmlz") # Give the userkey, ebook and TemporaryPersistent file to the decryption function. result = erdr2pml.decryptBook(path_to_ebook, of.name, True, userkey.decode('hex')) of.close() # Decryption was successful return the modified PersistentTemporary # file to Calibre's import process. if result == 0: print u"{0} v{1}: Successfully decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname_masked,time.time()-self.starttime) return of.name print u"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname_masked,time.time()-self.starttime) print u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime) raise DeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
def eReaderDecrypt(self,path_to_ebook): import calibre_plugins.dedrm.prefs as prefs import calibre_plugins.dedrm.erdr2pml dedrmprefs = prefs.DeDRM_Prefs() # Attempt to decrypt epub with each encryption key (generated or provided). for keyname, userkey in dedrmprefs['ereaderkeys'].items(): keyname_masked = u"".join((u'X' if (x.isdigit()) else x) for x in keyname) print u"{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname_masked) of = self.temporary_file(u".pmlz") # Give the userkey, ebook and TemporaryPersistent file to the decryption function. result = erdr2pml.decryptBook(path_to_ebook, of.name, True, userkey.decode('hex')) of.close() # Decryption was successful return the modified PersistentTemporary # file to Calibre's import process. if result == 0: print u"{0} v{1}: Successfully decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname_masked,time.time()-self.starttime) return of.name print u"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname_masked,time.time()-self.starttime) print u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds.\nRead the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime) raise DeDRMError(u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime))
def eReaderDecrypt(self, path_to_ebook): import calibre_plugins.dedrm.prefs as prefs import calibre_plugins.dedrm.erdr2pml dedrmprefs = prefs.DeDRM_Prefs() # Attempt to decrypt epub with each encryption key (generated or provided). for keyname, userkey in dedrmprefs["ereaderkeys"].items(): keyname_masked = u"".join((u"X" if (x.isdigit()) else x) for x in keyname) print u"{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname_masked) of = self.temporary_file(u".pmlz") # Give the userkey, ebook and TemporaryPersistent file to the decryption function. result = erdr2pml.decryptBook(path_to_ebook, of.name, True, userkey.decode("hex")) of.close() # Decryption was successful return the modified PersistentTemporary # file to Calibre's import process. if result == 0: return of.name print u"{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds".format( PLUGIN_NAME, PLUGIN_VERSION, keyname_masked, time.time() - self.starttime ) print u"{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds.\nRead the FAQs at Alf's blog: http://apprenticealf.wordpress.com/".format( PLUGIN_NAME, PLUGIN_VERSION, time.time() - self.starttime ) raise DeDRMError( u"{0} v{1}: Ultimately failed to decrypt “{2}” after {3:.1f} seconds.\nRead the FAQs at Alf's blog: http://apprenticealf.wordpress.com/".format( PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook), time.time() - self.starttime ) )
def decryptpdb(infile, outdir, rscpath): errlog = '' outname = os.path.splitext(os.path.basename(infile))[0] + ".pmlz" outpath = os.path.join(outdir, outname) rv = 1 socialpath = os.path.join(rscpath, 'sdrmlist.txt') if os.path.exists(socialpath): keydata = file(socialpath, 'r').read() keydata = keydata.rstrip(os.linesep) ar = keydata.split(',') for i in ar: try: name, cc8 = i.split(':') except ValueError: print(' Error parsing user supplied social drm data.') return 1 try: rv = erdr2pml.decryptBook(infile, outpath, True, erdr2pml.getuser_key(name, cc8)) except Exception as e: errlog += traceback.format_exc() errlog += str(e) rv = 1 if rv == 0: break return rv