diff options
author | ben | 2018-09-29 14:06:08 +0200 |
---|---|---|
committer | ben | 2018-09-29 14:06:08 +0200 |
commit | fc7e44a646462315effed63ad28f6ce0f3241ec9 (patch) | |
tree | 4108dc22f70170e5d9f189c02a2bc171beceaf89 /PolyglotFile/polyglotpdfany.py | |
parent | 04eb07f3210d91fadf6b75187bdc72ce713f587d (diff) | |
download | truepolyglot-fc7e44a646462315effed63ad28f6ce0f3241ec9.tar.gz truepolyglot-fc7e44a646462315effed63ad28f6ce0f3241ec9.tar.bz2 truepolyglot-fc7e44a646462315effed63ad28f6ce0f3241ec9.tar.xz |
Rename pdfraw to pdfany and allow 2 payloads. v1.5.21.5.2
Diffstat (limited to 'PolyglotFile/polyglotpdfany.py')
-rw-r--r-- | PolyglotFile/polyglotpdfany.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/PolyglotFile/polyglotpdfany.py b/PolyglotFile/polyglotpdfany.py new file mode 100644 index 0000000..8b7289f --- /dev/null +++ b/PolyglotFile/polyglotpdfany.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- + +import logging + +''' + |-------------------------------| - + |--------- PDF Header ----------K1 | J1 + |-------------------------------| - + |---- PDF OBJ 1 = Payload 1 ----K2 | + |-------------------------------| - + |---- Original PDF Ojbects -----K3 | J2 + |-------------------------------| - + |-- PDF Last OBJ = Payload 2 ---K4 | + |-------------------------------| | + |---------- Xref Table ---------| | + |-------------------------------K5 | + |----------- Trailer -----------| | + |-------------------------------| | +''' + + +class PolyglotPdfAny(): + from PdfFileTransformer import Pdf + + def __init__(self, Pdf, payload1filename, payload2filename): + self.buffer = bytearray() + self.pdf = Pdf + 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): + 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): + fd = open(filename, "wb") + fd.write(self.buffer) + fd.close() |