Skip to content

Commit

Permalink
tools v6.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
apprenticealf committed Mar 7, 2015
1 parent 20bc936 commit a2f044e
Show file tree
Hide file tree
Showing 59 changed files with 704 additions and 2,247 deletions.
6 changes: 3 additions & 3 deletions DeDRM_Macintosh_Application/DeDRM.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
<key>CFBundleExecutable</key>
<string>droplet</string>
<key>CFBundleGetInfoString</key>
<string>DeDRM AppleScript 6.0.0. Written 2010–2013 by Apprentice Alf and others.</string>
<string>DeDRM AppleScript 6.0.1. Written 2010–2013 by Apprentice Alf and others.</string>
<key>CFBundleIconFile</key>
<string>DeDRM</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>DeDRM AppleScript</string>
<string>DeDRM</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>6.0.0</string>
<string>6.0.1</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSRequiresCarbon</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
#
# Revision history:
# 6.0.0 - Initial release
# 6.0.1 - Bug Fixes for Windows App

"""
Decrypt DRMed ebooks.
"""

PLUGIN_NAME = u"DeDRM"
PLUGIN_VERSION_TUPLE = (6, 0, 0)
PLUGIN_VERSION_TUPLE = (6, 0, 1)
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@
# 5.6 - Revised to allow use in Plugins to eliminate need for duplicate code
# 5.7 - Unicode support added, renamed adobekey from ineptkey
# 5.8 - Added getkey interface for Windows DeDRM application
# 5.9 - moved unicode_argv call inside main for Windows DeDRM compatibility

"""
Retrieve Adobe ADEPT user key.
"""

__license__ = 'GPL v3'
__version__ = '5.8'
__version__ = '5.9'

import sys, os, struct, getopt

Expand Down Expand Up @@ -483,7 +484,8 @@ def usage(progname):
print u"Usage:"
print u" {0:s} [-h] [<outpath>]".format(progname)

def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
print u"{0} v{1}\nCopyright © 2009-2013 i♥cabbages and Apprentice Alf".format(progname,__version__)

Expand Down Expand Up @@ -538,7 +540,7 @@ def cli_main(argv=unicode_argv()):
return 0


def gui_main(argv=unicode_argv()):
def gui_main():
import Tkinter
import Tkconstants
import tkMessageBox
Expand All @@ -556,6 +558,7 @@ def __init__(self, root, text):
self.text.insert(Tkconstants.END, text)


argv=unicode_argv()
root = Tkinter.Tk()
root.withdraw()
progpath, progname = os.path.split(argv[0])
Expand Down
109 changes: 74 additions & 35 deletions DeDRM_Macintosh_Application/DeDRM.app/Contents/Resources/epubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Changelog epubtest
# 1.00 - Cut to epubtest.py, testing ePub files only by Apprentice Alf
# 1.01 - Added routine for use by Windows DeDRM
#
# Written in 2011 by Paul Durrant
# Released with unlicense. See http://unlicense.org/
Expand Down Expand Up @@ -45,7 +46,7 @@

from __future__ import with_statement

__version__ = '1.00'
__version__ = '1.01'

import sys, struct, os
import zlib
Expand All @@ -72,11 +73,49 @@ def write(self, data):
def __getattr__(self, attr):
return getattr(self.stream, attr)

try:
from calibre.constants import iswindows, isosx
except:
iswindows = sys.platform.startswith('win')
isosx = sys.platform.startswith('darwin')

def unicode_argv():
argvencoding = sys.stdin.encoding
if argvencoding == None:
argvencoding = "utf-8"
return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]
if iswindows:
# Uses shell32.GetCommandLineArgvW to get sys.argv as a list of Unicode
# strings.

# Versions 2.x of Python don't support Unicode in sys.argv on
# Windows, with the underlying Windows API instead replacing multi-byte
# characters with '?'. So use shell32.GetCommandLineArgvW to get sys.argv
# as a list of Unicode strings and encode them as utf-8

from ctypes import POINTER, byref, cdll, c_int, windll
from ctypes.wintypes import LPCWSTR, LPWSTR

GetCommandLineW = cdll.kernel32.GetCommandLineW
GetCommandLineW.argtypes = []
GetCommandLineW.restype = LPCWSTR

CommandLineToArgvW = windll.shell32.CommandLineToArgvW
CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
CommandLineToArgvW.restype = POINTER(LPWSTR)

cmd = GetCommandLineW()
argc = c_int(0)
argv = CommandLineToArgvW(cmd, byref(argc))
if argc.value > 0:
# Remove Python executable and commands if present
start = argc.value - len(sys.argv)
return [argv[i] for i in
xrange(start, argc.value)]
# if we don't have any arguments at all, just pass back script name
# this should never happen
return [u"epubtest.py"]
else:
argvencoding = sys.stdin.encoding
if argvencoding == None:
argvencoding = "utf-8"
return [arg if (type(arg) == unicode) else unicode(arg,argvencoding) for arg in sys.argv]

_FILENAME_LEN_OFFSET = 26
_EXTRA_LEN_OFFSET = 28
Expand Down Expand Up @@ -129,38 +168,38 @@ def getfiledata(file, zi):

return data

def main(argv=unicode_argv()):
infile = argv[1]
kind = "Unknown"
def encryption(infile):
# returns encryption: one of Unencrypted, Adobe, B&N and Unknown
encryption = "Unknown"
with file(infile,'rb') as infileobject:
bookdata = infileobject.read(58)
# Check for Mobipocket/Kindle
if bookdata[0:0+2] == "PK":
if bookdata[30:30+28] == 'mimetypeapplication/epub+zip':
kind = "ePub"
else:
kind = "ZIP"
encryption = "Unencrypted"
foundrights = False
foundencryption = False
inzip = zipfile.ZipFile(infile,'r')
namelist = set(inzip.namelist())
if 'META-INF/rights.xml' not in namelist or 'META-INF/encryption.xml' not in namelist:
encryption = "Unencrypted"
else:
rights = etree.fromstring(inzip.read('META-INF/rights.xml'))
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
expr = './/%s' % (adept('encryptedKey'),)
bookkey = ''.join(rights.findtext(expr))
if len(bookkey) == 172:
encryption = "Adobe"
elif len(bookkey) == 64:
encryption = "B&N"
try:
with open(infile,'rb') as infileobject:
bookdata = infileobject.read(58)
# Check for Zip
if bookdata[0:0+2] == "PK":
foundrights = False
foundencryption = False
inzip = zipfile.ZipFile(infile,'r')
namelist = set(inzip.namelist())
if 'META-INF/rights.xml' not in namelist or 'META-INF/encryption.xml' not in namelist:
encryption = "Unencrypted"
else:
encryption = "Unknown"

print u"{0} {1}".format(encryption, kind)
rights = etree.fromstring(inzip.read('META-INF/rights.xml'))
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
expr = './/%s' % (adept('encryptedKey'),)
bookkey = ''.join(rights.findtext(expr))
if len(bookkey) == 172:
encryption = "Adobe"
elif len(bookkey) == 64:
encryption = "B&N"
else:
encryption = "Unknown"
except:
traceback.print_exc()
return encryption

def main():
argv=unicode_argv()
print encryption(argv[1])
return 0

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
# - Don't reject dictionary format.
# - Ignore sidebars for dictionaries (different format?)
# 0.22 - Unicode and plugin support, different image folders for PMLZ and source
# 0.23 - moved unicode_argv call inside main for Windows DeDRM compatibility

__version__='0.22'
__version__='0.23'

import sys, re
import struct, binascii, getopt, zlib, os, os.path, urllib, tempfile, traceback
Expand Down Expand Up @@ -551,9 +552,10 @@ def getuser_key(name,cc):
cc = cc.replace(" ","")
return struct.pack('>LL', binascii.crc32(newname) & 0xffffffff,binascii.crc32(cc[-8:])& 0xffffffff)

