Skip to content

Commit

Permalink
tools v3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
apprenticealf committed Mar 5, 2015
1 parent 8b632e3 commit 2bedd75
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 650 deletions.
14 changes: 14 additions & 0 deletions Calibre_Plugins/K4MobiDeDRM_plugin/genbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def getData(self, path):
argres[j] = int(argres[j])
return result
def getGlyphDim(self, gly):
if self.gdpi[gly] == 0:
return 0, 0
maxh = (self.gh[gly] * self.dpi) / self.gdpi[gly]
maxw = (self.gw[gly] * self.dpi) / self.gdpi[gly]
return maxh, maxw
Expand Down Expand Up @@ -320,6 +322,18 @@ def generateBook(bookDir, raw, fixedimage):
print 'Processing Meta Data and creating OPF'
meta_array = getMetaArray(metaFile)

# replace special chars in title and authors like & < >
title = meta_array['Title']
title = title.replace('&','&amp;')
title = title.replace('<','&lt;')
title = title.replace('>','&gt;')
meta_array['Title'] = title
authors = meta_array['Authors']
authors = authors.replace('&','&amp;')
authors = authors.replace('<','&lt;')
authors = authors.replace('>','&gt;')
meta_array['Authors'] = authors

xname = os.path.join(xmlDir, 'metadata.xml')
metastr = ''
for key in meta_array:
Expand Down
26 changes: 0 additions & 26 deletions Calibre_Plugins/Win_OpenSSL_0.9.8o.txt

This file was deleted.

Binary file modified Calibre_Plugins/ignobleepub_plugin.zip
Binary file not shown.
4 changes: 3 additions & 1 deletion Calibre_Plugins/ignobleepub_plugin/ignobleepub_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
# - Incorporated SomeUpdates zipfix routine.
# 0.1.2 - bug fix for non-ascii file names in encryption.xml
# 0.1.3 - Try PyCrypto on Windows first
# 0.1.4 - update zipfix to deal with mimetype not in correct place
# 0.1.5 - update zipfix to deal with completely missing mimetype files

"""
Decrypt Barnes & Noble ADEPT encrypted EPUB books.
Expand Down Expand Up @@ -271,7 +273,7 @@ class IgnobleDeDRM(FileTypePlugin):
Credit given to I <3 Cabbages for the original stand-alone scripts.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'DiapDealer'
version = (0, 1, 4)
version = (0, 1, 5)
minimum_calibre_version = (0, 6, 44) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub'])
on_import = True
Expand Down
36 changes: 16 additions & 20 deletions Calibre_Plugins/ignobleepub_plugin/zipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@
_EXTRA_LEN_OFFSET = 28
_FILENAME_OFFSET = 30
_MAX_SIZE = 64 * 1024
_MIMETYPE = 'application/epub+zip'

class ZipInfo(zipfile.ZipInfo):
def __init__(self, *args, **kwargs):
if 'compress_type' in kwargs:
compress_type = kwargs.pop('compress_type')
super(ZipInfo, self).__init__(*args, **kwargs)
self.compress_type = compress_type

class fixZip:
def __init__(self, zinput, zoutput):
self.ztype = 'zip'
if zinput.lower().find('.epub') >= 0 :
self.ztype = 'epub'
self.inzip = zipfile.ZipFile(zinput,'r')
self.outzip = zipfile.ZipFile(zoutput,'w')
# open the input zip for reading only as a raw file
Expand Down Expand Up @@ -81,30 +92,15 @@ def fix(self):
# get the zipinfo for each member of the input archive
# and copy member over to output archive
# if problems exist with local vs central filename, fix them
# also fix bad epub compression

# write mimetype file first, if present, and with no compression
for zinfo in self.inzip.infolist():
if zinfo.filename == "mimetype":
nzinfo = zinfo
try:
data = self.inzip.read(zinfo.filename)
except zipfile.BadZipfile or zipfile.error:
local_name = self.getlocalname(zinfo)
data = self.getfiledata(zinfo)
nzinfo.filename = local_name

nzinfo.date_time = zinfo.date_time
nzinfo.compress_type = zipfile.ZIP_STORED
nzinfo.flag_bits = 0
nzinfo.internal_attr = 0
nzinfo.extra = ""
self.outzip.writestr(nzinfo,data)
break
# if epub write mimetype file first, with no compression
if self.ztype == 'epub':
nzinfo = ZipInfo('mimetype', compress_type=zipfile.ZIP_STORED)
self.outzip.writestr(nzinfo, _MIMETYPE)

# write the rest of the files
for zinfo in self.inzip.infolist():
if zinfo.filename != "mimetype":
if zinfo.filename != "mimetype" or self.ztype == '.zip':
data = None
nzinfo = zinfo
try:
Expand Down
Binary file modified Calibre_Plugins/ineptepub_plugin.zip
Binary file not shown.
5 changes: 3 additions & 2 deletions Calibre_Plugins/ineptepub_plugin/ineptepub_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
# result of Calibre changing to python 2.7.
# 0.1.3 - bug fix for epubs with non-ascii chars in file names
# 0.1.4 - default to try PyCrypto first on Windows

# 0.1.5 - update zipfix to handle out of position mimetypes
# 0.1.6 - update zipfix to handle completely missing mimetype files

"""
Decrypt Adobe ADEPT-encrypted EPUB books.
Expand Down Expand Up @@ -371,7 +372,7 @@ class IneptDeDRM(FileTypePlugin):
Credit given to I <3 Cabbages for the original stand-alone scripts.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'DiapDealer'
version = (0, 1, 5)
version = (0, 1, 6)
minimum_calibre_version = (0, 6, 44) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['epub'])
on_import = True
Expand Down
36 changes: 16 additions & 20 deletions Calibre_Plugins/ineptepub_plugin/zipfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@
_EXTRA_LEN_OFFSET = 28
_FILENAME_OFFSET = 30
_MAX_SIZE = 64 * 1024
_MIMETYPE = 'application/epub+zip'

