Skip to content

Commit

Permalink
Update to DeDRM to try to fix Linux python problem, and improve Adobe…
Browse files Browse the repository at this point in the history
… logging
  • Loading branch information
apprenticeharper committed Jan 11, 2016
1 parent 72968d2 commit 10963f6
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 45 deletions.
Binary file modified DeDRM_Macintosh_Application/DeDRM.app.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions DeDRM_Macintosh_Application/DeDRM.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<key>CFBundleExecutable</key>
<string>droplet</string>
<key>CFBundleGetInfoString</key>
<string>DeDRM AppleScript 6.3.4 Written 2010–2015 by Apprentice Alf et al.</string>
<string>DeDRM AppleScript 6.3.5 Written 2010–2016 by Apprentice Alf et al.</string>
<key>CFBundleIconFile</key>
<string>DeDRM</string>
<key>CFBundleIdentifier</key>
Expand All @@ -36,7 +36,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>6.3.4</string>
<string>6.3.5</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSRequiresCarbon</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
# 6.3.2 - Fixed Kindle for Android help file
# 6.3.3 - Bug fix for Kindle for PC support
# 6.3.4 - Fixes for Kindle for Android, Linux, and Kobo 3.17
# 6.3.5 - Fixes for Linux, and Kobo 3.19 and more logging


"""
Decrypt DRMed ebooks.
"""

PLUGIN_NAME = u"DeDRM"
PLUGIN_VERSION_TUPLE = (6, 3, 4)
PLUGIN_VERSION_TUPLE = (6, 3, 5)
PLUGIN_VERSION = u".".join([unicode(str(x)) for x in PLUGIN_VERSION_TUPLE])
# Include an html helpfile in the plugin's zipfile with the following name.
RESOURCE_NAME = PLUGIN_NAME + '_Help.htm'
Expand Down Expand Up @@ -96,7 +97,7 @@ class DeDRM(FileTypePlugin):
supported_platforms = ['linux', 'osx', 'windows']
author = u"Apprentice Alf, Aprentice Harper, The Dark Reverser and i♥cabbages"
version = PLUGIN_VERSION_TUPLE
minimum_calibre_version = (0, 7, 55) # Compiled python libraries cannot be imported in earlier versions.
minimum_calibre_version = (1, 0, 0) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub','pdf','pdb','prc','mobi','pobi','azw','azw1','azw3','azw4','tpz'])
on_import = True
priority = 600
Expand Down Expand Up @@ -296,11 +297,15 @@ def ePubDecrypt(self,path_to_ebook):
traceback.print_exc()
result = 1

of.close()
try:
of.close()
except:
print u"{0} v{1}: Exception closing temporary file after {2:.1f} seconds. Ignored.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime)

if result == 0:
# Decryption was successful.
# Return the modified PersistentTemporary file to calibre.
print u"{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname,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,time.time()-self.starttime)
Expand Down Expand Up @@ -360,6 +365,7 @@ def ePubDecrypt(self,path_to_ebook):
except:
print u"{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime)
traceback.print_exc()
print u"{0} v{1}: Decrypted with new default key after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime)
# Return the modified PersistentTemporary file to calibre.
return of.name

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

from __future__ import with_statement

# ineptepub.pyw, version 6.1
# ineptepub.pyw, version 6.3
# Copyright © 2009-2010 by i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>

# Modified 2010–2013 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015–2016 by Apprentice Harper

# Windows users: Before running this program, you must first install Python 2.6
# Windows users: Before running this program, you must first install Python 2.7
# from <http://www.python.org/download/> and PyCrypto from
# <http://www.voidspace.org.uk/python/modules.shtml#pycrypto> (make sure to
# install the version for Python 2.6). Save this script file as
# install the version for Python 2.7). Save this script file as
# ineptepub.pyw and double-click on it to run it.
#
# Mac OS X users: Save this script file as ineptepub.pyw. You can run this
Expand All @@ -38,13 +39,14 @@
# 6.0 - moved unicode_argv call inside main for Windows DeDRM compatibility
# 6.1 - Work if TkInter is missing
# 6.2 - Handle UTF-8 file names inside an ePub, fix by Jose Luis
# 6.3 - Add additional check on DER file sanity

"""
Decrypt Adobe Digital Editions encrypted ePub books.
"""

__license__ = 'GPL v3'
__version__ = "6.2"
__version__ = "6.3"

import sys
import os
Expand Down Expand Up @@ -169,9 +171,14 @@ class RSA(object):
def __init__(self, der):
buf = create_string_buffer(der)
pp = c_char_pp(cast(buf, c_char_p))
rsa = self._rsa = d2i_RSAPrivateKey(None, pp, len(der))
rsa = self._rsa = d2i_RSAPrivateKey(None, pp, len(der))
if rsa is None:
raise ADEPTError('Error parsing ADEPT user key DER')
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')

