Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
875747ad7a | ||
|
|
200508be7f |
@@ -5,4 +5,5 @@ from .polyglotpdfzip import PolyglotPdfZip
|
|||||||
from .polyglotpdfany import PolyglotPdfAny
|
from .polyglotpdfany import PolyglotPdfAny
|
||||||
from .polyglotzippdf import PolyglotZipPdf
|
from .polyglotzippdf import PolyglotZipPdf
|
||||||
from .polyglotszippdf import PolyglotSZipPdf
|
from .polyglotszippdf import PolyglotSZipPdf
|
||||||
|
from .polyglotzipany import PolyglotZipAny
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ class PolyglotPdfAny():
|
|||||||
with open(payload2filename, "rb") as f:
|
with open(payload2filename, "rb") as f:
|
||||||
self.payload2 = f.read()
|
self.payload2 = f.read()
|
||||||
|
|
||||||
self.buffer = bytearray()
|
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
k2stream = self.payload1
|
k2stream = self.payload1
|
||||||
if len(k2stream) > 0:
|
if len(k2stream) > 0:
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ class PolyglotSZipPdf(PolyglotPdfZip):
|
|||||||
k2_stream_offset = new_pdf.get_first_stream_offset()
|
k2_stream_offset = new_pdf.get_first_stream_offset()
|
||||||
|
|
||||||
new_pdf.file_offset = offset
|
new_pdf.file_offset = offset
|
||||||
|
if self.acrobat_compatibility:
|
||||||
|
new_pdf.file_offset = new_pdf.file_offset + 1
|
||||||
pdf_buffer = new_pdf.get_build_buffer()
|
pdf_buffer = new_pdf.get_build_buffer()
|
||||||
j2 = pdf_buffer[k2_stream_offset + size_k2_stream:]
|
j2 = pdf_buffer[k2_stream_offset + size_k2_stream:]
|
||||||
|
|
||||||
|
|||||||
42
PolyglotFile/polyglotzipany.py
Normal file
42
PolyglotFile/polyglotzipany.py
Normal file
@@ -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()
|
||||||
22
truepolyglot
22
truepolyglot
@@ -10,6 +10,8 @@ from PolyglotFile import PolyglotZipPdf
|
|||||||
from PolyglotFile import PolyglotPdfZip
|
from PolyglotFile import PolyglotPdfZip
|
||||||
from PolyglotFile import PolyglotSZipPdf
|
from PolyglotFile import PolyglotSZipPdf
|
||||||
from PolyglotFile import PolyglotPdfAny
|
from PolyglotFile import PolyglotPdfAny
|
||||||
|
from PolyglotFile import PolyglotZipAny
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -19,13 +21,18 @@ def main():
|
|||||||
'* zippdf: Generate a file valid as ZIP and PDF.' +
|
'* zippdf: Generate a file valid as ZIP and PDF.' +
|
||||||
' The format is closest to ZIP.\n' +
|
' The format is closest to ZIP.\n' +
|
||||||
'* szippdf: Generate a file valid as ZIP and PDF.' +
|
'* szippdf: Generate a file valid as ZIP and PDF.' +
|
||||||
' The format is strictly a ZIP.' +
|
' The format is strictly a ZIP.\n' +
|
||||||
' Archive is modified.\n' +
|
' Archive is modified.\n' +
|
||||||
'* pdfany: Generate a valid PDF file with payload1' +
|
'* pdfany: Generate a valid PDF file with payload1' +
|
||||||
' file content as first object or/and payload2 file' +
|
' file content as first object\n' +
|
||||||
' content as last oject.\n')
|
' or/and payload2 file' +
|
||||||
|
' content as last oject.\n' +
|
||||||
|
'* zipany: Generate a valid ZIP file with payload1' +
|
||||||
|
' file content at start of file\n' +
|
||||||
|
' or/and payload2 file content beetween' +
|
||||||
|
' LFH and CD.\n')
|
||||||
usage_str = '%(prog)s format [options] output-file'
|
usage_str = '%(prog)s format [options] output-file'
|
||||||
epilog_str = 'TruePolyglot v1.5.2'
|
epilog_str = 'TruePolyglot v1.6'
|
||||||
frm = argparse.RawTextHelpFormatter
|
frm = argparse.RawTextHelpFormatter
|
||||||
parser = argparse.ArgumentParser(description=description_str,
|
parser = argparse.ArgumentParser(description=description_str,
|
||||||
epilog=epilog_str,
|
epilog=epilog_str,
|
||||||
@@ -34,7 +41,8 @@ def main():
|
|||||||
parser.add_argument('format', nargs='+', choices=["pdfzip",
|
parser.add_argument('format', nargs='+', choices=["pdfzip",
|
||||||
"zippdf",
|
"zippdf",
|
||||||
"szippdf",
|
"szippdf",
|
||||||
"pdfany"],
|
"pdfany",
|
||||||
|
"zipany"],
|
||||||
help='Output polyglot format')
|
help='Output polyglot format')
|
||||||
parser.add_argument('--pdffile', dest='pdffile',
|
parser.add_argument('--pdffile', dest='pdffile',
|
||||||
help='PDF input file')
|
help='PDF input file')
|
||||||
@@ -91,6 +99,10 @@ def main():
|
|||||||
if args.format[0] == "pdfany":
|
if args.format[0] == "pdfany":
|
||||||
p = Pdf(args.pdffile)
|
p = Pdf(args.pdffile)
|
||||||
a = PolyglotPdfAny(p, args.payload1file, args.payload2file)
|
a = PolyglotPdfAny(p, args.payload1file, args.payload2file)
|
||||||
|
if args.format[0] == "zipany":
|
||||||
|
z = Zip(args.zipfile)
|
||||||
|
a = PolyglotZipAny(z, args.payload1file, args.payload2file)
|
||||||
|
|
||||||
|
|
||||||
a.generate()
|
a.generate()
|
||||||
a.write(args.output_file[0])
|
a.write(args.output_file[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user