class ZipInfo(zipfile.ZipInfo):
def __init__(self, *args, **kwargs):
if 'compress_type' in kwargs:
compress_type = kwargs.pop('compress_type')
super(ZipInfo, self).__init__(*args, **kwargs)
self.compress_type = compress_type

class fixZip:
def __init__(self, zinput, zoutput):
self.ztype = 'zip'
if zinput.lower().find('.epub') >= 0 :
self.ztype = 'epub'
self.inzip = zipfile.ZipFile(zinput,'r')
self.outzip = zipfile.ZipFile(zoutput,'w')
# open the input zip for reading only as a raw file
Expand Down Expand Up @@ -81,30 +92,15 @@ def fix(self):
# get the zipinfo for each member of the input archive
# and copy member over to output archive
# if problems exist with local vs central filename, fix them
# also fix bad epub compression

# write mimetype file first, if present, and with no compression
for zinfo in self.inzip.infolist():
if zinfo.filename == "mimetype":
nzinfo = zinfo
try:
data = self.inzip.read(zinfo.filename)
except zipfile.BadZipfile or zipfile.error:
local_name = self.getlocalname(zinfo)
data = self.getfiledata(zinfo)
nzinfo.filename = local_name

nzinfo.date_time = zinfo.date_time
nzinfo.compress_type = zipfile.ZIP_STORED
nzinfo.flag_bits = 0
nzinfo.internal_attr = 0
nzinfo.extra = ""
self.outzip.writestr(nzinfo,data)
break
# if epub write mimetype file first, with no compression
if self.ztype == 'epub':
nzinfo = ZipInfo('mimetype', compress_type=zipfile.ZIP_STORED)
self.outzip.writestr(nzinfo, _MIMETYPE)

# write the rest of the files
for zinfo in self.inzip.infolist():
if zinfo.filename != "mimetype":
if zinfo.filename != "mimetype" or self.ztype == '.zip':
data = None
nzinfo = zinfo
try:
Expand Down
Binary file modified Calibre_Plugins/ineptpdf_plugin.zip
Binary file not shown.
39 changes: 28 additions & 11 deletions Calibre_Plugins/ineptpdf_plugin/ineptpdf_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
# ** NOTE ** There is no plugin customization data for the Inept PDF DeDRM plugin.
#
# Revision history:
# 0.1 - Initial release
# 0.1 - Initial release
# 0.1.1 - back port ineptpdf 8.4.X support for increased number of encryption methods
# 0.1.2 - back port ineptpdf 8.4.X bug fixes
# 0.1.3 - add in fix for improper rejection of session bookkeys with len(bookkey) = length + 1

