BVB Source Codes

DeDRM_tools Show scriptinterface.py Source code

Return Download DeDRM_tools: download scriptinterface.py Source code - Download DeDRM_tools Source code - Type:.py
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
  4.  
  5. import sys
  6. import os
  7. import re
  8. import ineptepub
  9. import ignobleepub
  10. import epubtest
  11. import zipfix
  12. import ineptpdf
  13. import erdr2pml
  14. import k4mobidedrm
  15. import traceback
  16.  
  17. def decryptepub(infile, outdir, rscpath):
  18.     errlog = ''
  19.  
  20.     # first fix the epub to make sure we do not get errors
  21.     name, ext = os.path.splitext(os.path.basename(infile))
  22.     bpath = os.path.dirname(infile)
  23.     zippath = os.path.join(bpath,name + '_temp.zip')
  24.     rv = zipfix.repairBook(infile, zippath)
  25.     if rv != 0:
  26.         print "Error while trying to fix epub"
  27.         return rv
  28.  
  29.     # determine a good name for the output file
  30.     outfile = os.path.join(outdir, name + '_nodrm.epub')
  31.  
  32.     rv = 1
  33.     # first try with the Adobe adept epub
  34.     if  ineptepub.adeptBook(zippath):
  35.         # try with any keyfiles (*.der) in the rscpath
  36.         files = os.listdir(rscpath)
  37.         filefilter = re.compile("\.der$", re.IGNORECASE)
  38.         files = filter(filefilter.search, files)
  39.         if files:
  40.             for filename in files:
  41.                 keypath = os.path.join(rscpath, filename)
  42.                 userkey = open(keypath,'rb').read()
  43.                 try:
  44.                     rv = ineptepub.decryptBook(userkey, zippath, outfile)
  45.                     if rv == 0:
  46.                         print "Decrypted Adobe ePub with key file {0}".format(filename)
  47.                         break
  48.                 except Exception, e:
  49.                     errlog += traceback.format_exc()
  50.                     errlog += str(e)
  51.                     rv = 1
  52.     # now try with ignoble epub
  53.     elif  ignobleepub.ignobleBook(zippath):
  54.         # try with any keyfiles (*.b64) in the rscpath
  55.         files = os.listdir(rscpath)
  56.         filefilter = re.compile("\.b64$", re.IGNORECASE)
  57.         files = filter(filefilter.search, files)
  58.         if files:
  59.             for filename in files:
  60.                 keypath = os.path.join(rscpath, filename)
  61.                 userkey = open(keypath,'r').read()
  62.                 #print userkey
  63.                 try:
  64.                     rv = ignobleepub.decryptBook(userkey, zippath, outfile)
  65.                     if rv == 0:
  66.                         print "Decrypted B&N ePub with key file {0}".format(filename)
  67.                         break
  68.                 except Exception, e:
  69.                     errlog += traceback.format_exc()
  70.                     errlog += str(e)
  71.                     rv = 1
  72.     else:
  73.         encryption = epubtest.encryption(zippath)
  74.         if encryption == "Unencrypted":
  75.             print "{0} is not DRMed.".format(name)
  76.             rv = 0
  77.         else:
  78.             print "{0} has an unknown encryption.".format(name)
  79.  
  80.     os.remove(zippath)
  81.     if rv != 0:
  82.         print errlog
  83.     return rv
  84.  
  85.  
  86. def decryptpdf(infile, outdir, rscpath):
  87.     errlog = ''
  88.     rv = 1
  89.  
  90.     # determine a good name for the output file
  91.     name, ext = os.path.splitext(os.path.basename(infile))
  92.     outfile = os.path.join(outdir, name + '_nodrm.pdf')
  93.  
  94.     # try with any keyfiles (*.der) in the rscpath
  95.     files = os.listdir(rscpath)
  96.     filefilter = re.compile("\.der$", re.IGNORECASE)
  97.     files = filter(filefilter.search, files)
  98.     if files:
  99.         for filename in files:
  100.             keypath = os.path.join(rscpath, filename)
  101.             userkey = open(keypath,'rb').read()
  102.             try:
  103.                 rv = ineptpdf.decryptBook(userkey, infile, outfile)
  104.                 if rv == 0:
  105.                     break
  106.             except Exception, e:
  107.                 errlog += traceback.format_exc()
  108.                 errlog += str(e)
  109.                 rv = 1
  110.  
  111.     if rv != 0:
  112.         print errlog
  113.     return rv
  114.  
  115.  
  116. def decryptpdb(infile, outdir, rscpath):
  117.     outname = os.path.splitext(os.path.basename(infile))[0] + ".pmlz"
  118.     outpath = os.path.join(outdir, outname)
  119.     rv = 1
  120.     socialpath = os.path.join(rscpath,'sdrmlist.txt')
  121.     if os.path.exists(socialpath):
  122.         keydata = file(socialpath,'r').read()
  123.         keydata = keydata.rstrip(os.linesep)
  124.         ar = keydata.split(',')
  125.         for i in ar:
  126.             try:
  127.                 name, cc8 = i.split(':')
  128.             except ValueError:
  129.                 print '   Error parsing user supplied social drm data.'
  130.                 return 1
  131.             try:
  132.                 rv = erdr2pml.decryptBook(infile, outpath, True, erdr2pml.getuser_key(name, cc8))
  133.             except Exception, e:
  134.                 errlog += traceback.format_exc()
  135.                 errlog += str(e)
  136.                 rv = 1
  137.  
  138.             if rv == 0:
  139.                 break
  140.     return rv
  141.  
  142.  
  143. def decryptk4mobi(infile, outdir, rscpath):
  144.     rv = 1
  145.     pidnums = []
  146.     pidspath = os.path.join(rscpath,'pidlist.txt')
  147.     if os.path.exists(pidspath):
  148.         pidstr = file(pidspath,'r').read()
  149.         pidstr = pidstr.rstrip(os.linesep)
  150.         pidstr = pidstr.strip()
  151.         if pidstr != '':
  152.             pidnums = pidstr.split(',')
  153.     serialnums = []
  154.     serialnumspath = os.path.join(rscpath,'seriallist.txt')
  155.     if os.path.exists(serialnumspath):
  156.         serialstr = file(serialnumspath,'r').read()
  157.         serialstr = serialstr.rstrip(os.linesep)
  158.         serialstr = serialstr.strip()
  159.         if serialstr != '':
  160.             serialnums = serialstr.split(',')
  161.     kDatabaseFiles = []
  162.     files = os.listdir(rscpath)
  163.     filefilter = re.compile("\.k4i$", re.IGNORECASE)
  164.     files = filter(filefilter.search, files)
  165.     if files:
  166.         for filename in files:
  167.             dpath = os.path.join(rscpath,filename)
  168.             kDatabaseFiles.append(dpath)
  169.     androidFiles = []
  170.     files = os.listdir(rscpath)
  171.     filefilter = re.compile("\.ab$", re.IGNORECASE)
  172.     files = filter(filefilter.search, files)
  173.     if files:
  174.         for filename in files:
  175.             dpath = os.path.join(rscpath,filename)
  176.             androidFiles.append(dpath)
  177.     files = os.listdir(rscpath)
  178.     filefilter = re.compile("\.db$", re.IGNORECASE)
  179.     files = filter(filefilter.search, files)
  180.     if files:
  181.         for filename in files:
  182.             dpath = os.path.join(rscpath,filename)
  183.             androidFiles.append(dpath)
  184.     files = os.listdir(rscpath)
  185.     filefilter = re.compile("\.xml$", re.IGNORECASE)
  186.     files = filter(filefilter.search, files)
  187.     if files:
  188.         for filename in files:
  189.             dpath = os.path.join(rscpath,filename)
  190.             androidFiles.append(dpath)
  191.     try:
  192.         rv = k4mobidedrm.decryptBook(infile, outdir, kDatabaseFiles, androidFiles, serialnums, pidnums)
  193.     except Exception, e:
  194.         errlog += traceback.format_exc()
  195.         errlog += str(e)
  196.         rv = 1
  197.  
  198.     return rv
  199.  
