“trouser mac”
December 12th, 2007 -- Posted in General, trouser macA new geek term for the masses. Instead of calling the most kickass phone ever invented an “iPhone”, from now on it should be referred to as a “trouser mac”.
A new geek term for the masses. Instead of calling the most kickass phone ever invented an “iPhone”, from now on it should be referred to as a “trouser mac”.
This evening I decided today would be the day I upgraded to 1.0.2. Despite a few hiccups with the restoration, the update proceeded and my iPhone was now running Apple’s latest and greatest release. Sadly, that also meant my iPhone was now pristine again without any of the apps I have come to love on it. After hearing about the new Installer.app GUI installer, I had to give it a shot.
This is about as simple of a howto as one could get, the steps to getting Installer.app running (which opens the door for SSH, Terminal, etc) is as follows:
- Download the Installer.app GUI installer from here.
- Run the application and follow the onscreen instructions (connecting phone, shutting down iTunes, selecting current phone firmware revision).
- Sit back and wait 2-3 minutes. It literally does everything else for you!
No more do you need long howtos, no more do you need to worry about missing steps. Just sit back and let the GUI app do it’s business and you are good to go. I’m still a little irritated they haven’t opened up the source on the app, but otherwise the process couldn’t be simpler. If you haven’t hacked your phone yet, what are you waiting for?
In the first post of this howto, I talked you through getting full access to your iPhone and a basic SSH server running. If you haven’t read Part #1 yet, please do so before continuing here. In this post, we will actually get our toolchain setup as well as install a few more useful pieces of software.
The first thing I will talk you through is replacing DropBear. We will install OpenSSH2 onto the phone which will provide us with the full suite of SSH functionality. Follow these simple steps to upgrade:
mkdir /etc/ssh2 putfile /Users/(your username)/phonedmg/openssh/etc/ssh2/ssh2_config /etc/ssh2/ssh2_config putfile /Users/(your username)/phonedmg/openssh/etc/ssh2/sshd2_config /etc/ssh2/sshd2_config putfile /Users/(your username)/phonedmg/openssh/usr/bin/scp2 /usr/bin/scp2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/sftp-server2 /usr/bin/sftp-server2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/sftp2 /usr/bin/sftp2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh-add2 /usr/bin/ssh-add2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh-agent2 /usr/bin/ssh-agent2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh-keygen2 /usr/bin/ssh-keygen2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh-probe2 /usr/bin/ssh-probe2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh-signer2 /usr/bin/ssh-signer2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/ssh2 /usr/bin/ssh2 putfile /Users/(your username)/phonedmg/openssh/usr/bin/sshd2 /usr/bin/sshd2 putfile /Users/(your username)/phonedmg/openssh/System/Library/LaunchDaemons/com.sshd.plist /System/Library/LaunchDaemons/com.sshd.plist putfile /Users/(your username)/phonedmg/binkit/usr/bin/scp /usr/bin/scp putfile /Users/(your username)/phonedmg/binkit/bin/ls /usr/bin/ls putfile /Users/(your username)/phonedmg/binkit/usr/lib/libarmfp.dylib /usr/lib/libarmfp.dylib rmdir /System/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist
-sh-3.2# chmod 555 /bin/ls /usr/bin/* -sh-3.2# ssh-keygen2 -P -t dsa -c "DSA hostkey" /etc/ssh2/hostkey -sh-3.2# launchctl load /System/Library/LaunchDaemons/com.sshd.plist
Now that you have a good SSH server on your phone, it’s time to add in a bunch of standard Unix commands. You do this by running the following commands on your Mac:
$ cd ~/phonedmg/binkit $ scp -R bin sbin usr libexec root@(iphone IP):/
After doing this, you should have things like grep, uname, ps, etc on your iPhone. Try them out to be sure. As a quick exercise, now that you have a full blown SSH server on your iPhone and basic apps like vim, you should consider disabling password based authentication and put your SSH key on it. Much more secure, IMHO. If you need help with this, ping me.
The next thing we will do is get our toolchain working. My preference is to build the toolchain from source (easier to keep up to date). This can be time consuming though, so if you are the impatient type, do a Yahoo! search for “iphonetoolchain dmg”. I haven’t tested this approach, so I won’t provide any direct links (as they may rapidly change). To build the toolchain, do the following:
sudo port install libstreams
mkdir ~/phonedmg/toolchain/heavenly sudo cp -R /Volumes/Heavenly1A543a.UserBundle/* ~/phonedmg/toolchain/heavenly/
cd ~/phonedmg/toolchain svn checkout svn://svn.berlios.de/iphone-binutils/trunk
cd ~/phonedmg/toolchain/trunk ./configure --with-heavenly=/Users/(your username)/phonedmg/toolchain/heavenly/
Then we need to fix a problem in the generated makefile by editing line 34 and making it read:
cd llvm-2.0 && $(MAKE) ENABLE_OPTIMIZED=1 install
and then following that we run _sudo make_ (note the sudo is apparently required).
Now that we have our toolchain setup, let’s build the most useful app I have found so far. This application is a Terminal.app like application for the iPhone. It provides a GUI interface to running shell commands on the phone and is immensely useful for things like SSH (outbound from the phone). The app also has good polish for such an early edition and thus is a good example of what can be done. Follow these steps for getting it running on your iPhone:
mkdir ~/phonedmg/apps cd ~/phonedmg/apps svn checkout http://mobileterminal.googlecode.com/svn/trunk/ mobileterminal
sudo touch /Developer/SDKs/iPhone/include/UIKit/NSObject.h sudo touch /Developer/SDKs/iPhone/include/LayerKit/NSObject.h
scp -r Terminal.app root@(iPhone IP):/Applications/

That completes our howto and I would love to thank the numerous devs around the world who have made all this possible. Now that you have a toolchain and an extremely useful sample app, let’s see what apps you can create! If you make something, please be sure and let me know.
P.S. - A helpful tip in regards to the terminal app, to do a control key sequence use the “bullet” key which can be found by pressing the 123 key, then the #+= key (center far right of that last keyboard). Also, to hide the keyboard, simply tap the screen (and again to bring it back up).
After getting numerous inquiries from coworkers and friends, decided to write a cohesive howto guide on getting custom apps on your iPhone. Yes, there are numerous sources of information all over the net, but I haven’t seen (keyword, I haven’t, maybe you have) a howto which covers everything from start to finish. This will be a multi-part series (mainly because I don’t want to type so much write now) so stay tuned for the complete guide. For all of these instructions, I am going to assume you are on a Mac. I’ve not seen any way to build apps using the toolchain on Windows and since that is the whole point of this howto series, I won’t go into any Windows related stuff (sorry!).
First things first, you need to get access into the iPhone outside of normal Apple channels. I’ve tried numerous different methods with varying levels of success, but the one I have found easiest is to use Jailbreak combined with iPHUC. Yes, yes, you can do all of it with just iPHUC now, but I have found Jailbreak to be far easier and less error prone to get out of the chroot jail. So, first things first, you need to download a few things:
The restore image is really a zipfile, so if it didn’t uncompress automatically, then rename the file with a .zip extension and extract it. Now create a directory somewhere (like your home dir) named ” phonedmg “. Inside this directory put the _contents_ of the iPhone1,1_1 from the extracted restore image. Make sure you put the contents (aka two disk images, a directory, and two files) and not the directory itself! Now also extract Jailbreak and put it’s contents there too. Next you are going to run Jailbreak (if I need to tell you how to run it, you should really stop here). Follow the instructions it gives to put the phone in restore mode and a couple moments later your phone should now be fully accessible. If you are curious the steps it is performing behind the scenes, read this twiki page on “How to escape Jail” which is more or less the same steps (except it does it in a different order, but essentially the same thing). I chose to use the automated method as the steps are a bit tedious and there is no perceived benefit I can tell from using the manual steps.
Now that we have complete access to the phone’s filesystem, we will install a basic SSH server to help us with the bootstrap process. The first step is to download and compile iPHUC. The build process is as follows (lifted from here, only reprinted to keep you from having to jump around):
sudo port selfupdate sudo port install readline cd ~/phonedmg/ mkdir tools-src cd tools-src/ svn co http://iphonesvn.halifrag.com/svn/iPhone iphuc-src cd ./iphuc-src/trunk/iPHUC/
Index: NormalInterface.cpp =================================================================== --- NormalInterface.cpp ( revision 8 ) +++ NormalInterface.cpp ( working copy ) @@ -1,4 +1,4 @@ -#include "normalinterface.h" +#include "NormalInterface.h" #include "Shell.h" int n_pwd(string *args, struct shell_state *sh)
Now that you have built iPHUC, it’s time to get shell access on the phone. We first need to download dropbear for iPhone. Ultimately, dropbear isn’t the SSH server we will stay with, it’s just easier to get it going first. After downloading it, extract it into ~/phonedmg/dropbear. We also need to create ourselves some SSH host keys which we can do by:
./dropbearkey -t rsa -f dropbear_rsa_host_key ./dropbearkey -t dss -f dropbear_dss_host_key
With that completed, now let us upload the stuff to the phone. We do this by firing up iPHUC and following these steps:
localhost:~/phonedmg $ ./iphuc iphuc 0.5.0 >> By The iPhoneDev Team: nightwatch geohot ixtli warren nall mjc operator initPrivateFunctions: this is still not clean. Architecture: i386 AMDeviceNotificationSubscribe: 0 CFRunLoop: Waiting for iPhone. notification: iPhone attached. AMDeviceConnect: 0 AMDeviceIsPaired: 1 AMDeviceValidatePairing: 0 AMDeviceStartSession: 0 AMDeviceStartService AFC: 0 AFCConnectionOpen: 0 AFCPlatformInit: (no retval) notification: Entering shell in Normal Mode. shell: Entering loop. (iPHUC) /:
(iPHUC) /: setafc com.apple.afc2 AMDeviceStartService AFC: 0 AFCConnectionOpen: 0
getfile /System/Library/LaunchDaemons/com.apple.update.plist com.apple.update.plist.original getfile /usr/sbin/update update.original
putfile /Users/(your username)/phonedmg/dropbear/sh /bin/sh putfile /Users/(your username)/phonedmg/dropbear/chmod /bin/chmod putfile /Users/(your username)/phonedmg/dropbear/chmod /usr/sbin/update putfile /Users/(your username)/phonedmg/dropbear/dropbear /usr/bin/dropbear putfile /Users/(your username)/phonedmg/dropbear/au.asn.ucc.matt.dropbear.plist /System/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist putfile /Users/(your username)/phonedmg/dropbear/com.apple.update.plist.hacked /System/Library/LaunchDaemons/com.apple.update.plist mkdir /etc/dropbear putfile /Users/(your username)/phonedmg/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key putfile /Users/(your username)/phonedmg/dropbear_dss_host_key /etc/dropbear/dropbear_dss_host_key
putfile /Users/(your username)/phonedmg/com.apple.update.plist.original /System/Library/LaunchDaemons/com.apple.update.plist putfile /Users/(your username)/phonedmg/update.original /usr/sbin/update
Replacing MYPASSWORD with a password and XX with any random two letters (it’s the salt). The easiest way to replace the passwords is to do a “getfile /etc/master.passwd master.passwd.original” in iPHUC, edit both the root and mobile users’ passwords, and the do a “putfile /Users/(your username)/master.passwd.original /etc/master.passwd”.
With that, this first part of the series is now complete. You have successfully hacked your iPhone and got an SSH server running on it. In the next part of the series, I will detail how to install a better SSH server, get basic unix commands on the phone, setup your toolchain/build environment, and then build and install a terminal GUI app on the phone.