Update PDF to use Decimal instead of float to handle very precise numbers. Update for changes to ActiveState Python. Fix a few copyright dates. Update version to 6.5.4. Minor changes to obok script for stand-alone use.

This commit is contained in:
Apprentice Harper
2017-06-27 06:50:24 +01:00
parent 9bea20c7ab
commit 2042354788
23 changed files with 195 additions and 110 deletions

View File

@@ -29,8 +29,9 @@
# 6.5.1 - Version bump to match plugin & Mac app
# 6.5.2 - Fix for a new tag in Topaz ebooks
# 6.5.3 - Explicitly warn about KFX files
# 6.5.4 - PDF float fix.
__version__ = '6.5.3'
__version__ = '6.5.4'
import sys
import os, os.path

View File

@@ -57,6 +57,7 @@ __docformat__ = 'restructuredtext en'
# 6.5.1 - Updated version number, added PDF check for DRM-free documents
# 6.5.2 - Another Topaz fix
# 6.5.3 - Warn about KFX files explicitly
# 6.5.4 - Mac App Fix, improve PDF decryption, handle latest tcl changes in ActivePython
"""
@@ -64,7 +65,7 @@ Decrypt DRMed ebooks.
"""
PLUGIN_NAME = u"DeDRM"
PLUGIN_VERSION_TUPLE = (6, 5, 3)
PLUGIN_VERSION_TUPLE = (6, 5, 4)
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'

View File

@@ -3,13 +3,14 @@
from __future__ import with_statement
# ignobleepub.pyw, version 3.8
# ignobleepub.pyw, version 4.1
# Copyright © 2009-2010 by i♥cabbages
# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>
# Modified 20102013 by some_updates, DiapDealer and Apprentice Alf
# Modified 20152017 by Apprentice Harper
# Windows users: Before running this program, you must first install Python 2.6
# from <http://www.python.org/download/> and PyCrypto from
@@ -35,13 +36,14 @@ from __future__ import with_statement
# 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
# 4.0 - Work if TkInter is missing
# 4.1 - Import tkFileDialog, don't assume something else will import it.
"""
Decrypt Barnes & Noble encrypted ePub books.
"""
__license__ = 'GPL v3'
__version__ = "4.0"
__version__ = "4.1"
import sys
import os
@@ -337,6 +339,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:

View File

@@ -3,14 +3,14 @@
from __future__ import with_statement
# ineptepub.pyw, version 6.5
# ineptepub.pyw, version 6.6
# Copyright © 2009-2010 by i♥cabbages
# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>
# Modified 20102013 by some_updates, DiapDealer and Apprentice Alf
# Modified 20152016 by Apprentice Harper
# Modified 20152017 by Apprentice Harper
# Windows users: Before running this program, you must first install Python 2.7
# from <http://www.python.org/download/> and PyCrypto from
@@ -42,13 +42,14 @@ from __future__ import with_statement
# 6.3 - Add additional check on DER file sanity
# 6.4 - Remove erroneous check on DER file sanity
# 6.5 - Completely remove erroneous check on DER file sanity
# 6.6 - Import tkFileDialog, don't assume something else will import it.
"""
Decrypt Adobe Digital Editions encrypted ePub books.
"""
__license__ = 'GPL v3'
__version__ = "6.5"
__version__ = "6.6"
import sys
import os
@@ -484,6 +485,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:

View File

