Inspecting NSCoder Files

One of the very handy features in Cocoa is NSCoder, it allows you to easily write your objects to a file. Your objects need to know how to encode and decode themselves with an NSCoder and that’s it.

While this is pretty handy it also ties the created files tightly to your application. If you try to open such a file you need to have all the needed classes at hand. That’s a pretty ugly problem if you just want to know what’s inside the file.

Yesterday I had this exact problem and I’ve played around a bit until I had a tool that allows me to inspect any file that was written with an NSKeyedArchiver. NSArchiver is not yet supported.

Thanks to ObjC 2 this was relatively easy to do: If a class is missing, create it and retry to unarchive. That’s pretty brute force but I didn’t see no other way. With some private methods in NSKeyedArchiver I was also able to get all the keys of an Object. With the classes present and with the keys available I could then read all the Objects.

The tool is available here: PlistExplorer.zip

Usage: PlistExplorer <file>
It’ll write the content to stdout so you might want to pipe it to something like TextWrangler.

The tool comes with no warranty whatsoever. Use at your own risk.

Karsten (@_karsten_)

4 Responses to “Inspecting NSCoder Files”

  1. Jordy/Jediknil Says:

    Very cool! I tried this once in the pre-ObjC-2 days, and didn’t get very far; never thought of creating classes on the fly.

    Any chance of providing the source? This seems like it could be a cool tool to keep improving.

  2. Jason Martin Says:

    I very much agree; I’d be interested in the source code to this as well.

  3. C├ędric Luthi Says:

    This sounds great. I always wanted a tool to explore NSKeyedArchives. Could you please recompile with 10.5 deployment target please so that Leopard users have a chance to test?

  4. Karsten Says:

    and there go the sources: https://briksoftware.com/blog/?p=118