O'Reilly logo

Hacking and Securing iOS Applications by Jonathan Zdziarski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Disassembling and Debugging

The low-level C structures that comprise the core Objective-C messaging framework have now been explained; it’s time to explore what happens at runtime on the low level. To do this, you’ll use a disassembler. If you haven’t already done so, install the GNU Debugger (gdb) onto your test device using the Cydia software installer, or by signing and copying Apple’s universal binary, supplied with Xcode.

Build the simplified version of Hello World shown in Example 8-1 on your desktop machine. This simplified version invokes only four methods: alloc, init, say, and release.

Example 8-1. Simplified “Hello, world!” application using Objective-C classes. (HelloWorld.m)

#import <Foundation/Foundation.h>

@interface SaySomething : NSObject
- (void) say: (NSString *) phrase;
@end

@implementation SaySomething

- (void) say: (NSString *) phrase {
    printf("%s\n", [ phrase UTF8String ]);
}

@end

int main(void) {
  SaySomething *saySomething = [ [ SaySomething alloc ] init ];
  [ saySomething say: @"Hello, world!" ];
  [ saySomething release ];
  return 0;
}

To compile this simple program, use the cross-compiler included with your version of Xcode:

$ export PLATFORM=/Developer/Platforms/iPhoneOS.platform
$ $PLATFORM/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 \
    -o HelloWorld HelloWorld.m \
    -isysroot $PLATFORM/Developer/SDKs/iPhoneOS5.0.sdk \
    -framework Foundation -lobjc

Using gdb, disassemble the main function on your device:

root# gdb ./HelloWorld GNU gdb 6.3.50.20050815-cvs (Fri ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required