Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
200508be7f | ||
|
|
fc7e44a646 | ||
|
|
04eb07f321 | ||
|
|
caaaaafeb0 |
@@ -2,6 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from .polyglotpdfzip import PolyglotPdfZip
|
from .polyglotpdfzip import PolyglotPdfZip
|
||||||
|
from .polyglotpdfany import PolyglotPdfAny
|
||||||
from .polyglotzippdf import PolyglotZipPdf
|
from .polyglotzippdf import PolyglotZipPdf
|
||||||
from .polyglotszippdf import PolyglotSZipPdf
|
from .polyglotszippdf import PolyglotSZipPdf
|
||||||
|
|
||||||
|
|||||||
51
PolyglotFile/polyglotpdfany.py
Normal file
51
PolyglotFile/polyglotpdfany.py
Normal file
@@ -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()
|
||||||
@@ -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:]
|
||||||
|
|
||||||
|
|||||||
38
truepolyglot
38
truepolyglot
@@ -6,7 +6,10 @@ import logging
|
|||||||
|
|
||||||
from PdfFileTransformer import Pdf
|
from PdfFileTransformer import Pdf
|
||||||
from ZipFileTransformer import Zip
|
from ZipFileTransformer import Zip
|
||||||
from PolyglotFile import PolyglotZipPdf, PolyglotPdfZip, PolyglotSZipPdf
|
from PolyglotFile import PolyglotZipPdf
|
||||||
|
from PolyglotFile import PolyglotPdfZip
|
||||||
|
from PolyglotFile import PolyglotSZipPdf
|
||||||
|
from PolyglotFile import PolyglotPdfAny
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -17,9 +20,12 @@ def main():
|
|||||||
' 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.' +
|
||||||
' Archive is modified.')
|
' Archive is modified.\n' +
|
||||||
|
'* pdfany: Generate a valid PDF file with payload1' +
|
||||||
|
' file content as first object or/and payload2 file' +
|
||||||
|
' content as last oject.\n')
|
||||||
usage_str = '%(prog)s format [options] output-file'
|
usage_str = '%(prog)s format [options] output-file'
|
||||||
epilog_str = 'TruePolyglot v1.4.1'
|
epilog_str = 'TruePolyglot v1.5.3'
|
||||||
frm = argparse.RawTextHelpFormatter
|
frm = argparse.RawTextHelpFormatter
|
||||||
parser = argparse.ArgumentParser(description=description_str,
|
parser = argparse.ArgumentParser(description=description_str,
|
||||||
epilog=epilog_str,
|
epilog=epilog_str,
|
||||||
@@ -27,12 +33,17 @@ def main():
|
|||||||
formatter_class=frm)
|
formatter_class=frm)
|
||||||
parser.add_argument('format', nargs='+', choices=["pdfzip",
|
parser.add_argument('format', nargs='+', choices=["pdfzip",
|
||||||
"zippdf",
|
"zippdf",
|
||||||
"szippdf"],
|
"szippdf",
|
||||||
|
"pdfany"],
|
||||||
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')
|
||||||
parser.add_argument('--zipfile', dest='zipfile',
|
parser.add_argument('--zipfile', dest='zipfile',
|
||||||
help='ZIP input file')
|
help='ZIP input file')
|
||||||
|
parser.add_argument('--payload1file', dest='payload1file',
|
||||||
|
help='Payload 1 input file')
|
||||||
|
parser.add_argument('--payload2file', dest='payload2file',
|
||||||
|
help='Payload 2 input file')
|
||||||
parser.add_argument('--acrobat-compatibility',
|
parser.add_argument('--acrobat-compatibility',
|
||||||
dest='acrobat_compatibility',
|
dest='acrobat_compatibility',
|
||||||
help='Add a byte at start for Acrobat Reader compatibility with szippdf format',
|
help='Add a byte at start for Acrobat Reader compatibility with szippdf format',
|
||||||
@@ -46,14 +57,15 @@ def main():
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
formats = ["pdfzip", "zippdf", "szippdf"]
|
|
||||||
if args.acrobat_compatibility and args.format[0] != "szippdf":
|
if args.acrobat_compatibility and args.format[0] != "szippdf":
|
||||||
parser.error('--acrobat-compatibility is for szippdf only')
|
parser.error('--acrobat-compatibility is for szippdf only')
|
||||||
if args.format[0] in formats:
|
if "pdf" in args.format[0] and args.pdffile is None:
|
||||||
if args.pdffile is None:
|
|
||||||
parser.error('pdffile is required')
|
parser.error('pdffile is required')
|
||||||
if args.zipfile is None:
|
if "zip" in args.format[0] and args.zipfile is None:
|
||||||
parser.error('zipfile is required')
|
parser.error('zipfile is required')
|
||||||
|
if ("any" in args.format[0] and args.payload1file is None and
|
||||||
|
args.payload2file is None):
|
||||||
|
parser.error('payload1file or payload2file is required')
|
||||||
|
|
||||||
if args.verbose == "none":
|
if args.verbose == "none":
|
||||||
logging.basicConfig(level=logging.CRITICAL)
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
@@ -64,14 +76,22 @@ def main():
|
|||||||
if args.verbose == "debug":
|
if args.verbose == "debug":
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
if args.format[0] == "pdfzip":
|
||||||
p = Pdf(args.pdffile)
|
p = Pdf(args.pdffile)
|
||||||
z = Zip(args.zipfile)
|
z = Zip(args.zipfile)
|
||||||
if args.format[0] == "pdfzip":
|
|
||||||
a = PolyglotPdfZip(p, z)
|
a = PolyglotPdfZip(p, z)
|
||||||
if args.format[0] == "zippdf":
|
if args.format[0] == "zippdf":
|
||||||
|
p = Pdf(args.pdffile)
|
||||||
|
z = Zip(args.zipfile)
|
||||||
a = PolyglotZipPdf(p, z)
|
a = PolyglotZipPdf(p, z)
|
||||||
if args.format[0] == "szippdf":
|
if args.format[0] == "szippdf":
|
||||||
|
p = Pdf(args.pdffile)
|
||||||
|
z = Zip(args.zipfile)
|
||||||
a = PolyglotSZipPdf(p, z, args.acrobat_compatibility)
|
a = PolyglotSZipPdf(p, z, args.acrobat_compatibility)
|
||||||
|
if args.format[0] == "pdfany":
|
||||||
|
p = Pdf(args.pdffile)
|
||||||
|
a = PolyglotPdfAny(p, 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