Handy iPhone Dev Tool: Disassemble Mach-O Files Into Objective-C with “class-dump”

February 6, 2009

As I Java developer I’ve occasionally needed to “disassemble” a .class file and reveal the method signatures and instance variables of the class(es) inside it, typically using the javap tool. As one would expect, a similar tool exist in the Objective-C world: class-dump. You pass the class-dump executable Mach object files (e.g., *.o, *.exe, etc.) and it spits out interface declarations in Objective-C. Handy.

As an example, let’s use class-dump to analyze itself (note all the goodies it generates: structs, protocols, interfaces, ivars…):

$ ./class-dump ./class-dump
/*
 *     Generated by class-dump 3.1.2.
 *
 *     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2007 by Steve Nygard.
 */

struct dylib {
    union lc_str name;
    unsigned int timestamp;
    unsigned int current_version;
    unsigned int compatibility_version;
};

@protocol CDStructureRegistration
- (void)phase1RegisterStructure:(id)fp8;
- (BOOL)phase2RegisterStructure:(id)fp8 usedInMethod:(BOOL)fp12 countReferences:(BOOL)fp16;
@end

@interface CDOCCategory : CDOCProtocol
{
    NSString *className;
}
- (void)dealloc;
- (id)className;
- (void)setClassName:(id)fp8;
- (id)sortableName;
- (id)findTag:(id)fp8;
- (void)recursivelyVisit:(id)fp8;
- (id)identifier;
- (id)dependancies;
@end
Clint Harris is an independent software consultant living in Brooklyn, New York. He can be contacted directly at ten.sirrahtnilc@tnilc.

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>