"""
Decrypts Adobe ADEPT-encrypted PDF files.
Expand Down Expand Up @@ -1544,16 +1547,30 @@ def initialize_ebx(self, password, docid, param):
bookkey = bookkey[index:]
ebx_V = int_value(param.get('V', 4))
ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6))
# added because of the booktype / decryption book session key error
if ebx_V == 3:
V = 3
elif ebx_V < 4 or ebx_type < 6:
V = ord(bookkey[0])
bookkey = bookkey[1:]
# added because of improper booktype / decryption book session key errors
if length > 0:
if len(bookkey) == length:
if ebx_V == 3:
V = 3
else:
V = 2
elif len(bookkey) == length + 1:
V = ord(bookkey[0])
bookkey = bookkey[1:]
else:
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
print "bookkey[0] is %d" % ord(bookkey[0])
raise ADEPTError('error decrypting book session key - mismatched length')
else:
V = 2
if length and len(bookkey) != length:
raise ADEPTError('error decrypting book session key')
# proper length unknown try with whatever you have
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
print "bookkey[0] is %d" % ord(bookkey[0])
if ebx_V == 3:
V = 3
else:
V = 2
self.decrypt_key = bookkey
self.genkey = self.genkey_v3 if V == 3 else self.genkey_v2
self.decipher = self.decrypt_rc4
Expand Down Expand Up @@ -2116,7 +2133,7 @@ class IneptPDFDeDRM(FileTypePlugin):
Credit given to I <3 Cabbages for the original stand-alone scripts.'
supported_platforms = ['linux', 'osx', 'windows']
author = 'DiapDealer'
version = (0, 1, 2)
version = (0, 1, 3)
minimum_calibre_version = (0, 6, 44) # Compiled python libraries cannot be imported in earlier versions.
file_types = set(['pdf'])
on_import = True
Expand Down
Binary file modified Calibre_Plugins/k4mobidedrm_plugin.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions Calibre_Plugins/k4mobidedrm_plugin/k4mobidedrm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# and import that ZIP into Calibre using its plugin configuration GUI.


__version__ = '2.2'
__version__ = '2.3'

class Unbuffered:
def __init__(self, stream):
Expand Down Expand Up @@ -250,7 +250,7 @@ class K4DeDRM(FileTypePlugin):
Provided by the work of many including DiapDealer, SomeUpdates, IHeartCabbages, CMBDTC, Skindle, DarkReverser, ApprenticeAlf, etc.'
supported_platforms = ['osx', 'windows', 'linux'] # Platforms this plugin will run on
author = 'DiapDealer, SomeUpdates' # The author of this plugin
version = (0, 2, 2) # The version number of this plugin
version = (0, 2, 3) # The version number of this plugin
file_types = set(['prc','mobi','azw','azw1','tpz']) # The file types that this plugin will be applied to
on_import = True # Run this plugin during the import
priority = 210 # run this plugin before mobidedrm, k4pcdedrm, k4dedrm
Expand Down
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 2.1, Copyright © 2010–2011 by Apprentice Alf and others.</string>
<string>DeDRM 2.2, Copyright © 2010–2011 by Apprentice Alf and others.</string>
<key>CFBundleIconFile</key>
<string>droplet</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand All @@ -34,7 +34,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1</string>
<string>2.2</string>
<key>CFBundleSignature</key>
<string>dplt</string>
<key>LSMinimumSystemVersion</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def getData(self, path):
argres[j] = int(argres[j])
return result
def getGlyphDim(self, gly):
if self.gdpi[gly] == 0:
return 0, 0
maxh = (self.gh[gly] * self.dpi) / self.gdpi[gly]
maxw = (self.gw[gly] * self.dpi) / self.gdpi[gly]
return maxh, maxw
Expand Down Expand Up @@ -320,6 +322,18 @@ def generateBook(bookDir, raw, fixedimage):
print 'Processing Meta Data and creating OPF'
meta_array = getMetaArray(metaFile)

# replace special chars in title and authors like & < >
title = meta_array['Title']
title = title.replace('&','&amp;')
title = title.replace('<','&lt;')
title = title.replace('>','&gt;')
meta_array['Title'] = title
authors = meta_array['Authors']
authors = authors.replace('&','&amp;')
authors = authors.replace('<','&lt;')
authors = authors.replace('>','&gt;')
meta_array['Authors'] = authors

xname = os.path.join(xmlDir, 'metadata.xml')
metastr = ''
for key in meta_array:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env python
# ineptpdf.pyw, version 7.7
# ineptpdf.pyw, version 7.9

from __future__ import with_statement

Expand Down Expand Up @@ -33,6 +33,7 @@
# 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
# 7.9 - Bug fix for some session key errors when len(bookkey) > length required

"""
Decrypts Adobe ADEPT-encrypted PDF files.
Expand Down Expand Up @@ -1531,16 +1532,30 @@ def initialize_ebx(self, password, docid, param):
bookkey = bookkey[index:]
ebx_V = int_value(param.get('V', 4))
ebx_type = int_value(param.get('EBX_ENCRYPTIONTYPE', 6))
# added because of the booktype / decryption book session key error
if ebx_V == 3:
V = 3
elif ebx_V < 4 or ebx_type < 6:
V = ord(bookkey[0])
bookkey = bookkey[1:]
# added because of improper booktype / decryption book session key errors
if length > 0:
if len(bookkey) == length:
if ebx_V == 3:
V = 3
else:
V = 2
elif len(bookkey) == length + 1:
V = ord(bookkey[0])
bookkey = bookkey[1:]
else:
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
print "bookkey[0] is %d" % ord(bookkey[0])
raise ADEPTError('error decrypting book session key - mismatched length')
else:
V = 2
if length and len(bookkey) != length:
raise ADEPTError('error decrypting book session key')
# proper length unknown try with whatever you have
print "ebx_V is %d and ebx_type is %d" % (ebx_V, ebx_type)
print "length is %d and len(bookkey) is %d" % (length, len(bookkey))
print "bookkey[0] is %d" % ord(bookkey[0])
if ebx_V == 3:
V = 3
else:
V = 2
self.decrypt_key = bookkey
self.genkey = self.genkey_v3 if V == 3 else self.genkey_v2
self.decipher = self.decrypt_rc4
Expand Down
Loading

0 comments on commit 2bedd75

Please sign in to comment.