Skip to content

Commit

Permalink
Update PDF to use Decimal instead of float to handle very precise num…
Browse files Browse the repository at this point in the history
…bers. 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.
  • Loading branch information
apprenticeharper committed Jun 27, 2017
1 parent 9bea20c commit 2042354
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@
# 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


"""
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2010–2013 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015–2017 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
Expand All @@ -35,13 +36,14 @@
# 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
Expand Down Expand Up @@ -337,6 +339,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2010–2013 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
Expand Down Expand Up @@ -42,13 +42,14 @@
# 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
Expand Down Expand Up @@ -484,6 +485,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2010–2012 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
Expand Down Expand Up @@ -58,21 +58,23 @@
# 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


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

__license__ = 'GPL v3'
__version__ = "8.0.5"
__version__ = "8.0.6"

import sys
import os
import re
import zlib
import struct
import hashlib
from decimal import *
from itertools import chain, islice
import xml.etree.ElementTree as etree

Expand Down Expand Up @@ -653,7 +655,7 @@ def parse_main(self, s, i):
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)
Expand Down Expand Up @@ -718,20 +720,21 @@ def parse_number(self, s, i):
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):
Expand Down Expand Up @@ -933,7 +936,7 @@ def nextobject(self, direct=False):
(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)):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2142,7 +2145,11 @@ def serialize_object(self, obj):
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))
Expand Down Expand Up @@ -2218,6 +2225,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,14 +22,15 @@
# 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.


"""
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
Expand Down Expand Up @@ -1010,8 +1011,11 @@ def getDBfromFile(kInfoFile):
'max_date',\
'SIGVERIF',\
'build_version',\
'SerialNumber',\
'UsernameHash',\
'kindle.directedid.info',\
'DSN'
]

DB = {}
with open(kInfoFile, 'rb') as infoReader:
data = infoReader.read()
Expand Down Expand Up @@ -1447,6 +1451,10 @@ def getDBfromFile(kInfoFile):
'max_date',\
'SIGVERIF',\
'build_version',\
'SerialNumber',\
'UsernameHash',\
'kindle.directedid.info',\
'DSN'
]
with open(kInfoFile, 'rb') as infoReader:
filedata = infoReader.read()
Expand Down
3 changes: 2 additions & 1 deletion DeDRM_Windows_Application/DeDRM_App/DeDRM_lib/DeDRM_App.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@
# 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


"""
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2010–2013 by some_updates, DiapDealer and Apprentice Alf
# Modified 2015–2017 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
Expand All @@ -35,13 +36,14 @@
# 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
Expand Down Expand Up @@ -337,6 +339,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2010–2013 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
Expand Down Expand Up @@ -42,13 +42,14 @@
# 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
Expand Down Expand Up @@ -484,6 +485,7 @@ def gui_main():
try:
import Tkinter
import Tkconstants
import tkFileDialog
import tkMessageBox
import traceback
except:
Expand Down
Loading

0 comments on commit 2042354

Please sign in to comment.