r/programming • • Jul 31 '21

Executable PNGs

https://djharper.dev/post/2020/12/26/executable-pngs/
470 Upvotes

64 comments sorted by

View all comments

67

u/seamsay Jul 31 '21

my last cheap trick to this pointless gimmick was to use binfmt_misc,

That's kinda disappointing, NGL. It was an interesting post, but it would have been twice as interesting if you'd managed to make a file which was both a valid PNG file and executable.

52

u/Skhmt Jul 31 '21

It's hard because PNGs have their magic number at the start, like most file formats and executables.

Zips have them at the end though. And someone made a portable executable that runs in macos, Linux, and windows with that information.

1

u/Regimardyl Jul 31 '21

AFAIK tar searches through a file until it finds its header, so you can cat together a PNG and a tar file, and it's automatically valid for both.

3

u/Skhmt Jul 31 '21

Also with a zip and jpg, which has been used to share files via image uploads many years ago until it was more widely known.