Using the Open Tool Chain in Xcode (for both OS 2.2 and 3.0)

OTC =/= Over the counter, but it WILL cure what ails ya.
OTC =/= Over the counter, but it WILL cure what ails ya.

The iPhone OS SDK from Apple is wonderful, and being able to develop and debug on-device even without paying the entry tax is even more wonderful. To really take Jailbreak development to the next level, though – to develop Apps that don’t play nicely in Apple’s SDK playground – you are going to need the open tool chain. Here’s how to rock Xcode OTC style.First, what IS the open tool chain? Apple’s SDK gives you a bunch of APIs to work with. For example, there’s CoreLocation, which helps you interface with the GPS, there’s UIKit, which helps you interface with the display and other basic functions, and so on. These are great, and let you write full-featured apps for the platform and all devices running it. They aren’t very deep, though – they don’t let you do things like access hardware directly. They don’t let you do things like modify system code. Moreover, they weren’t publically available before the SDK was released.

As a result, a bunch of iPhone hackers, primarily Jay Freeman (also known in various locations, including twitter, as saurik) dumped the headers from iPhoneOS (headers are the things that tell you what classes and methods are available to program with) and fashioned them into a SDK unto itself, usable in much the same way as Apple’s. The difference is that there are hundreds of “Private APIs”, classes not available to the standard SDK users. Many of these APIs allow things like directly controlling the radios, modifying system parameters, and so on. They’re generally super useful if you’re trying to develop something that the regular APIs don’t like, and if you don’t care that your audience will be limited to jailbroken users.

So how do we use this open tool chain? We could write our program in a text editor, build a makefile, compile against our special headers, and so on and so forth, but that’s not my style. I use the command line as much as the next nerd, but I’ll take a pretty cocoa interface any day of the week. That said, the logical conclusion is to tell Xcode how to use them. We do this using templates (the things you can choose from when you “make new project” in Xcode), and OTC templates are exactly what @javacom made for iPhoneOS 2.0 way back when in September 2008. I basically just modified these templates to work with OS 3.0 (at least I’m 99.99% sure they do, I’ve lightly tested, but call me out if you find something). Here’s how to install them and get going:

