This blog is highly personal, makes no attempt at being politically correct, will occasionaly offend your sensibility, and certainly does not represent the opinions of the people I work with or for.
ωFS nslog(png)
avatar
I said I would do it, so I did. This morning I wrote a small command line utility to inject an arbitrary amount of data (text or binary), into a PNG file. (There are --expensive-- commercial tools to do that but they are all GUI based, meaning freaking useless)

The first step was actually to write another command line utility which transforms a PNG file into a textual representation. You can then "hack" the textual representation and convert it back to PNG. In principle there is no need for such a complicated approach (as hacking the PNG binary format itself is trivial -- I even didn't have to go to the formal specification, the wikipedia page was good enough to understand), but this transformation was a good opportunity for me to show to myself that I understood how PNG works.

The following picture, for instance





is textually represented as


#nslog(png)

IHDR {
00000080000000440802000000
}

IDAT {
785EEDD48106C3301440D1B734DDFFFF
6FB37456EA89126C2873E2AA34490387
D6FED87B89BB528D3B87FE0100800000
10000002004000000800000100200000
04008000001000000200400000080000
010020000000D45E6A644B94F5987CD1
F4925C5C3ECF9C3F7371585FAF8B795B
EE96B647EBF1EAD1CEB6E3753BE6B995
8DC7CE0339C9AFC633937B6637CFABBF
F9C92F08800000100000020040000008
00000100200000040080000010000002
0040000008000001002000008C37DB68
0320
}

IEND


"#nslog(png)" is my way of saying that the file is a PNG dump, also note that the textual representation seems relatively short given the apparent complexity of the picture, but that picture (taken from the wikipedia page) was chosen to show some properties of PNG.

Of, course, I have to mention that the idea of the textual representation was taken from SNG (Scriptable Network Graphics) by Raymond. I would have used the sng command line tool, but it didn't compile on the Mac, so I wrote one. The conversion from the text representation to PNG only requires to recompute the length of the data chunks (in case you changed something), and recompute the CRCs (easy). The main interest being not really to change what was already there, but to add your own proprietary chunks.

I let you guess how that all thing will be used for new storage protocols in ωFS (^.^)

Now might actually be a good time to go and check few image sharing websites terms of use...

[ add a comment ]

Archives