diff options
Diffstat (limited to 'PolyglotFile')
-rw-r--r-- | PolyglotFile/__init__.py | 2 | ||||
-rw-r--r-- | PolyglotFile/polyglotpdfany.py (renamed from PolyglotFile/polyglotpdfraw.py) | 29 |
2 files changed, 21 insertions, 10 deletions
diff --git a/PolyglotFile/__init__.py b/PolyglotFile/__init__.py index 6800028..e6f6416 100644 --- a/PolyglotFile/__init__.py +++ b/PolyglotFile/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from .polyglotpdfzip import PolyglotPdfZip -from .polyglotpdfraw import PolyglotPdfRaw +from .polyglotpdfany import PolyglotPdfAny from .polyglotzippdf import PolyglotZipPdf from .polyglotszippdf import PolyglotSZipPdf diff --git a/PolyglotFile/polyglotpdfraw.py b/PolyglotFile/polyglotpdfany.py index c524788..8b7289f 100644 --- a/PolyglotFile/polyglotpdfraw.py +++ b/PolyglotFile/polyglotpdfany.py @@ -6,10 +6,12 @@ import logging |-------------------------------| - |--------- PDF Header ----------K1 | J1 |-------------------------------| - - |----- PDF OBJ 1 = RAW Data ----K2 | + |---- PDF OBJ 1 = Payload 1 ----K2 | |-------------------------------| - |---- Original PDF Ojbects -----K3 | J2 |-------------------------------| - + |-- PDF Last OBJ = Payload 2 ---K4 | + |-------------------------------| | |---------- Xref Table ---------| | |-------------------------------K5 | |----------- Trailer -----------| | @@ -17,21 +19,30 @@ import logging ''' -class PolyglotPdfRaw(): +class PolyglotPdfAny(): from PdfFileTransformer import Pdf - def __init__(self, Pdf, Raw_filename): + def __init__(self, Pdf, payload1filename, payload2filename): self.buffer = bytearray() self.pdf = Pdf - self.raw_filename = Raw_filename + self.payload1 = bytearray() + if payload1filename is not None: + with open(payload1filename, "rb") as f: + self.payload1 = f.read() + self.payload2 = bytearray() + if payload2filename is not None: + with open(payload2filename, "rb") as f: + self.payload2 = f.read() + self.buffer = bytearray() def generate(self): - raw_buffer = bytearray() - with open(self.raw_filename, "rb") as f: - raw_buffer = f.read() - k2_stream = raw_buffer - self.pdf.insert_new_obj_stream_at_start(k2_stream) + k2stream = self.payload1 + if len(k2stream) > 0: + self.pdf.insert_new_obj_stream_at_start(k2stream) + k4stream = self.payload2 + if len(k4stream) > 0: + self.pdf.insert_new_obj_stream_at_end(k4stream) self.buffer = self.pdf.get_build_buffer() def write(self, filename): |