downloadscriptinterface.py Source code - Download DeDRM_tools Source code
Related Source Codes/Software:
kcp - KCP - A Fast and Reliable ARQ Protocol 2017-04-08
cloc - cloc counts blank lines, comment lines, and physic... 2017-04-08
nvidia-docker - Build and run Docker containers leveraging NVIDIA ... 2017-04-08
quickstart - Angular 2 QuickStart - source from the documentati... 2017-04-08
jQuery-Autocomplete - Ajax Autocomplete for jQuery allows you to easily ... 2017-04-08
fuckitjs - The Original Javascript Error Steamroller 2017-04-09
eslint-plugin-react - React specific linting rules for ESLint 2017-04-09
husky - 2017-04-09
electron-builder - A complete solution to package and build a ready f... 2017-04-09
jsfeat - JavaScript Computer Vision library. 2017-04-16
flakes - Flakes is an Admin Template Framework. A combinati... 2017-04-15
capstone - Capstone disassembly/disassembler framework: Core ... 2017-04-15
nginx-resources - A collection of resources covering Nginx, Nginx + ... 2017-04-15
utron - A lightweight MVC framework for Go(Golang) 2017-04-15
cfssl - CFSSL: Cloudflare's PKI and TLS toolkit ... 2017-04-15
HandBrake - HandBrake's main development repository ... 2017-04-15
Awesome-Networking - A curated list of awesome networking libraries, re... 2017-04-15
react-sortable-hoc - A set of higher-order components to turn any list ... 2017-04-15
jugglingdb - Multi-database ORM for nodejs: redis, mongodb, mys... 2017-04-15

 Back to top