We’ve been aware of projects like Cosmopolitan that allow you to crank out a single executable that will run on different operating systems. [Kamila] noticed that the idea was sound, but that the executables were large and there were some limitations. So she produced a 13K file that will run under Windows, Linux, or even in a Web browser. The program itself is a simple snake game.
There seems to be little sharing between the three versions. Instead, each version is compressed and stitched together so that each platform sees what it wants to see. To accommodate Windows, the file has to start with a PE header. However, there is enough flexibility in the header that part of the stub forms a valid shell script that skips over the Windows code when running under Linux.
So, essentially, Windows skips the “garbage” in the header, which is the part that makes Linux skip the “garbage” in the front of the file.
That leaves the browser. Browsers will throw away everything before an <HTML> tag, so that’s the easy part.
Should you do this? Probably not. But if you needed to make this happen, this is a clear template for how to do it. If you want to go back to [Kamila’s] inspiration, we’ve covered Cosmopolitan and its APE format before.

I like llamacpp (llamafile from mozilla) and whisper
ideal for carring AI in pendrive
This sound as a good way to distribute multiplatform malware as mail attachment :-(
Well Vivaldi blocks its download as a virus, probably because of the malformed headers.
Nice work. That’s using your head(ers) ๐
Now let’s use the MZ header part on top of of any Windows PE file and add some DOS code, too! ๐
Can you elabotate more on this? it sounds to me like bypassing shell and using dos-era instructions that no loger run in win enviroment?
Hi, sure! Normally, Windows executables have an MZ stub which displays “This program requires MS Windows!” on DOS, so it wouldn’t crash the PC if accidently run on plain DOS.
Both Win16 (NE) and Win32 (PE) applications had that MZ stub.
On 16-Bit Windows there also were hybrid applications, such as setup.exe (Windows Setup) inside Windows directory.
Instead of a short message these programs contained both full Windows 3.x and MS-DOS applications.
On 16-Bit OS/2, there also were MZ/NE hybrid applications. The socalled “Family API” applications.
Here, the MZ part contained an OS/2 runtime for DOS that would run the OS/2 application in the NE part of same EXE file.
That way, same application ran on an 8088 based PC/XT in Real-Mode and on an 80286/80386 based PC/AT in 16-Bit Protected-Mode, including the advantage of multitasking, virtual memory and memory protection.
The draw-back was that those hybrid applications were fatter and more memory hungry.
And the OS/2 runtime was more limited than real OS/2, of course.
Thank you very much for the insight! Of course, the imagination runs wild haha!!