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?

  • 1
    What's a “Windows executable polyglot”? Can you give a reference? – egreg Feb 24 '14 at 21:36
  • @egreg edited with clarification – Ange Feb 24 '14 at 21:39
  • 1
    OMG WTF PDF. :-{ – Martin Schröder Feb 24 '14 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 '14 at 7:43

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:

  \immediate\pdfobj stream file{foo.bar}\relax

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

| 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 '14 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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