Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to generate a PDF file via PDFTeX that is also a Windows Executable at the same time (the resulting file is a polyglot).

For this, I need the PDF file, among other thing, to start with the 'MZ' letters.

Can I do that via a specific macro or package?

share|improve this question
1  
What's a “Windows executable polyglot”? Can you give a reference? –  egreg Feb 24 at 21:36
    
@egreg edited with clarification –  Ange Feb 24 at 21:39
1  
OMG WTF PDF. :-{ –  Martin Schröder Feb 24 at 21:57
    
@MartinSchröder (my page on the topic)[pdf.corkami.com]. I also made a bootable PDF (PoC||GTFO 0x02). –  Ange Feb 25 at 7:43
add comment

1 Answer

Your "polyglot" is not a valid PDF file. A canonical PDF file starts with the PDF header (%PDF-1.x). However Acrobat Reader and some other PDF viewers are less strict, from the implementation notes in the PDF specification:

3.4.1, "File Header"
13. Acrobat viewers require only that the header appear somewhere within the first 1024 bytes of the file.

A canonical PDF file ends with %%EOF in the last line. Again, Acrobat Reader is less strict:

3.4.4, "File Trailer"
18. Acrobat viewers require only that the %%EOF marker appear somewhere within the last 1024 bytes of the file.

Thus there is some room to add a wrapper for other formats.

However, you cannot add something at the beginning or the end with pdfTeX. But something can be added inside the PDF file:

\begingroup
  \pdfcompresslevel=0\relax
  \immediate\pdfobj stream file{foo.bar}\relax
\endgroup

Then the contents of file foo.bar can be found uncompressed inside the PDF file.

share|improve this answer
    
It is a valid file from my (malware analyst) perspective: it's rendered as expected, without any errors, by all readers (linux ones, sumatra, firefox, chrome, adobe). –  Ange Feb 25 at 7:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.