예제 #1
0
def decryptpdb(infile, outdir, rscpath):
    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, e:
                errlog += traceback.format_exc()
                errlog += str(e)
                rv = 1

            if rv == 0:
                break
예제 #2
0
    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))
예제 #3
0
def main(argv=sys.argv):
    args = argv[1:]
    if len(args) != 3:
        return -1
    infile = args[0]
    outdir = args[1]
    rscpath = args[2]
    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
            rv = erdr2pml.decryptBook(infile, outdir, name, cc8, True)
            if rv == 0:
                break
    return rv
예제 #4
0
def decryptpdb(infile, outdir, rscpath):
    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, e:
                errlog += traceback.format_exc()
                errlog += str(e)
                rv = 1

            if rv == 0:
                break