@@ -3,14 +3,14 @@
from __future__ import with_statement
# ineptpdf.pyw, version 8.0.4
# ineptpdf.pyw, version 8.0.6
# Copyright © 2009-2010 by i♥cabbages
# Released under the terms of the GNU General Public Licence, version 3
# <http://www.gnu.org/licenses/>
# Modified 20102012 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015-2016 by Apprentice Harper
# Modified 2015-2017 by Apprentice Harper
# Windows users: Before running this program, you must first install Python 2.7
# from <http://www.python.org/download/> and PyCrypto from
@@ -58,6 +58,7 @@ from __future__ import with_statement
# 8.0.3 - Remove erroneous check on DER file sanity
# 8.0.4 - Completely remove erroneous check on DER file sanity
# 8.0.5 - Do not process DRM-free documents
# 8.0.6 - Replace use of float by Decimal for greater precision, and import tkFileDialog
"""
@@ -65,7 +66,7 @@ Decrypts Adobe ADEPT-encrypted PDF files.
"""
__license__ = 'GPL v3'
__version__ = "8.0.5"
__version__ = "8.0.6"
import sys
import os
@@ -73,6 +74,7 @@ import re
import zlib
import struct
import hashlib
from decimal import *
from itertools import chain, islice
import xml.etree.ElementTree as etree
@@ -653,7 +655,7 @@ class PSBaseParser(object):
return (self.parse_number, j+1)
if c == '.':
self.token = c
return (self.parse_float, j+1)
return (self.parse_decimal, j+1)
if c.isalpha():
self.token = c
return (self.parse_keyword, j+1)
@@ -718,20 +720,21 @@ class PSBaseParser(object):
c = s[j]
if c == '.':
self.token += c
return (self.parse_float, j+1)
return (self.parse_decimal, j+1)
try:
self.add_token(int(self.token))
except ValueError:
pass
return (self.parse_main, j)
def parse_float(self, s, i):
def parse_decimal(self, s, i):
m = END_NUMBER.search(s, i)
if not m:
self.token += s[i:]
return (self.parse_float, len(s))
return (self.parse_decimal, len(s))
j = m.start(0)
self.token += s[i:j]
self.add_token(float(self.token))
self.add_token(Decimal(self.token))
return (self.parse_main, j)
def parse_keyword(self, s, i):
@@ -933,7 +936,7 @@ class PSStackParser(PSBaseParser):
(pos, token) = self.nexttoken()
##print (pos,token), (self.curtype, self.curstack)
if (isinstance(token, int) or
isinstance(token, float) or
isinstance(token, Decimal) or
isinstance(token, bool) or
isinstance(token, str) or
isinstance(token, PSLiteral)):
@@ -1062,17 +1065,17 @@ def int_value(x):
return 0
return x
def float_value(x):
def decimal_value(x):
x = resolve1(x)
if not isinstance(x, float):
if not isinstance(x, Decimal):
if STRICT:
raise PDFTypeError('Float required: %r' % x)
raise PDFTypeError('Decimal required: %r' % x)
return 0.0
return x
def num_value(x):
x = resolve1(x)
if not (isinstance(x, int) or isinstance(x, float)):
if not (isinstance(x, int) or isinstance(x, Decimal)):
if STRICT:
raise PDFTypeError('Int or Float required: %r' % x)
return 0
@@ -2142,7 +2145,11 @@ class PDFSerializer(object):
if self.last.isalnum():
self.write(' ')
self.write(str(obj).lower())
elif isinstance(obj, (int, long, float)):
elif isinstance(obj, (int, long)):
if self.last.isalnum():
self.write(' ')
self.write(str(obj))
elif isinstance(obj, Decimal):
if self.last.isalnum():
self.write(' ')
self.write(str(obj))
@@ -2218,6 +2225,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:

View File

@@ -4,7 +4,7 @@
from __future__ import with_statement
# kindlekey.py
# Copyright © 2010-2016 by some_updates, Apprentice Alf and Apprentice Harper
# Copyright © 2010-2017 by some_updates, Apprentice Alf and Apprentice Harper
# Revision history:
# 1.0 - Kindle info file decryption, extracted from k4mobidedrm, etc.
@@ -22,6 +22,7 @@ from __future__ import with_statement
# 2.1 - Fixed Kindle for PC encryption changes March 2016
# 2.2 - Fixes for Macs with bonded ethernet ports
# Also removed old .kinfo file support (pre-2011)
# 2.3 - Added more field names thanks to concavegit's KFX code.
"""
@@ -29,7 +30,7 @@ Retrieve Kindle for PC/Mac user key.
"""
__license__ = 'GPL v3'
__version__ = '2.2'
__version__ = '2.3'
import sys, os, re
from struct import pack, unpack, unpack_from
@@ -1010,8 +1011,11 @@ if iswindows:
'max_date',\
'SIGVERIF',\
'build_version',\
'SerialNumber',\
'UsernameHash',\
'kindle.directedid.info',\
'DSN'
]
DB = {}
with open(kInfoFile, 'rb') as infoReader:
data = infoReader.read()
@@ -1447,6 +1451,10 @@ elif isosx:
'max_date',\
'SIGVERIF',\
'build_version',\
'SerialNumber',\
'UsernameHash',\
'kindle.directedid.info',\
'DSN'
]
with open(kInfoFile, 'rb') as infoReader:
filedata = infoReader.read()