Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions DeDRM_plugin/ineptpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@
# 10.0.0 - Add support for "hardened" Adobe DRM (RMSDK >= 10)
# 10.0.2 - Fix some Python2 stuff
# 10.0.4 - Fix more Python2 stuff
# 10.0.5 - modified PDFStream object to decrypt included dictionary

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

__license__ = 'GPL v3'
__version__ = "10.0.4"
__version__ = "10.0.5"

import codecs
import hashlib
Expand Down Expand Up @@ -913,6 +914,7 @@ def __init__(self, dic, rawdata, decipher=None):
self.decipher = decipher
self.data = None
self.decdata = None
self.decdic = None
self.objid = None
self.genno = None
return
Expand All @@ -931,13 +933,15 @@ def __repr__(self):
(self.objid, len(self.data), self.dic)

def decode(self):
assert self.data is None and self.rawdata is not None
assert self.data is None and self.rawdata is not None and self.dic is not None
data = self.rawdata
if self.decipher:
# Handle encryption
data = self.decipher(self.objid, self.genno, data)
dic = decipher_all(self.decipher, self.objid, self.genno, self.dic)
if gen_xref_stm:
self.decdata = data # keep decrypted data
self.decdic = dic # keep decrypted dic
if 'Filter' not in self.dic:
self.data = data
self.rawdata = None
Expand Down Expand Up @@ -1008,7 +1012,15 @@ def get_decdata(self):
# Handle encryption
data = self.decipher(self.objid, self.genno, data)
return data


def get_decdic(self):
if self.decdic is not None:
return self.decdic
dic = self.dic
if self.decipher and dic:
# Handle encryption
dic = decipher_all(self.decipher, self.objid, self.genno, dic)
return dic

## PDF Exceptions
##
Expand Down Expand Up @@ -2304,6 +2316,7 @@ def serialize_object(self, obj):
self.write(b'(deleted)')
else:
data = obj.get_decdata()
dic = obj.get_decdic()

# Fix length:
# We've decompressed and then recompressed the PDF stream.
Expand All @@ -2314,11 +2327,11 @@ def serialize_object(self, obj):
# Without this change, all PDFs exported by this plugin are slightly corrupted -
# even though most if not all PDF readers can correct that on-the-fly.

if 'Length' in obj.dic:
obj.dic['Length'] = len(data)
if 'Length' in dic:
dic['Length'] = len(data)


self.serialize_object(obj.dic)
self.serialize_object(dic)
self.write(b'stream\n')
self.write(data)
self.write(b'\nendstream')
Expand Down