def decrypt(self, from_):
rsa = self._rsa
Expand Down Expand Up @@ -313,6 +320,12 @@ def __init__(self, der):
key = [key.getChild(x).value for x in xrange(1, 4)]
key = [self.bytesToNumber(v) for v in key]
self._rsa = _RSA.construct(key)
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')


def bytesToNumber(self, bytes):
total = 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

from __future__ import with_statement

# ineptpdf.pyw, version 7.11
# ineptpdf.pyw, version 8.0.2
# Copyright © 2009-2010 by i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>

# Modified 2010–2012 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015-2016 by Apprentice Harper

# Windows users: Before running this program, you must first install Python 2.6
# Windows users: Before running this program, you must first install Python 2.7
# from <http://www.python.org/download/> and PyCrypto from
# <http://www.voidspace.org.uk/python/modules.shtml#pycrypto> (make sure to
# install the version for Python 2.6). Save this script file as
# install the version for Python 2.7). Save this script file as
# ineptpdf.pyw and double-click on it to run it.
#
# Mac OS X users: Save this script file as ineptpdf.pyw. You can run this
Expand Down Expand Up @@ -53,13 +54,15 @@
# 7.14 - moved unicode_argv call inside main for Windows DeDRM compatibility
# 8.0 - Work if TkInter is missing
# 8.0.1 - Broken Metadata fix.
# 8.0.2 - Add additional check on DER file sanity


"""
Decrypts Adobe ADEPT-encrypted PDF files.
"""

__license__ = 'GPL v3'
__version__ = "8.0.1"
__version__ = "8.0.2"

import sys
import os
Expand Down Expand Up @@ -198,6 +201,11 @@ def __init__(self, der):
rsa = self._rsa = d2i_RSAPrivateKey(None, pp, len(der))
if rsa is None:
raise ADEPTError('Error parsing ADEPT user key DER')
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')

def decrypt(self, from_):
rsa = self._rsa
Expand Down Expand Up @@ -383,6 +391,11 @@ def __init__(self, der):
key = [key.getChild(x).value for x in xrange(1, 4)]
key = [self.bytesToNumber(v) for v in key]
self._rsa = _RSA.construct(key)
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')

def bytesToNumber(self, bytes):
total = 0L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
if not os.path.exists(outdirpath):
os.makedirs(outdirpath)

wineprefix = os.path.abspath(os.path.expanduser(os.path.expandvars(wineprefix)))
if wineprefix != "" and os.path.exists(wineprefix):
cmdline = u"WINEPREFIX=\"{2}\" wine python.exe \"{0}\" \"{1}\"".format(scriptpath,outdirpath,wineprefix)
else:
Expand All @@ -38,8 +39,20 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
result = p2.wait("wait")
except Exception, e:
print u"{0} v{1}: Wine subprocess call error: {2}".format(PLUGIN_NAME, PLUGIN_VERSION, e.args[0])
return []
if wineprefix != "" and os.path.exists(wineprefix):
cmdline = u"WINEPREFIX=\"{2}\" wine C:\\Python27\\python.exe \"{0}\" \"{1}\"".format(scriptpath,outdirpath,wineprefix)
else:
cmdline = u"wine C:\\Python27\\python.exe \"{0}\" \"{1}\"".format(scriptpath,outdirpath)
print u"{0} v{1}: Command line: “{2}”".format(PLUGIN_NAME, PLUGIN_VERSION, cmdline)

try:
cmdline = cmdline.encode(sys.getfilesystemencoding())
p2 = Process(cmdline, shell=True, bufsize=1, stdin=None, stdout=sys.stdout, stderr=STDOUT, close_fds=False)
result = p2.wait("wait")
except Exception, e:
print u"{0} v{1}: Wine subprocess call error: {2}".format(PLUGIN_NAME, PLUGIN_VERSION, e.args[0])

# try finding winekeys anyway, even if above code errored
winekeys = []
# get any files with extension in the output dir
files = [f for f in os.listdir(outdirpath) if f.endswith(extension)]
Expand Down
5 changes: 3 additions & 2 deletions DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/DeDRM_App.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# DeDRM.pyw
# Copyright 2010-2015 some_updates, Apprentice Alf and Apprentice Harper
# Copyright 2010-2016 some_updates, Apprentice Alf and Apprentice Harper

# Revision history:
# 6.0.0 - Release along with unified plugin
Expand All @@ -19,8 +19,9 @@
# 6.3.2 - Version bump to match plugin
# 6.3.3 - Version bump to match plugin
# 6.3.4 - Version bump to match plugin
# 6.3.5 - Version bump to match plugin

