mirror of
https://github.com/noDRM/DeDRM_tools.git
synced 2024-12-29 04:37:39 +06:00
Correct user pass padding, fix PDFStream export
This commit is contained in:
parent
c11db59150
commit
80f511ade9
@ -867,6 +867,7 @@ class DeDRM(FileTypePlugin):
|
|||||||
elif pdf_encryption == "FOPN_fLock" or pdf_encryption == "FOPN_foweb":
|
elif pdf_encryption == "FOPN_fLock" or pdf_encryption == "FOPN_foweb":
|
||||||
print("{0} v{1}: FileOpen encryption '{2}' is unsupported.".format(PLUGIN_NAME, PLUGIN_VERSION, pdf_encryption))
|
print("{0} v{1}: FileOpen encryption '{2}' is unsupported.".format(PLUGIN_NAME, PLUGIN_VERSION, pdf_encryption))
|
||||||
print("{0} v{1}: Try the standalone script from the 'Tetrachroma_FileOpen_ineptpdf' folder in the Github repo.".format(PLUGIN_NAME, PLUGIN_VERSION))
|
print("{0} v{1}: Try the standalone script from the 'Tetrachroma_FileOpen_ineptpdf' folder in the Github repo.".format(PLUGIN_NAME, PLUGIN_VERSION))
|
||||||
|
return path_to_ebook
|
||||||
else:
|
else:
|
||||||
print("{0} v{1}: Encryption '{2}' is unsupported.".format(PLUGIN_NAME, PLUGIN_VERSION, pdf_encryption))
|
print("{0} v{1}: Encryption '{2}' is unsupported.".format(PLUGIN_NAME, PLUGIN_VERSION, pdf_encryption))
|
||||||
return path_to_ebook
|
return path_to_ebook
|
||||||
|
@ -67,6 +67,7 @@ from io import BytesIO
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import itertools
|
import itertools
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
|
import traceback
|
||||||
|
|
||||||
# Wrap a stream so that output gets flushed immediately
|
# Wrap a stream so that output gets flushed immediately
|
||||||
# and also make sure that any unicode strings get
|
# and also make sure that any unicode strings get
|
||||||
@ -1740,12 +1741,19 @@ class PDFDocument(object):
|
|||||||
k = b''.join(bytes([c ^ i]) for c in hash )
|
k = b''.join(bytes([c ^ i]) for c in hash )
|
||||||
x = ARC4.new(k).decrypt(x)
|
x = ARC4.new(k).decrypt(x)
|
||||||
|
|
||||||
# TODO: remove the padding string from the end of the data!
|
|
||||||
for ct in range(1, len(x)):
|
# "x" is now the padded user password.
|
||||||
new_x = x[:ct]
|
|
||||||
enc_key = self.check_user_password(new_x, docid, param)
|
# If we wanted to recover / extract the user password,
|
||||||
if enc_key is not None:
|
# we'd need to trim off the padding string from the end.
|
||||||
return enc_key
|
# As we just want to get access to the encryption key,
|
||||||
|
# we can just hand the password into the check_user_password
|
||||||
|
# as it is, as that function would be adding padding anyways.
|
||||||
|
# This trick only works with V4 and lower.
|
||||||
|
|
||||||
|
enc_key = self.check_user_password(x, docid, param)
|
||||||
|
if enc_key is not None:
|
||||||
|
return enc_key
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -2553,7 +2561,7 @@ class PDFSerializer(object):
|
|||||||
### are no longer useful, as we have extracted all objects from
|
### are no longer useful, as we have extracted all objects from
|
||||||
### them. Therefore leave them out from the output.
|
### them. Therefore leave them out from the output.
|
||||||
if obj.dic.get('Type') == LITERAL_OBJSTM and not gen_xref_stm:
|
if obj.dic.get('Type') == LITERAL_OBJSTM and not gen_xref_stm:
|
||||||
self.write('(deleted)')
|
self.write(b'(deleted)')
|
||||||
else:
|
else:
|
||||||
data = obj.get_decdata()
|
data = obj.get_decdata()
|
||||||
self.serialize_object(obj.dic)
|
self.serialize_object(obj.dic)
|
||||||
@ -2587,6 +2595,7 @@ def decryptBook(userkey, inpath, outpath, inept=True):
|
|||||||
serializer.dump(outf)
|
serializer.dump(outf)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error writing pdf: {0}".format(e))
|
print("error writing pdf: {0}".format(e))
|
||||||
|
traceback.print_exc()
|
||||||
return 2
|
return 2
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user