コード例 #1
0
ファイル: config.py プロジェクト: MorantHypopolia/DeDRM_tools
 def migrate_files(self):
     unique_dlg_name = PLUGIN_NAME + u"import {0} keys".format(self.key_type_name).replace(' ', '_') #takes care of automatically remembering last directory
     caption = u"Select {0} files to import".format(self.key_type_name)
     filters = [(u"{0} files".format(self.key_type_name), [self.keyfile_ext])]
     files = choose_files(self, unique_dlg_name, caption, filters, all_files=False)
     counter = 0
     skipped = 0
     if files:
         for filename in files:
             fpath = os.path.join(config_dir, filename)
             filename = os.path.basename(filename)
             if type(self.plugin_keys) != dict:
                 # must be the new Kindle for Android section
                 print u"Getting keys from "+fpath
                 new_keys = get_serials(fpath)
                 for key in new_keys:
                     if key in self.plugin_keys:
                         skipped += 1
                     else:
                         counter += 1
                         self.plugin_keys.append(key)
             else:
                 new_key_name = os.path.splitext(os.path.basename(filename))[0]
                 with open(fpath,'rb') as keyfile:
                     new_key_value = keyfile.read()
                 if self.binary_file:
                     new_key_value = new_key_value.encode('hex')
                 elif self.json_file:
                     new_key_value = json.loads(new_key_value)
                 match = False
                 for key in self.plugin_keys.keys():
                     if uStrCmp(new_key_name, key, True):
                         skipped += 1
                         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)
                         inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                 _(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""
         if counter+skipped > 1:
             if counter > 0:
                 msg += u"Imported <strong>{0:d}</strong> key {1}. ".format(counter, u"file" if counter == 1 else u"files")
             if skipped > 0:
                 msg += u"Skipped <strong>{0:d}</strong> key {1}.".format(skipped, u"file" if counter == 1 else u"files")
             inf = info_dialog(None, "{0} {1}".format(PLUGIN_NAME, PLUGIN_VERSION),
                                 _(msg), show_copy_button=False, show=True)
     return counter > 0
コード例 #2
0
ファイル: k4mobidedrm.py プロジェクト: quehub/DeDRM_tools
def GetDecryptedBook(infile,
                     kDatabases,
                     androidFiles,
                     serials,
                     pids,
                     starttime=time.time()):
    # handle the obvious cases at the beginning
    if not os.path.isfile(infile):
        raise DrmException(u"Input file does not exist.")

    mobi = True
    magic8 = open(infile, 'rb').read(8)
    if magic8 == '\xeaDRMION\xee':
        raise DrmException(
            u"The .kfx DRMION file cannot be decrypted by itself. A .kfx-zip archive containing a DRM voucher is required."
        )

    magic3 = magic8[:3]
    if magic3 == 'TPZ':
        mobi = False

    if magic8[:4] == 'PK\x03\x04':
        mb = kfxdedrm.KFXZipBook(infile)
    elif mobi:
        mb = mobidedrm.MobiBook(infile)
    else:
        mb = topazextract.TopazBook(infile)

    bookname = unescape(mb.getBookTitle())
    print u"Decrypting {1} ebook: {0}".format(bookname, mb.getBookType())

    # copy list of pids
    totalpids = list(pids)
    # extend list of serials with serials from android databases
    for aFile in androidFiles:
        serials.extend(androidkindlekey.get_serials(aFile))
    # extend PID list with book-specific PIDs from seriala and kDatabases
    md1, md2 = mb.getPIDMetaInfo()
    totalpids.extend(kgenpids.getPidList(md1, md2, serials, kDatabases))
    # remove any duplicates
    totalpids = list(set(totalpids))
    print u"Found {1:d} keys to try after {0:.1f} seconds".format(
        time.time() - starttime, len(totalpids))
    #print totalpids

    try:
        mb.processBook(totalpids)
    except:
        mb.cleanup
        raise

    print u"Decryption succeeded after {0:.1f} seconds".format(time.time() -
                                                               starttime)
    return mb
コード例 #3
0
ファイル: config.py プロジェクト: xmorgan/DeDRM_tools
 def get_android_file(self):
     unique_dlg_name = PLUGIN_NAME + "Import Kindle for Android backup file" #takes care of automatically remembering last directory
     caption = "Select Kindle for Android backup file to add"
     filters = [("Kindle for Android backup files", ['db','ab','xml'])]
     files = choose_files(self, unique_dlg_name, caption, filters, all_files=False)
     self.serials_from_file = []
     file_name = ""
     if files:
         # find the first selected file that yields some serial numbers
         for filename in files:
             fpath = os.path.join(config_dir, filename)
             self.filename = os.path.basename(filename)
             file_serials = androidkindlekey.get_serials(fpath)
             if len(file_serials)>0:
                 file_name = os.path.basename(self.filename)
                 self.serials_from_file.extend(file_serials)
     self.selected_file_name.setText(file_name)
コード例 #4
0
ファイル: config.py プロジェクト: Bearhomeng/DeDRM_tools
 def get_android_file(self):
     unique_dlg_name = PLUGIN_NAME + u"Import Kindle for Android backup file" #takes care of automatically remembering last directory
     caption = u"Select Kindle for Android backup file to add"
     filters = [(u"Kindle for Android backup files", ['db','ab','xml'])]
     files = choose_files(self, unique_dlg_name, caption, filters, all_files=False)
     self.serials_from_file = []
     file_name = u""
     if files:
         # find the first selected file that yields some serial numbers
         for filename in files:
             fpath = os.path.join(config_dir, filename)
             self.filename = os.path.basename(filename)
             file_serials = androidkindlekey.get_serials(fpath)
             if len(file_serials)>0:
                 file_name = os.path.basename(self.filename)
                 self.serials_from_file.extend(file_serials)
     self.selected_file_name.setText(file_name)
コード例 #5
0
ファイル: k4mobidedrm.py プロジェクト: CyB0rG0D/DeDRM_tools
def GetDecryptedBook(infile, kDatabases, androidFiles, serials, pids, starttime = time.time()):
    # handle the obvious cases at the beginning
    if not os.path.isfile(infile):
        raise DrmException(u"Input file does not exist.")

    mobi = True
    magic8 = open(infile,'rb').read(8)
    if magic8 == '\xeaDRMION\xee':
        raise DrmException(u"KFX format detected. This format cannot be decrypted yet.")
        
    magic3 = magic8[:3]
    if magic3 == 'TPZ':
        mobi = False

    if mobi:
        mb = mobidedrm.MobiBook(infile)
    else:
        mb = topazextract.TopazBook(infile)

    bookname = unescape(mb.getBookTitle())
    print u"Decrypting {1} ebook: {0}".format(bookname, mb.getBookType())

    # copy list of pids
    totalpids = list(pids)
    # extend list of serials with serials from android databases
    for aFile in androidFiles:
        serials.extend(androidkindlekey.get_serials(aFile))
    # extend PID list with book-specific PIDs from seriala and kDatabases
    md1, md2 = mb.getPIDMetaInfo()
    totalpids.extend(kgenpids.getPidList(md1, md2, serials, kDatabases))
    # remove any duplicates
    totalpids = list(set(totalpids))
    print u"Found {1:d} keys to try after {0:.1f} seconds".format(time.time()-starttime, len(totalpids))
    #print totalpids

    try:
        mb.processBook(totalpids)
    except:
        mb.cleanup
        raise

    print u"Decryption succeeded after {0:.1f} seconds".format(time.time()-starttime)
    return mb
コード例 #6
0
ファイル: k4mobidedrm.py プロジェクト: Moscarda/DRMM
    pids = []

    for o, a in opts:
        if o == "-k":
            if a == None:
                raise DrmException("Invalid parameter for -k")
            kDatabaseFiles.append(a)
        if o == "-p":
            if a == None:
                raise DrmException("Invalid parameter for -p")
            pids = a.split(',')
        if o == "-s":
            if a == None:
                raise DrmException("Invalid parameter for -s")
            serials = a.split(',')
        if o == '-a':
            if a == None:
                continue
            serials.extend(androidkindlekey.get_serials(a))

    # try with built in Kindle Info files if not on Linux
    k4 = not sys.platform.startswith('linux')

    return decryptBook(infile, outdir, kDatabaseFiles, serials, pids)


if __name__ == '__main__':
    sys.stdout = SafeUnbuffered(sys.stdout)
    sys.stderr = SafeUnbuffered(sys.stderr)
    sys.exit(cli_main())
コード例 #7
0
    pids = []

    for o, a in opts:
        if o == "-k":
            if a == None :
                raise DrmException("Invalid parameter for -k")
            kDatabaseFiles.append(a)
        if o == "-p":
            if a == None :
                raise DrmException("Invalid parameter for -p")
            pids = a.split(',')
        if o == "-s":
            if a == None :
                raise DrmException("Invalid parameter for -s")
            serials = a.split(',')
        if o == '-a':
            if a == None:
                continue
            serials.extend(androidkindlekey.get_serials(a))

    # try with built in Kindle Info files if not on Linux
    k4 = not sys.platform.startswith('linux')

    return decryptBook(infile, outdir, kDatabaseFiles, serials, pids)


if __name__ == '__main__':
    sys.stdout=SafeUnbuffered(sys.stdout)
    sys.stderr=SafeUnbuffered(sys.stderr)
    sys.exit(cli_main())