I realized that it was possible to create polyglot files1 when I searched for the details of the structure of a zip file (Archived) and found that the file header in this case is at the end of the file, and thus can easily coexist within an executable file, whose headers are usually at the start.

I later found out the existence of PoC||GTFO (Archived) and all other variously realized polyglot files, which usually are much more involved than simply having one header at the start and another one at the end, and many of which also have a sort of recursive madness (like a PDF which is a Git repository containing its own LaTeX source and a copy of itself (Archived)).

Another incredible polyglot project is Actually Portable Executable (Archived), a magic where a file is built which is a valid executable under Windows, Linux and MacOS (and BIOS), even though only for a single architecture (at least for now).

So an idea that I have seen arising multiple times is that of combining the two and create an executable program for all major platforms which also has a zip file-structure at the end, and that modifies the zip as if it were a filesystem to provide a persistence layer inside of a single file.

In this way one would realize the utopia of a single self-contained file that can be seamlessly moved from one computer to another one preserving both the fact that it is executable and its own data, which would actually be awesome.

As a bonus one can actually include a PDF into such mix which could store the documentation for the usage of the program. But maybe I'm getting too far...

If I picked your interest in this file madness I can recommend you those interesting references:

Footnotes

  1. Files that are valid in more than one format. For example, a file may be both a valid ZIP and a valid PDF (Archived).