From 875747ad7aab1cee8ce635a8f2af2ab5fc6aec0a Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 29 Sep 2018 23:37:54 +0200 Subject: Add zipany format. v1.6 --- PolyglotFile/__init__.py | 1 + PolyglotFile/polyglotpdfany.py | 2 -- PolyglotFile/polyglotzipany.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 PolyglotFile/polyglotzipany.py (limited to 'PolyglotFile') diff --git a/PolyglotFile/__init__.py b/PolyglotFile/__init__.py index e6f6416..4ece820 100644 --- a/PolyglotFile/__init__.py +++ b/PolyglotFile/__init__.py @@ -5,4 +5,5 @@ from .polyglotpdfzip import PolyglotPdfZip from .polyglotpdfany import PolyglotPdfAny from .polyglotzippdf import PolyglotZipPdf from .polyglotszippdf import PolyglotSZipPdf +from .polyglotzipany import PolyglotZipAny diff --git a/PolyglotFile/polyglotpdfany.py b/PolyglotFile/polyglotpdfany.py index 8b7289f..a441f2c 100644 --- a/PolyglotFile/polyglotpdfany.py +++ b/PolyglotFile/polyglotpdfany.py @@ -34,8 +34,6 @@ class PolyglotPdfAny(): with open(payload2filename, "rb") as f: self.payload2 = f.read() - self.buffer = bytearray() - def generate(self): k2stream = self.payload1 if len(k2stream) > 0: diff --git a/PolyglotFile/polyglotzipany.py b/PolyglotFile/polyglotzipany.py new file mode 100644 index 0000000..133db4a --- /dev/null +++ b/PolyglotFile/polyglotzipany.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +import logging + +''' + |-------------------------------| - + |---------- Payload 1 ----------K1 | J1 + |-------------------------------| - + |---- ZIP Local File Header ----K2 | + |-------------------------------| - + |---------- Payload 2-----------K3 | J2 + |-------------------------------| - + |---- ZIP Central Directory ----K4 | + |-------------------------------| | + |--- End of Central Directory --K5 | + |-------------------------------| | +''' + + +class PolyglotZipAny(): + from ZipFileTransformer import Zip + + def __init__(self, Zip, payload1filename, payload2filename): + self.buffer = bytearray() + self.zip = Zip + 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() + + def generate(self): + self.zip.add_data_to_file(self.payload1, self.payload2, True) + self.buffer = self.zip.buffer + + def write(self, filename): + fd = open(filename, "wb") + fd.write(self.buffer) + fd.close() -- cgit v1.2.3