An iOS Artwork Tool Update

I’ve updated my iOS Artwork Extractor to support iOS 4.2.1.

If you haven’t seen it, the artwork extractor is capable of exporting images to and from the .artwork archive files found in the iOS SDK.

Normally I wouldn’t remark on an update to this tool, but things changed significantly in iOS 4.2.1; this necessitated some larger changes to my tool.

The easy bit of the tool is the script you’ll actually use: Provided the .artwork file in question is supported (that is, has a corresponding JSON data file in the supported_artwork_files directory), getting PNGs out of SDK files is a snap.

The interesting — and new — bit of code is in how I generate the JSON files. I used to generate these by popping open a hex editor and looking for bits of the UIKit binary that appeared to contain an array of image dimensions. This was painfully slow, though it did work.

Starting with iOS 4.2.1, I’ve taken a more principled approach. The UIKit binary is a Mach-O executable file, so I wrote some python tools to take advantage of this. I built on top of macholib, a Python library for reading Mach-O headers. While macholib reads headers, it offers no support for reading symbol tables or making sense of the constant data structures that C/Objective-C dump into the binaries. My symbol table code is capable of finding data for all symbols, including un-exported symbols; a little poking around showed me that __sharedImagesPhone and __sharedImagesPad were the symbols to look for. After a tiny bit of further work figuring out the relevant data structures, I had a working tool that not only finds image sizes, but also finds their offsets and names.

Anyway, it was a fun hack and I hope you find it useful.