Using Dynamic Library Injection with the iPhone Simulator

October 25 2008

UPDATE: This method no longer works for iPhone OS SDK 2.2 - please see my new article for an updated method.

Many developers who are not targeting the App Store are developing extensions or plugins to SpringBoard, the iPhone’s shell, using a piece of software called MobileSubstrate which simplifies the loading of your own code into SpringBoard. But, for development and debugging purposes, this takes valuable time as each time you build your plugin you have to delete the old version from the phone, sign your plugin, push the new version to the phone, and restart SpringBoard. All these steps take a little time off your life, but if you have access to the iPhone Simulator included with the SDK things are a bit easier!

You can set up automatic loading of your dynamic library by replacing the SpringBoard binary with a shell script and passing the DYLD_INSERT_LIBRARIES option to the original SpringBoard with the path to your library, or if you want a quick once-off test, you can use gdb as below:

Your code should now inject itself into SpringBoard on the iPhone Simulator so you can test on the desktop, take screenshots, check for leaks, or merely stress test your application against the different builds of the iPhone OS (the Simulator allows version switching on the fly). For me, I find this very useful (I use the DYLD_INSERT_LIBRARIES method) so that I can iterate very quickly when developing Stack. You can also get the console output from SpringBoard by launching the iPhone Simulator from Terminal, so for debugging it’s very important. Hope this post may be of some use.