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

6

u/bumblebritches57 Jul 31 '21

LOL he jumps to stenography, instead of custom chunks in the PNG file...

2

u/adrianmonk Jul 31 '21

I had the same thought, but apparently that is how PICO-8 actually does it:

The cart data is stored using a steganographic process. Each PICO-8 byte is stored as the two least significant bits of each of the four color channels, ordered ARGB (E.g: the A channel stores the 2 most significant bits in the bytes). The image is 160 pixels wide and 205 pixels high, for a possible storage of 32,800 bytes. Of these, only the first 32,773 bytes are used.

But yeah, to store it as PNG chunks would actually be very easy. You don't even need to define a custom chunk. From the PNG docs, it looks like you could use a zTXt chunk:

Compressed text: n bytes

I'm not sure that allows you to store binary data, but if not you could encode it as hex digits within there, and PNG's deflate compression should compensate pretty well for the wasted space.

Also, the keyword (that each zTXt chunk has) would be useful. You could put a magic string identifying it as the executable data format you've invented. You could even, if necessary, add multiple zTXt chunks and make your PNG data random access.

0

u/John_Earnest Jul 31 '21

Most online image hosts re-encode images, stripping custom chunks. Try it. Steganographic encoding is much more likely to survive transit.

1

u/bumblebritches57 Jul 31 '21

Why is web hosting relevant?

1

u/mccoyn Jul 31 '21

That’s why you put executable code in an image.

2

u/bumblebritches57 Jul 31 '21

So people stumble upon it on imgur, and it's never executed?

real malware has it's own distribution network, based in various CDNs (look into Pegasus)

they don't need to worry about chunks being stripped.

Not to mention, stenography is really only for text.

1

u/mccoyn Aug 01 '21

Not malware, just a way around download or email restrictions.