Vital Stats: Xcode installed using default settings via the iPhoneOS 3.0 SDK. Cracked to break provisioning profile requirement by the method posted here.

  1. First, we need to install the open tool chain itself. Run each of the following commands line by line in Terminal:

    $ cd ~/Desktop
    $ sudo mkdir -p /Developer/SDKs/iPhoneOS.sdk/Versions/iPhoneOS3.0.sdk/
    $ svn co http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk
    $ cd include-1.2-sdk
    $ ./configure --prefix=/Developer/SDKs/iPhoneOS.sdk/Versions/iPhoneOS3.0.sdk/
    $ sudo sh install-headers.sh
    $ cd ~/Desktop
    $ rm -rf include-1.2-sdk
  2. NOTE: This installation is to a totally different location than the official SDK: it may look like the same structure if you’ve seen it, but that’s only because it’s installing in the same location as the MacOSX SDK.ALSO NOTE: I’m not 100% positive that the open tool chain version used in the step above has been 100% updated for OS3.0 – I’ll update if I find out that it doesn’t work. (The problem here is that certain APIs could be deprecated and no longer function, despite that my methods for installing and testing all work. As a result, you could try to build your OTC app only to find out that some API or another doesn’t work like you expected. I’m nowhere near experienced enough to handle this port myself, it’ll probably have to wait until @saurik has finished his work on the port to 3.0 and gives the go ahead that everything’s functional.)
  3. The next thing to take care of is installing the templates that USE these headers we just downloaded and installed. The original templates in the link I posted above only work for OS 2.x. I modified them all to look for things labeled 3.0 instead. Additionally, I modified them such that, by default, they use the code signing identity named “iPhone Developer” which is consistent with the other hacks I’ve published here. Anyway, to install them, run the following in Terminal, again line-by-line:

    mkdir ~/Desktop/TemplateInstall
    cd ~/Desktop/TemplateInstall
    curl -O http://www.alexwhittemore.com/wp-content/uploads/2009/07/30ToolChainTemplates.zip
    unzip -o 30ToolChainTemplates.zip -d "/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates"
    cd ~/Desktop
    rm -rf TemplateInstall
    rm -rf /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/__MACOSX
  4. This will install all the templates, and most are ready to go now. Some, however (all of the command line templates, for example), get the app on the phone to test it via SSH. As such, you need to configure your iPhone wifi IP in your project settings (you’ll always have to do this, no real way around it), and you’ll ALSO need to load your Mac’s SSH keys into your iPhone so that the transfer doesn’t ask for a password. Do the following (note: copied almost verbatim from the forum thread below):
    in MAC Terminal:
    $ ssh-keygen -t rsa
    replace below as appropriate for your network.
    $ ssh root@ 'mkdir -p .ssh'
    the iPhone root password, by default, is 'alpine'.
    $ cat ~/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
    make sure you're still ssh'd into the phone
    $ vi /etc/ssh/sshd_config
    Find these:
    #StrictModes yes
    #PubkeyAuthentication yes
    #AuthorizedKeysFile .ssh/authorized_keys
    and uncomment them (delete the #s). Hint: you can type '/' to 'find' in vi, 'n' to 'find next', 'i' to enter 'insert mode' and esc to exit it.
    type ':x' to exit and save.
    reboot your phone.

From this point on, we should be all set. The only thing left to do is to make sure that you set your phone’s IP in the project settings should it be required. It is worth reading the descriptions of each template when you have the new project window open, too, just so you can be sure you know what’s up.

Happy Jailbreak Coding!

Note: I’ve re-tested this method since reworking the enable-on-device-debugging method of my previous post, and I’ve found that everything is functional, and despite using the open tool chain, debugging is fully functional in all its glory. I haven’t tested Instruments, but I have no reason to assume they don’t work also. As always though, comment if something doesn’t work and I’ll fix it ASAP.

Sources: This post is a compilation of info from lots of places. In no order, http://onlamp.com/pub/a/onlamp/2008/03/25/the-apple-sdk-apis-apple-didnt-want-you-to-know-about.html, http://iphonesdkdev.blogspot.com/2008/09/xcode-template-for-pwned-iphone-device.html, and http://www.iphone.org.hk/cgi-bin/ch/topic_show.cgi?id=6017&pg=2&bpg=1

13 Comments

  1. August 5, 2009

    You know, I didn’t even see Casper’s comment when I made mine (how could I miss that?). Sorry Casper, you had it first!

  2. Pope
    August 12, 2009

    so i got think i got it all right from what you said here. i can ping and ssh into phone phine, and thot i know i sent that rsa key with no password. but i get this error when running build script: ‘Permission denied (publickey,password,keyboard-interactive).’ any ideas?

  3. Ben
    August 18, 2009

    The templates seemed to have installed correctly. But when I add the appropriate lines to the “Other C Flags” section of the project properties, and add a private framework that has a line in the header that imports NSObject.h, XCode complains.

    Not quite sure how to resolve this issue.

  4. Link Bian
    September 13, 2009

    Hi, I created a project with “Open Toolchain Application” when I finished step 1 and 3, but it failed with such error message – redefinition of ‘_mm_max_pi16’. Could anyone give me a help? Thanks a lot!

  5. Joe
    September 20, 2009

    Hi, Thank you for the tutorial. For some reason the templates are not showing up in XCode.

    My “unzip -o 30ToolChainTemplates.zip -d” line failed to create a directory so I made one myself and added the files from the zip archive.

    Any suggestions would be appreciated.

  6. Joe
    September 21, 2009

    Hi, The solution to my earlier problems was that I did not have the iPhone 3.0 SDK installed. Easy fix.

    Now I am receiving. “Code Signing Identity ‘iPhone Developer’ does not match any valid, non-expired, code-signing certificate in your keychain.”

    I followed the following instructions for creating a certificate for ‘iPhone Developer’ (1) and added the build phase script from (2)

    (1) http://www.insanelymac.com/forum/index.php?s=5b2e74a908ea19646b053641589b65c3&showtopic=127990&st=0&p=911738& and added the build

    (2) http://www.alexwhittemore.com/?p=270

    Has anyone has luck resolving this issue (probably a simple fix) Thanks!

  7. Leo Kenner
    September 23, 2009

    I just upgraded to SL, so am wondering if anyone knows if this works on xcode 3.2?

  8. James
    January 3, 2010

    Any idea if this works with Snow Leopard? I’ve tried and every time I build anything, I get ~17,000 errors. I DO have the 10.4 SDK installed (installed Xcode 3.0 as well as Xcode 3.2.1). When configuring, I did specify the 10.4 SDK directory as well.

    Any ideas?

  9. Fabio
    January 6, 2012

    Is it possible to use the open toolchain in XCode 4 and iOS 5?
    I’m not targetting the iOS 5 specifically, but I just bought a Mac mini and it comes with Lion, so I can’t use a previous version of XCode.

  10. June 28, 2013

    Any idea if this works with Snow Leopard? I’ve tried and every time I build anything, I get ~17,000 errors. I DO have the 10.4 SDK installed (installed Xcode 3.0 as well as Xcode 3.2.1). When configuring, I did specify the 10.4 SDK directory as well.

    Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *