Skip to content

Commit

Permalink
tools v3.2
Browse files Browse the repository at this point in the history
First appearance of combined windows python app
  • Loading branch information
apprenticealf committed Mar 5, 2015
1 parent 00ac669 commit bc968f8
Show file tree
Hide file tree
Showing 64 changed files with 11,223 additions and 708 deletions.
93 changes: 50 additions & 43 deletions Adobe_EPUB_Tools/ineptepub.pyw
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-

# ineptepub.pyw, version 5.5
from __future__ import with_statement

# ineptepub.pyw, version 5.6
# Copyright © 2009-2010 i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3 or
Expand All @@ -27,13 +29,11 @@
# 5.3 - add support for OpenSSL on Windows, fix bug with some versions of libcrypto 0.9.8 prior to path level o
# 5.4 - add support for encoding to 'utf-8' when building up list of files to decrypt from encryption.xml
# 5.5 - On Windows try PyCrypto first, OpenSSL next

# 5.6 - Modify interface to allow use with import
"""
Decrypt Adobe ADEPT-encrypted EPUB books.
"""

from __future__ import with_statement

__license__ = 'GPL v3'

import sys
Expand Down Expand Up @@ -312,45 +312,6 @@ class Decryptor(object):
data = self.decompress(data)
return data

def cli_main(argv=sys.argv):
progname = os.path.basename(argv[0])
if AES is None:
print "%s: This script requires OpenSSL or PyCrypto, which must be" \
" installed separately. Read the top-of-script comment for" \
" details." % (progname,)
return 1
if len(argv) != 4:
print "usage: %s KEYFILE INBOOK OUTBOOK" % (progname,)
return 1
keypath, inpath, outpath = argv[1:]
with open(keypath, 'rb') as f:
keyder = f.read()
rsa = RSA(keyder)
with closing(ZipFile(open(inpath, 'rb'))) as inf:
namelist = set(inf.namelist())
if 'META-INF/rights.xml' not in namelist or \
'META-INF/encryption.xml' not in namelist:
raise ADEPTError('%s: not an ADEPT EPUB' % (inpath,))
for name in META_NAMES:
namelist.remove(name)
rights = etree.fromstring(inf.read('META-INF/rights.xml'))
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
expr = './/%s' % (adept('encryptedKey'),)
bookkey = ''.join(rights.findtext(expr))
bookkey = rsa.decrypt(bookkey.decode('base64'))
# Padded as per RSAES-PKCS1-v1_5
if bookkey[-17] != '\x00':
raise ADEPTError('problem decrypting session key')
encryption = inf.read('META-INF/encryption.xml')
decryptor = Decryptor(bookkey[-16:], encryption)
kwds = dict(compression=ZIP_DEFLATED, allowZip64=False)
with closing(ZipFile(open(outpath, 'wb'), 'w', **kwds)) as outf:
zi = ZipInfo('mimetype', compress_type=ZIP_STORED)
outf.writestr(zi, inf.read('mimetype'))
for path in namelist:
data = inf.read(path)
outf.writestr(path, decryptor.decrypt(path, data))
return 0

class DecryptionDialog(Tkinter.Frame):
def __init__(self, root):
Expand Down Expand Up @@ -446,6 +407,52 @@ class DecryptionDialog(Tkinter.Frame):
return
self.status['text'] = 'File successfully decrypted'


def decryptBook(keypath, inpath, outpath):
with open(keypath, 'rb') as f:
keyder = f.read()
rsa = RSA(keyder)
with closing(ZipFile(open(inpath, 'rb'))) as inf:
namelist = set(inf.namelist())
if 'META-INF/rights.xml' not in namelist or \
'META-INF/encryption.xml' not in namelist:
raise ADEPTError('%s: not an ADEPT EPUB' % (inpath,))
for name in META_NAMES:
namelist.remove(name)
rights = etree.fromstring(inf.read('META-INF/rights.xml'))
adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
expr = './/%s' % (adept('encryptedKey'),)
bookkey = ''.join(rights.findtext(expr))
bookkey = rsa.decrypt(bookkey.decode('base64'))
# Padded as per RSAES-PKCS1-v1_5
if bookkey[-17] != '\x00':
raise ADEPTError('problem decrypting session key')
encryption = inf.read('META-INF/encryption.xml')
decryptor = Decryptor(bookkey[-16:], encryption)
kwds = dict(compression=ZIP_DEFLATED, allowZip64=False)
with closing(ZipFile(open(outpath, 'wb'), 'w', **kwds)) as outf:
zi = ZipInfo('mimetype', compress_type=ZIP_STORED)
outf.writestr(zi, inf.read('mimetype'))
for path in namelist:
data = inf.read(path)
outf.writestr(path, decryptor.decrypt(path, data))
return 0


def cli_main(argv=sys.argv):
progname = os.path.basename(argv[0])
if AES is None:
print "%s: This script requires OpenSSL or PyCrypto, which must be" \
" installed separately. Read the top-of-script comment for" \
" details." % (progname,)
return 1
if len(argv) != 4:
print "usage: %s KEYFILE INBOOK OUTBOOK" % (progname,)
return 1
keypath, inpath, outpath = argv[1:]
return decryptBook(keypath, inpath, outpath)


def gui_main():
root = Tkinter.Tk()
if AES is None:
Expand Down
18 changes: 13 additions & 5 deletions Adobe_EPUB_Tools/ineptkey.pyw
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-

# ineptkey.pyw, version 5.3
from __future__ import with_statement

# ineptkey.pyw, version 5.4
# Copyright © 2009-2010 i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3 or
Expand Down Expand Up @@ -33,13 +35,12 @@
# 5.1 - add support for using OpenSSL on Windows in place of PyCrypto
# 5.2 - added support for output of key to a particular file
# 5.3 - On Windows try PyCrypto first, OpenSSL next
# 5.4 - Modify interface to allow use of import

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

from __future__ import with_statement

__license__ = 'GPL v3'

import sys
Expand Down Expand Up @@ -415,10 +416,11 @@ class ExceptionDialog(Tkinter.Frame):
label.pack(fill=Tkconstants.X, expand=0)
self.text = Tkinter.Text(self)
self.text.pack(fill=Tkconstants.BOTH, expand=1)

self.text.insert(Tkconstants.END, text)

def cli_main(argv=sys.argv):
keypath = argv[1]

def extractKeyfile(keypath):
try:
success = retrieve_key(keypath)
except ADEPTError, e:
Expand All @@ -431,6 +433,12 @@ def cli_main(argv=sys.argv):
return 1
return 0


def cli_main(argv=sys.argv):
keypath = argv[1]
return extractKeyfile(keypath)


def main(argv=sys.argv):
root = Tkinter.Tk()
root.withdraw()
Expand Down
18 changes: 13 additions & 5 deletions Adobe_PDF_Tools/ineptkey.pyw
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /usr/bin/python
# -*- coding: utf-8 -*-

# ineptkey.pyw, version 5.3
from __future__ import with_statement

# ineptkey.pyw, version 5.4
# Copyright © 2009-2010 i♥cabbages

# Released under the terms of the GNU General Public Licence, version 3 or
Expand Down Expand Up @@ -33,13 +35,12 @@
# 5.1 - add support for using OpenSSL on Windows in place of PyCrypto
# 5.2 - added support for output of key to a particular file
# 5.3 - On Windows try PyCrypto first, OpenSSL next
# 5.4 - Modify interface to allow use of import

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

from __future__ import with_statement

__license__ = 'GPL v3'

import sys
Expand Down Expand Up @@ -415,10 +416,11 @@ class ExceptionDialog(Tkinter.Frame):
label.pack(fill=Tkconstants.X, expand=0)
self.text = Tkinter.Text(self)
self.text.pack(fill=Tkconstants.BOTH, expand=1)

self.text.insert(Tkconstants.END, text)

def cli_main(argv=sys.argv):
keypath = argv[1]

def extractKeyfile(keypath):
try:
success = retrieve_key(keypath)
except ADEPTError, e:
Expand All @@ -431,6 +433,12 @@ def cli_main(argv=sys.argv):
return 1
return 0


def cli_main(argv=sys.argv):
keypath = argv[1]
return extractKeyfile(keypath)


def main(argv=sys.argv):
root = Tkinter.Tk()
root.withdraw()
Expand Down
49 changes: 28 additions & 21 deletions Adobe_PDF_Tools/ineptpdf.pyw
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /usr/bin/env python
# ineptpdf.pyw, version 7.7

from __future__ import with_statement

# To run this program install Python 2.6 from http://www.python.org/download/
# and OpenSSL (already installed on Mac OS X and Linux) OR
# PyCrypto from http://www.voidspace.org.uk/python/modules.shtml#pycrypto
Expand Down Expand Up @@ -30,13 +32,12 @@
# fixed minor typos
# 7.6 - backported AES and other fixes from version 8.4.48
# 7.7 - On Windows try PyCrypto first and OpenSSL next
# 7.8 - Modify interface to allow use of import

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

from __future__ import with_statement

__license__ = 'GPL v3'

import sys
Expand Down Expand Up @@ -2076,25 +2077,6 @@ class PDFSerializer(object):
self.write('\n')
self.write('endobj\n')

def cli_main(argv=sys.argv):
progname = os.path.basename(argv[0])
if RSA is None:
print "%s: This script requires OpenSSL or PyCrypto, which must be installed " \
"separately. Read the top-of-script comment for details." % \
(progname,)
return 1
if len(argv) != 4:
print "usage: %s KEYFILE INBOOK OUTBOOK" % (progname,)
return 1
keypath, inpath, outpath = argv[1:]
with open(inpath, 'rb') as inf:
serializer = PDFSerializer(inf, keypath)
# hope this will fix the 'bad file descriptor' problem
with open(outpath, 'wb') as outf:
# help construct to make sure the method runs to the end
serializer.dump(outf)
return 0


class DecryptionDialog(Tkinter.Frame):
def __init__(self, root):
Expand Down Expand Up @@ -2198,6 +2180,31 @@ class DecryptionDialog(Tkinter.Frame):
'Close this window or decrypt another pdf file.'
return


def decryptBook(keypath, inpath, outpath):
with open(inpath, 'rb') as inf:
serializer = PDFSerializer(inf, keypath)
# hope this will fix the 'bad file descriptor' problem
with open(outpath, 'wb') as outf:
# help construct to make sure the method runs to the end
serializer.dump(outf)
return 0


def cli_main(argv=sys.argv):
progname = os.path.basename(argv[0])
if RSA is None:
print "%s: This script requires OpenSSL or PyCrypto, which must be installed " \
"separately. Read the top-of-script comment for details." % \
(progname,)
return 1
if len(argv) != 4:
print "usage: %s KEYFILE INBOOK OUTBOOK" % (progname,)
return 1
keypath, inpath, outpath = argv[1:]
return decryptBook(keypath, inpath, outpath)


def gui_main():
root = Tkinter.Tk()
if RSA is None:
Expand Down
Loading

0 comments on commit bc968f8

Please sign in to comment.