Using the Open Tool Chain in Xcode (for both OS 2.2 and 3.0)
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.
- 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
- 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.)
- 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:
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"
rm -rf TemplateInstall
rm -rf /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/__MACOSX
- 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 firstname.lastname@example.org 'cat >> .ssh/authorized_keys'
make sure you're still ssh'd into the phone
$ vi /etc/ssh/sshd_config
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