Exposing those private frameworks


Don’t we all just love undocumented goodness? Some people spend a lot of time exploring and experimenting with APIs and functions to see what they can accomplish. I get a fair amount of email of people asking how exactly these private, undocumented goodies are discovered. You only need two things. The appropriate tools, and lots of spare time.

MagicHat

MagicHat

MagicHat is a programmer’s research and reference tool. With MagicHat, you navigate through Cocoa’s application programming interface (API); review the declarations of language elements such as methods, functions, and constants; and retrieve relevant passages from the Cocoa developer documentation. MagicHat helps you unravel unfamiliar code, whether building blocks from the Cocoa software kits, programming examples, or programs written by your own development team.

MagicHat lets you look at the declarations of public, private and local (installed) frameworks. This is a good graphical way to look at the structure of a framework, but is limited to Objective-C; which shouldn’t matter much for general use. MagicHat: observing Smoke.framework

Above: MagicHat in action, displaying Disco.app’s Smoke.framework

Class-Dump

Class-Dump is one of the easiest to use command line utilities to look at the Objective-C portions of Mach-O files. The command is immediately available after moving the downloaded file to /usr/bin/ (you may need to use sudo mv). Executing it involves a running a simple “class-dump nameoffile” command in Terminal and the output is a nicely formatted Objective-C header. Objective-C output is the feature that makes this tool unique. It is especially useful if you need header files for frameworks which don’t include them, but it also gives you an idea as to the classes and methods present in the framework.

otool

otool provides one of the most comprehensive feature-sets - its primary role being to display parts of object files or libraries. You’ll generally find that using otool gives you access to frameworks such as CoreGraphics, which don’t contain Objective-C classes. The -v command will give you verbose output; -o displays the Objective-C and -t the text sections.

Take ‘em apart

Using these tools, you are now equipped to examine in detail most frameworks and libraries. Be aware that searching though and discovering new functions takes a lot of experimentation and trial and error - which the primary reason I leave it to people like Wade Tregaskis (who, like me, lives in Melbourne. Never met him, though).

Obligatory disclaimer: The private frameworks are probably private for a reason. Meddle with them at your own risk.

(For those adventurous souls, the Core Graphics framework is located at /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework but there are plenty of other private frameworks besides this one; Core Graphics just happens to have the window transition effects.

Ok, did this help, and what did I miss?


Back to Top ↑

5 Comments so far

Leave a comment
  1. 1

    Thanks for the writeup, I hadn’t heard of MagicHat- looks nice.

    You may also want to have a look at otx:

    http://otx.osxninja.com/

    The author describes its output as a combination of otool and gdb disassembly. I used it recently to reconstruct some of Display Eater’s Obj-C code. When class-dump shows you an interesting interface, otx can help you see the implementation.

  2. 2

    Thanks Blake, otx looks pretty nice. I’ll give it a look.

  3. 3

    What I find surprising, is that Apple seems to be almost encouraging people to reverse-engineer some of their technologies. Leopard’s got so many integrated tools to see exactly what something is doing that getting fundamental knowledge of an applications’ workings will be little more than child’s play (of course, one has to understand the output, but it’s great). What do you think about this?

  4. 4

    I think it’s great that Apple are providing some of these tools. Getting into the fundamental workings of the operating system is a great way to really understand and apply techniques to improve your code. Of course, I can’t wait for Leopard to be released. The main thing I’m looking forward to is Xcode 3.0, which I’ve heard is a real improvement.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Comments may be edited for formatting.