def cli_main(argv=unicode_argv()):
def cli_main():
print u"eRdr2Pml v{0}. Copyright © 2009–2012 The Dark Reverser et al.".format(__version__)

argv=unicode_argv()
try:
opts, args = getopt.getopt(argv[1:], "hp", ["make-pmlz"])
except getopt.GetoptError, err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
# 3.6 - Revised to allow use in calibre plugins to eliminate need for duplicate code
# 3.7 - Tweaked to match ineptepub more closely
# 3.8 - Fixed to retain zip file metadata (e.g. file modification date)
# 3.9 - moved unicode_argv call inside main for Windows DeDRM compatibility

"""
Decrypt Barnes & Noble encrypted ePub books.
"""

__license__ = 'GPL v3'
__version__ = "3.8"
__version__ = "3.9"

import sys
import os
Expand Down Expand Up @@ -316,7 +317,8 @@ def decryptBook(keyb64, inpath, outpath):
return 0


def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
if len(argv) != 4:
print u"usage: {0} <keyfile.b64> <inbook.epub> <outbook.epub>".format(progname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
# 2.3 - Modify interface to allow use of import
# 2.4 - Improvements to UI and now works in plugins
# 2.5 - Additional improvement for unicode and plugin support
# 2.6 - moved unicode_argv call inside main for Windows DeDRM compatibility

"""
Generate Barnes & Noble EPUB user key from name and credit card number.
"""

__license__ = 'GPL v3'
__version__ = "2.5"
__version__ = "2.6"

import sys
import os
Expand Down Expand Up @@ -214,7 +215,8 @@ def generate_key(name, ccn):



def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
if AES is None:
print "%s: This script requires OpenSSL or PyCrypto, which must be installed " \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
# 5.7 - Fix for potential problem with PyCrypto
# 5.8 - Revised to allow use in calibre plugins to eliminate need for duplicate code
# 5.9 - Fixed to retain zip file metadata (e.g. file modification date)
# 5.10 - moved unicode_argv call inside main for Windows DeDRM compatibility

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

__license__ = 'GPL v3'
__version__ = "5.9"
__version__ = "5.10"

import sys
import os
Expand Down Expand Up @@ -458,7 +459,8 @@ def decryptBook(userkey, inpath, outpath):
return 0


def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
if len(argv) != 4:
print u"usage: {0} <keyfile.der> <inbook.epub> <outbook.epub>".format(progname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
# 7.11 - More tweaks to fix minor problems.
# 7.12 - Revised to allow use in calibre plugins to eliminate need for duplicate code
# 7.13 - Fixed erroneous mentions of ineptepub
# 7.14 - moved unicode_argv call inside main for Windows DeDRM compatibility

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

__license__ = 'GPL v3'
__version__ = "7.13"
__version__ = "7.14"

import sys
import os
Expand Down Expand Up @@ -2185,7 +2186,8 @@ def decryptBook(userkey, inpath, outpath):
return 0


def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
if len(argv) != 4:
print u"usage: {0} <keyfile.der> <inbook.pdf> <outbook.pdf>".format(progname)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
# 4.9 - Missed some invalid characters in cleanup_name
# 5.0 - Extraction of info from Kindle for PC/Mac moved into kindlekey.py
# - tweaked GetDecryptedBook interface to leave passed parameters unchanged
# 5.1 - moved unicode_argv call inside main for Windows DeDRM compatibility

__version__ = '5.0'
__version__ = '5.1'


import sys, os, re
Expand Down Expand Up @@ -276,7 +277,8 @@ def usage(progname):
#
# Main
#
def cli_main(argv=unicode_argv()):
def cli_main():
argv=unicode_argv()
progname = os.path.basename(argv[0])
print u"K4MobiDeDrm v{0}.\nCopyright © 2008-2013 The Dark Reverser et al.".format(__version__)

Expand Down
Loading

0 comments on commit a2f044e

Please sign in to comment.