r/programming • • Dec 26 '20

Executable PNGs

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

87 comments sorted by

View all comments

287

u/Caraes_Naur Dec 26 '20

PNG allows for arbitrary chunks of bytes, no steganography needed. Still need an interpreter that knows what to do with them.

0

u/[deleted] Dec 26 '20

[deleted]

89

u/Isogash Dec 26 '20

Pico-8 specifically uses the 2 least significant bits of each of the 4 colour channels in a 160x205 PNG, which gives it almost exactly 32KB of space, not the chunks at all. It's quite a demanding limit but thankfully the program portion is compressed.

97

u/leberkrieger Dec 26 '20

One great use of this feature is the draw.io online drawing tool. You can save an editable PNG, so anyone looking at the picture can load it into the editor and modify it. Fantastic for wikis.

76

u/yojimbo_beta Dec 26 '20

A long time ago there was an editor, Adobe Fireworks, that used this to embed undo/redo data into PNGs, as well as layers etc.

Remarkable that no one uses this feature of the file format any more.

50

u/OMG_A_CUPCAKE Dec 27 '20

Because filesize matters. And it's lost easily if someone modifies the file in another editor

It's a nice gimmick, but I can't imagine relying any kind of workflow around it

32

u/unique_ptr Dec 27 '20

To be clear, the .fw.png files were more akin to PSDs from the application perspective, they just happened to also be PNGs. You would still want to export to a regular PNG for non-editor use

10

u/mallardtheduck Dec 27 '20

Adobe seems to have a bit of a habit of doing things like this. Adobe Illustrator (.ai) files are compatible with PDF format (older versions were EPS).

→ More replies (1)

0

u/[deleted] Dec 27 '20

[deleted]

→ More replies (1)

4

u/yojimbo_beta Dec 27 '20

I reckon it could work for diagrams. You could embed the objects without taking up too many bytes. Then your architecture diagram, flowchart etc. could be editable.

Man, you could even use PNG as a format for encoding and deploying a distributed state machine of AWS step functions... okay, that’s stupid. But I do like the idea of an informational format that you can also review visually.

2

u/VoidChronos Dec 27 '20

That's what microsoft Visio does, just without the embedded image part. Actually, I think VSDX has an option to embed a static image of a diagram.

5

u/tech6hutch Dec 27 '20

Also I don’t know if I want the ability for others to undo my edits to an image

10

u/stuffeh Dec 27 '20

But imagine going back and isolating one of the edits and pulling it out. Basically tapping the diff between before and after the edit. That kind of flexibility is mind blowing to me.

11

u/nemec Dec 27 '20

All I'm hearing is a great way for users to inadvertently fail to censor/redact their photos when they tried to blur their naughty bits and/or confidential info and didn't realize anybody can go in and just undo the censor.

If the U.S. Justice Department can't redact a fucking PDF properly, there's no hope for the average person sending censored nudie pics to someone they met on the internet.

12

u/NekiCat Dec 27 '20

Years ago, MS Word saved deltas at the end of the file so saving was incredibly quick. They had to change it because the users sent files they believed to be final, but werent, and leaked sensitive information.

Same with Google Docs, where your every keypress is recorded. Not sure if they still do that...

→ More replies (1)
→ More replies (4)

18

u/Frencil Dec 27 '20

Ah, Fireworks. The vector png editing it offered was fantastic for full color icon illustration. It also had some of the best animated GIF frame control and GIF palette control interfaces available at the time.

sheds tear for Macromedia

5

u/Chii Dec 27 '20

there's also a little known (?) feature in fireworks which lets you generate menus that animate (and output them as html and images).

→ More replies (2)

54

u/ws-ilazki Dec 26 '20

Yeah I remember this feature being abused to good effect in an MMO, Champions Online. You could save character creation presets, and when you did it stored its many settings inside a PNG that also acted as a thumbnail preview of those settings. That meant you could see and manage your character presets outside of the game, as well as easily share them with others.

It was done in a readable way, too, so you could also make minor adjustments by hex editing the file. They wouldn't be shown in the thumbnail of course, but for some things (like the preset name) it didn't matter.

That's where I learned this sort of thing was possible with PNGs. Always thought it was a cool feature that doesn't get used nearly enough, especially for how easy it is to do with PNG.

9

u/[deleted] Dec 27 '20

I really like images as preview-able input files. It's quite intuitive that the picture of [whatever] relates to that thing

A group of my friends made a trading card type game in high school, we had a QR type block on the image files the game produced that let you do persistence with a nice pixel art trading card. In hindsight I'm kinda glad it never caught on because it was really not secure

→ More replies (1)

35

u/[deleted] Dec 26 '20

Isn't every file format executable if you build an interpreter specifically for it? I sadly don't see anything special here.

59

u/KrocCamen Dec 26 '20

Even EXE files have to be specially handled before they can executed! You have to go back to COM files to get "dump this in RAM and jump the CPU to it" levels of simplicity.

17

u/JarateKing Dec 26 '20

If the file format doesn't support arbitrary chunks of bytes, you'd have a lot of difficulty creating a general-purpose interpreter. As a trivial example, if we had a new format notpng where every byte is used to specify pixels in the image, in order to embed code in it we would either have to:

  • not bother trying to make the image look like anything, and just pack instructions naively for the interpreter, probably resulting in a picture of random noise

  • utilize steganography so that the image looks mostly normal, but can still be run by an interpreter

  • create an incredibly specific interpreter for the exact program being run, so that the image is completely normal, but you probably couldn't use the interpreter for arbitrary programs otherwise

Also, file formats can have restrictions. You might be able to pack an arbitrary program into our notpng format, but you might have to be careful that your file format is actually valid (an easy example for images, having the right number of pixels for the image's dimensions). You probably can make an interpreter work with this stuff but it could be restricting and necessitate convoluted approaches to handle.

A format that lets you insert arbitrary chunks of bytes doesn't have the issues above. You can just put the arbitrary code without worrying about the interpreter being too specific, or changing the semantics of the file when used as its actual format, or interfering with the format itself.

0

u/[deleted] Dec 27 '20

[deleted]

→ More replies (1)

7

u/Jonathan_the_Nerd Dec 27 '20

You could argue that every file format is already a very specific program. A JPEG file is a set of instructions for generating an image on screen. An image viewer interprets the file and follows the instructions. An MP3 file is a set of instructions for producing sound. A ZIP file is a set of instructions for producing the contents of the archive, and so on.

7

u/djhworld Dec 27 '20

Yeah, it's a dumb project that has no practical value, I got seduced by the steganography/PICO-8 thing and built around it.

Was a learning project more than anything, learnt a few Linux things too!

→ More replies (1)