scribble

[self blog]

About GitHub

14 Oct 2013
Objective-C Hierarchy Graph

When working on MobileSubstrate tweaks, you need to have a clear representation in your mind of what the class hierarchy of a library or a component looks like. This allows you to properly use and hook inherited methods and properties to your advantage, for example.

class-dump does a great job on dumping the runtime information from a Mach-O executable: you can even tell it to sort classes, protocols and categories by inheritance, which is great, but doesn’t give you an easy way to memorize them all.

So far, I used a combination of ‘dummy’ headers and various ‘.txt’ files to note down all the classes and protocols for future reference. Last week I got tired of having hundreds of files floating around my development environment, so I wrote a simple Python script to solve this problem (No, I couldn’t find anything that would suit my needs).

hierarchy-graph.py allows you to generate a graph of the hierarchy of the Objective-C classes implemented in a particular Mach-O executable.

Even though the script is quite simple, it’s also quite flexible: it supports either a Mach-O or an header file as the input, and can save the output as a ‘.dot’, ‘.svg’ or ‘.plist’ file (Defaults to svg; I thought the plist format could come in handy too).

If you’d like to see some example outputs, this is the MapKit framework graph.


Ciao,
Filippo Bigarella at 14:10

About GitHub