__version__ = '6.3.4'
__version__ = '6.3.5'

import sys
import os, os.path
Expand Down
12 changes: 9 additions & 3 deletions DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
# 6.3.2 - Fixed Kindle for Android help file
# 6.3.3 - Bug fix for Kindle for PC support
# 6.3.4 - Fixes for Kindle for Android, Linux, and Kobo 3.17
# 6.3.5 - Fixes for Linux, and Kobo 3.19 and more logging


"""
Decrypt DRMed ebooks.
"""

PLUGIN_NAME = u"DeDRM"
PLUGIN_VERSION_TUPLE = (6, 3, 4)
PLUGIN_VERSION_TUPLE = (6, 3, 5)
PLUGIN_VERSION = u".".join([unicode(str(x)) for x in PLUGIN_VERSION_TUPLE])
# Include an html helpfile in the plugin's zipfile with the following name.
RESOURCE_NAME = PLUGIN_NAME + '_Help.htm'
Expand Down Expand Up @@ -96,7 +97,7 @@ class DeDRM(FileTypePlugin):
supported_platforms = ['linux', 'osx', 'windows']
author = u"Apprentice Alf, Aprentice Harper, The Dark Reverser and i♥cabbages"
version = PLUGIN_VERSION_TUPLE
minimum_calibre_version = (0, 7, 55) # Compiled python libraries cannot be imported in earlier versions.
minimum_calibre_version = (1, 0, 0) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub','pdf','pdb','prc','mobi','pobi','azw','azw1','azw3','azw4','tpz'])
on_import = True
priority = 600
Expand Down Expand Up @@ -296,11 +297,15 @@ def ePubDecrypt(self,path_to_ebook):
traceback.print_exc()
result = 1

of.close()
try:
of.close()
except:
print u"{0} v{1}: Exception closing temporary file after {2:.1f} seconds. Ignored.".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime)

if result == 0:
# Decryption was successful.
# Return the modified PersistentTemporary file to calibre.
print u"{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,keyname,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,time.time()-self.starttime)
Expand Down Expand Up @@ -360,6 +365,7 @@ def ePubDecrypt(self,path_to_ebook):
except:
print u"{0} v{1}: Exception when saving a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION, time.time()-self.starttime)
traceback.print_exc()
print u"{0} v{1}: Decrypted with new default key after {3:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime)
# Return the modified PersistentTemporary file to calibre.
return of.name

Expand Down
23 changes: 18 additions & 5 deletions DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/lib/ineptepub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

from __future__ import with_statement

# ineptepub.pyw, version 6.1
# ineptepub.pyw, version 6.3
# Copyright © 2009-2010 by i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>

# Modified 2010–2013 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015–2016 by Apprentice Harper

# Windows users: Before running this program, you must first install Python 2.6
# Windows users: Before running this program, you must first install Python 2.7
# from <http://www.python.org/download/> and PyCrypto from
# <http://www.voidspace.org.uk/python/modules.shtml#pycrypto> (make sure to
# install the version for Python 2.6). Save this script file as
# install the version for Python 2.7). Save this script file as
# ineptepub.pyw and double-click on it to run it.
#
# Mac OS X users: Save this script file as ineptepub.pyw. You can run this
Expand All @@ -38,13 +39,14 @@
# 6.0 - moved unicode_argv call inside main for Windows DeDRM compatibility
# 6.1 - Work if TkInter is missing
# 6.2 - Handle UTF-8 file names inside an ePub, fix by Jose Luis
# 6.3 - Add additional check on DER file sanity

"""
Decrypt Adobe Digital Editions encrypted ePub books.
"""

__license__ = 'GPL v3'
__version__ = "6.2"
__version__ = "6.3"

import sys
import os
Expand Down Expand Up @@ -169,9 +171,14 @@ class RSA(object):
def __init__(self, der):
buf = create_string_buffer(der)
pp = c_char_pp(cast(buf, c_char_p))
rsa = self._rsa = d2i_RSAPrivateKey(None, pp, len(der))
rsa = self._rsa = d2i_RSAPrivateKey(None, pp, len(der))
if rsa is None:
raise ADEPTError('Error parsing ADEPT user key DER')
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')

def decrypt(self, from_):
rsa = self._rsa
Expand Down Expand Up @@ -313,6 +320,12 @@ def __init__(self, der):
key = [key.getChild(x).value for x in xrange(1, 4)]
key = [self.bytesToNumber(v) for v in key]
self._rsa = _RSA.construct(key)
# check if pointer is not NULL
try:
c = self._rsa.contents
except ValueError:
raise ADEPTError('Error parsing ADEPT user key DER')


def bytesToNumber(self, bytes):
total = 0L
Expand Down
Loading

0 comments on commit 10963f6

Please sign in to comment.