Developing for a jailbroken iPhone, A to Z (iPhone 3.0)

30rockin
Rockin 3.0

UPDATE: NEWGUIDE NEWGUIDE NEWGUIDE!

Vital iPhone stats for this post:
iPhone version: 3G (should work with 2G and 3GS)
iPhone OS version: 3.0 (rock the hizzouse!)
Jailbreak status: Jailbroken using Pwnage Tool.

The Goal: Get live on-device XCode debugging without being a paying ADC member. This time OS 3.0 style.

Abstract: Same deal as last round. We want to break code signing on the iPhone, and then we want to make Xcode load software into it automatically to debug. In SDK 2.2 (Xcode version 3.1.2) this was just a simple matter of editing some Plists and such to tell Xcode to ignore provisioning profiles. SDK 3.0 (Xcode version 3.1.3) broke these Plist editing tricks. For a while, all you could do was try to hack SDK 3.0 support into Xcode 3.1.2, installed with SDK 2.2. That was really very hairy, though, if you didn’t want to have to switch environments to debug (close and restart Xcode). It was also annoying to configure. Luckily, there’s a new, much less ghetto way. It’s all based on a little hack posted by <zim> in this thread (coral). Essentially, it just replaces a few bits in the Xcode plugin that actually handles the device build, which restores our build and go ability.

Procedure: things marked (2.2 STEP) will already be done if you followed my previous procedure, and you may not need to repeat them.

  1. Jailbreak your phone. In Cydia, add the source http://iphone.org.hk/apt/. Install the package “Installd Patch” (this used to be Mobileinstallation Patch, just a name change in OS 3.0). Thanks go to @javacom for this lovely little hack, and lots of other wonderful info on his blog. Seriously, if you’re reading this right now, you should be following him. UPDATE 8/3/09: Some are reporting that if you’re on OS 3.0.1 or possibly a 3GS (or both) Installd Patch may or may not actually install. If this is the case, or if you get weird message about your identity being no longer valid, try installing AppSync as a stand-in.
  2. (2.2 STEP) You will need a signing identity. We’ll break the check such that it doesn’t have to be an official ADC one, so you can make your own using this guide from apple (coral). What you are doing in this step is creating a “Self-Signing Identity.” Note that you should name the identity “iPhone Developer” EXACTLY to avoid having to change a bunch of the steps below.
  3. (2.2 STEP) Open your project and go to (menu) Project > Edit Project Settings. In the list of properties, find “Code Signing Identity” > “Any iPhone OS Device” and click in the empty box. Assuming there are no entries in the menu, click “Other” and type in the same name you used to generate the code signing certificate above in step (2). For example: in step 2, I used the name “iPhone Developer” and that is exactly what I put in this field. Hit OK and close that settings window. This setting should persist in future projects, and you shouldn’t have to do this again.

Add the special 3.0 sauce:

  1. Open a terminal.
  2. type cd ~/Desktop (enter)
  3. type vi script (enter)
  4. tap i on your keyboard (to enter “insert” mode in vi).
  5. Copy/Paste (cmd-v) the following code into your terminal window:
    #!/bin/bash
    cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/
    dd if=iPhoneOS\ Build\ System\ Support of=working bs=500 count=255
    printf "\x8f\x2a\x00\x00" >> working
    dd if=iPhoneOS\ Build\ System\ Support of=working bs=1 skip=127504 seek=127504
    /bin/mv -n iPhoneOS\ Build\ System\ Support iPhoneOS\ Build\ System\ Support.original
    /bin/mv working iPhoneOS\ Build\ System\ Support
    chmod a+x iPhoneOS\ Build\ System\ Support
  6. type ESC, then : x (colon,x) (enter). This saves and exits in vi.
  7. type chmod 777 script (enter)
  8. type ./script (enter) This will execute the script to patch the Xcode plugin. Assuming it completes correctly, you should be good to go, try it out!

If it executed correctly, you should see something like this:

alex-whittemores-computer:Desktop alex$ ./script
255+0 records in
255+0 records out
127500 bytes transferred in 0.035658 secs (3575647 bytes/sec)
191056+0 records in
191056+0 records out
191056 bytes transferred in 1.782819 secs (107165 bytes/sec)

And the final step (added 7/18/09, fixes the issue where debugging failed on 3.0 and where the binary would fail to launch on 2.2.1): Codesign the binary before it hits the phone (this got patched out in the new Xcode method above). In terminal:

  1. mkdir /Developer/iphoneentitlements30
  2. cd /Developer/iphoneentitlements30
  3. curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
  4. mv gen_entitlements.txt gen_entitlements.py
  5. chmod 777 gen_entitlements.py

Add the build phase: in Xcode, select the menu options “Project > New Build Phase > New Run Script Build Phase”, and enter the following script:

export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ]; then
    /Developer/iphoneentitlements30/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent";
    codesign -f -s "iPhone developer" --resource-rules "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/ResourceRules.plist" \
         --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent"  "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/"
fi

NOTE: You will have to repeat this step for every project! (That is, the add build phase part, not the terminal part.) It’s a bummer, but I’m not sure there’s any way around it. I’ll try to figure out if you can persist custom build phases across projects.

Note: You may notice that a number of the steps you remembered from last time are gone now. I believe the few-byte hack above takes care of all the steps. As far as I know, there’s no need to even modify your projects with that one Plist key, everything just works. I currently have this setup working on my production machine, but just to be sure, I’m going to boot up my external disk and I’m going to test this procedure start to finish. As usual, don’t hesitate to comment if you have questions or run into trouble, and I’ll do my best to help.

Special thanks regarding the last step to zim at iPhone Dev SDK forums and to Sylvain Munaut, whose script gen_entitlements.py is used above.

274 Comments

  1. Joshua
    September 27, 2009

    You did create the certificate thing in the login keychain and did these steps?

    Open /Developer/Platforms/iPhoneOS.platform/Info.plist. (Backup if you want to be safe.)
    Go to line 46. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Go to line 79. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Save the file.
    Restart Xcode.

  2. MertenNor
    September 27, 2009

    hey..

    I cant build and go to my iPhone 3.1 I gett this error:
    /Users/******/Documents/xCode/iPhone Apps/ASC/build/Debug-iphoneos/ASC.app/ResourceRules.plist: cannot read resources

    Command /bin/sh failed with exit code 1

    Build failed (1 error)

    I used this as the “new build phase”:

    export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
    if [ “${PLATFORM_NAME}” == “iphoneos” ]; then
    /Developer/iphoneentitlements30/gen_entitlements.py “my.company.${PROJECT_NAME}” “${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent”;
    codesign -f -s “iPhone developer” –resource-rules “${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/ResourceRules.plist” \
    –entitlements “${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent” “${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/”
    fi

    and btw:
    iPhone 1G on 3.1
    xCode 3.1.3

    Any help.. ?

    Thanks

    MertenNor

  3. MertenNor
    September 27, 2009

    oh and btw I am on Snow Leopard

    MertenNor

  4. September 28, 2009

    thanks a lot but now i’ve got another error

    /bin/sh: /Users/dimasitnikov2/Desktop/f2kg/build/f2kg.build/Debug-iphoneos/f2kg.build/Script-95E81110106FF5CB0049225A.sh: export: bad interpreter: No such file or directory
    what does it mean?

  5. Joshua
    September 28, 2009

    @Yogurt: That’s the build script from this blog post. You don’t need it anymore with xcode 3.2 so you might just delete the ‘Script-95E81110106FF5CB0049225A.sh’ file located in ‘/Users/dimasitnikov2/Desktop/f2kg/build/f2kg.build/Debug-iphoneos/f2kg.build/’

    Be sure xcode is not running when you delete the file or it will recreate it.

    @MertenNor: What happens if you set the active SDK in your project settings to iPhone SDK 3.0?

  6. September 28, 2009

    yeah! it work)))))

  7. Zizou
    September 29, 2009

    Hi all!

    Do yo know if a workaround exist for Xcode 3.2 ?

  8. Joshua
    September 29, 2009

    This guide provides a workaround for xcode 3.2

    Check the older comments for common errors. If you arent sure what you are doing, i would stop with step 4 of the second guide. The steps after that are to enable on device debugging but they could really damage your device.

  9. Zizou
    September 29, 2009

    Thx Joshua ! It works !!! :))

  10. Amit
    October 2, 2009

    Hi,

    Thanks for the post, really helpful. Thanks to Joshua 🙂
    I am stuck on how to deploy the build.

    I can jailbreak if need be , to transfer the project files. But when i build , I get helloWorld.app on the Xcode (left side). I would like to know what to copy from the project after successful build in my iPhone device, and then run the application.

    Any help will be very useful for me.
    Thanks

  11. October 3, 2009

    I’m stuch at Build with

    “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.Test2’ could not be found”

    Now what.. :S

    /me SDK 3.2

  12. Joshua
    October 3, 2009

    @amit: You need to jailbreak your device and install Installd or AppSync

    @somnius: Did you follow the guides I mentioned earlier?

  13. jhon
    October 9, 2009

    Hi.. Everything worked fine and even i was able to deploy my app to jailbroken iPhone 3.0.. Thanks a lot for this tutorial.. the problem i am facing is the application icon doenot have any glossy look.. What can i do for that.. Any suggestion on this..
    Thank you

  14. Ryback
    October 9, 2009

    Hi… is this procedure valid for XCode 3.1.4? I am having trouble getting it to work with 3.1.4. My project compiles fine but I keep getting the “no provisioned iphone OS connected” error. Please help if anyone has gotten this to work with 3.1.4.

  15. October 12, 2009

    In Xcode 3.2, iphone 3.1 You need to do this to work:

    Open /Developer/Platforms/iPhoneOS.platform/Info.plist. (Backup if you want to be safe.)
    Go to line 46. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Go to line 83. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Go to line 95. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Save the file.
    Restart Xcode.

    it works like a charm! 🙂 Thanks!

  16. JK
    October 14, 2009

    Hi I’m trying to get this set up on my iPhone 3G OS 3.1, Jailbroken with DevTeam’s PwnageTool.

    Problem is I can not install the “Installd Patch”.

    I get the following error messages:

    Setting up hk.org.iphone.installd (3.1.2)
    [+] Start dry-run phase
    [!] Didn't find the expected data at offset
    [!] Error patching /usr/libexec/installd
    [!] Something bad happenned in dry-run. Nothing has been done
    Error: Installd Patch not supported.
    Error: Installd Patch not supported.
    Error: Installd Patch not supported.
    Error: Installd Patch not supported.
    Error: Installd Patch not supported.
    dkpg: error processing hk.org.iphone.installd (--configure):
    subprocess post-installation script returned error exit status 1

    I’m a little wary about the warning in the beginning telling me the installation will go south if something goes wrong, but I don’t think it did scrap my instllation cus’ of the dry-run, so hopefully I’ ok there.

    So why is this happening? The installer was going to replace some bytes of code but it didn’t find what it was looking for, this can be because of one of two reasons:
    -I have a different file then the one the patch was made for (it said it should work for OS 3.1 in the cydia description)
    -The file has already been patched. (Note: I have not installed the patch before.)
    I have the application “Installous” installad, it seams it is also installing this kind of patch to break the code signing.

    Suggested by theese threads:
    http://hackulo.us/forums/index.php?showtopic=28842
    http://www.xsellize.com/showthread.php?t=63313

    Hopefully developing applications will work with the Installous version of the patch.

  17. JK
    October 15, 2009

    Finally got it working, thanks for the guide and all comments!
    The information is all there here if you just look carefully enough.

    Turns out Installuos installs AppSync.

    I had Xcode version 3.1.4 and OS 3.1, but the guide is written for version 3.1.3, OS 3.0 .

    Fivos suggestion works, you have to use another verion of the script in step 5 above (below I’ve fixed Fivos cite-chars):


    #!/bin/bash
    cd /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS\ Build\ System\ Support.xcplugin/Contents/MacOS/
    dd if=iPhoneOS\ Build\ System\ Support of=working bs=500 count=255
    printf "\xc3\x26\x00\x00" >> working
    dd if=iPhoneOS\ Build\ System\ Support of=working bs=1 skip=127504 seek=127504
    /bin/mv -n iPhoneOS\ Build\ System\ Support iPhoneOS\ Build\ System\ Support.original
    /bin/mv working iPhoneOS\ Build\ System\ Support
    chmod a+x iPhoneOS\ Build\ System\ Support

  18. dutchieman
    October 15, 2009

    Felipe Navarro V.’s approach works! Just one plist to edit for XCode 3.2, no fussing with binary patches required!

    So great.

  19. October 25, 2009

    Ok y’all, so who actually has a situation that works verifiably for iPhone OS 3.1.2, Xcode 3.2.1, and Snow Leopard? I seem to keep getting a build error “/usr/bin/codesign failed with exit code 1” every time I try to build to device. You guys seem to have at least something worked out, though. Who’s got the complete deal?

  20. Wagner
    October 27, 2009

    ok, I can hack the XCode. My question is. Where do I find a kind of “documentation” for HOW to code for iPhone. The IO’s, the lower layers of OS. Example. I wanna create a program that runs in background. How do I do that? The last open layer from Apple is very limited!

  21. lazar
    October 28, 2009

    hi i need help… i made my app and want to test it on iphone… i am using sdk 3.1 and 3.1.4 xcode
    i have ldid on my iphone and all that things.. its iphone 3g fw 3.1… when i use ldid command in terminal i get
    ./minimal/mapping.h(54): _assert(2:false)
    ./minimal/mapping.h(54): _assert(2:false)
    ./minimal/mapping.h(54): _assert(2:false)
    i also sometimes get
    codesign_allocate: object: /Applications/proba.app/proba malformed object (unknown load command 4)
    util/ldid.cpp(582): _assert(0:WEXITSTATUS(status) == 0)

    i used script that JK wrote…

    i tryed everything but cant make it work… i get app on iphone but it dont want to start 🙁

    thx for helping me…

    my msn is [email protected]
    skype name lazar89nis

  22. randomIssue
    October 29, 2009

    After I hit build and go it compiles just fine but it tries to deploy the app to the iphone it gets a pop up error message “could not translate messages from device”

    anyone know what is going on or a way around this?

  23. vinise
    October 29, 2009

    Hy i’ve folowed all the step and coments which could help me but i’m stuck after all…

    2errores:
    Command /bin/sh failed with exit code 1
    Command /usr/bin/codesign failed with exit code 1

    any help is welcom

    vince

  24. Nick
    October 31, 2009

    Does this work for OS 3.1.2?

  25. Bibo
    November 1, 2009

    I am a registered apple developer but my iPhone is jailbroken. What do I have to do to get my app on my phone ?

  26. James
    November 4, 2009

    Used JK’s suggestion, it works on 3.1.4 Xcode and 3.0.1 OS. Now I upgraded OS to 3.1.2 and SDK to 3.1.2 as well. the same method can only install app to iphone, but could not debug on iphone, it says could not attache to debugger.

    Any Ideas, JK? I think you know what these numbers mean in the script, any changes need for OS 3.1.2?

    Thanks so much.

  27. uzi
    November 8, 2009

    OK works on os3.0 but instruments don’t.
    (Activity monitor works, displays iphone processes but other instruments like cpu sampler, opengl es etc. doesn’t show anything just when starting an app with any of performance tools app is transwered to iphone and imediately stops. Can you help me with it? thanks

  28. uzi
    November 8, 2009

    ****************
    I’m sorry for last reply – everything works, i forgot to change /Developer/Platforms/iPhoneOS.platform/Info.plist like Navarro wrote.

  29. Jim
    November 23, 2009

    hi, so does this mean i can use shiva3D or Unity to create iphone games which i can test out on my iphone?

  30. November 25, 2009

    Hi :
    I tried all the steps mentioned in the article. I am seeing a weird problem. When i start my xcode, its says internal error and the description says “No Device support package installed” object XCRemoteIphone line number 88

    Xcode version – 3.1.4
    OS – 3.1.2

    Appreciate any help in this regard. I dont see the iPhone device when i build the application

    Thanks
    Om

  31. tees
    November 28, 2009

    Hello, I’ve tried all the steps, backtracked couple times unfortunately, never got code to deploy properly.

    I’m currently getting an ‘iPhone developer: no such identity’ error. I have added and removed ‘iPhone developer’ (uses default Certificate Assistant values) couple times. maybe that’s the problem?

    Xcode 3.1.4, iPod Touch OS 3.1.2, OS X 10.5.8

    Would be really grateful for help. I really need to get this project done fast, so I can’t wait couple weeks for Apple to approve my application for the certificate before starting development.

  32. tees
    November 28, 2009

    btw, the Keychain Access suite displays ‘iPhone developer’ in both Certificates and My Certificates, and it has red ‘This root certificate is not trusted’ note.

  33. OCT Developer
    November 30, 2009

    Lovely guide, was a breeze to setup! Thank you 😀

    I had to change the signing identity from “iPhone Developer” to something different as it conflicted with the other identities. Went with OCT developer…but it could be anything.

    Xcode uses “iPhone Developer” as a default identity to figure out which it should use(when you have multiple signing identities) so it is best to use something different.

  34. November 30, 2009

    does this method work on Snow Leopard??
    Because some people are reporting that this method works on Snow Leopard, and some others are having trouble…

  35. almost
    December 18, 2009

    Hi,

    Thx a lot, was working
    last build xcode 3.1.4

    o to line 46. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Go to line 83. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
    Go to line 95. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext

    VERY important or xocde crash after a few seconds

  36. almost
    December 18, 2009

    I wasnt able to make debug work on device

    ——–

    Instrument also doesnt work, is it normal ?

  37. Erik
    December 19, 2009

    Hi

    Has anybody got it working for snow leopard
    xcode 3.2.1

    i keep getting codesign error,
    if anybody got it working please post a guide

    best regards Erik

  38. Works 3.1.4
    January 4, 2010

    I got everything working perfectly with Xcode 3.1.4 and iPod Touch firmware 3.1.2.

    I used the script JK commented, along with a self-signed cert (had to change the name to one without spaces for some reason). Build and Go (on device debugging) also works perfectly for me, just make sure to add the script that is run after build to sign it properly. Note for build and go that you must not already have a copy of the app you are running on the iPhone/iPod, as it conflicts (took me FOREVER to figure this out, kept getting an error saying that it could not translate messages from device).

    I am very happy now after 3 long days getting it to work 😛

  39. Albert
    January 6, 2010

    Hi guys!
    Altough i get the error in /bin/sh and for the certificate, i saw the apps is built correctly! xD
    Thanks a lot guys xD

  40. Sara
    January 19, 2010

    Hey,

    I followed the steps above and I’m getting the following error:

    Command /bin/sh failed with exit code 1

    Note that I’m using OS 3.1.2, and xcode 3.1.4. The active SDK is 3.0.

    Any ideas?

    Tanks

  41. January 19, 2010

    Sara: First, use this guide: http://www.alexwhittemore.com/?p=354
    Second, try setting Active SDK to 3.1.2 instead (or maybe it only goes to 3.1, don’t remember.
    Third, in the Build Results window, in the right hand drop down at the bottom of the tool bar, select “show all steps.” It’ll show you exactly what happens for each step of the build process, including what ACTUALLY went wrong with the run script build phase (as opposed to just the fact that it failed to execute properly, which is what exit code one means).

  42. Mihai
    January 19, 2010

    Help. I am using os 3.1.2 xcode 3.1.4.

    I followed the steps in the article, i modified the script with the comment from jk. When i try to build the following build errors appear :

    – Command /bin/sh failed with exit code 1
    followed by
    – Codesign error: no certificate was found in your keychain for the specified identifier “iPhone Developer”

    With the keychain tool i see the created certificate tough it’s not trusted.

    Anyway it seems that xCode builds something because i have in the directory Release-iphone os an .app file,

    i tried to transfer it on the jailbreacked iPhone and set the rights to execute , restart the springboard , but the application crashes.

    Please someone help me ,because i am running out of solutions for deploying on the iPhone.

    Thank you.

  43. Gilad
    January 30, 2010

    The new guide (p=354) state requirements as:
    iPhone OS 3.1.2
    Xcode version 3.2.1, 64 bit
    Mac OSX 10.6.2 Snow Leopard

    What if I am using Xcode 3.1.4 and Mac OS 10.5.8 (Leopard)?
    Thanks,

  44. January 30, 2010

    This one should work. Let me know what snags you hit.

  45. Gilad
    January 31, 2010

    Thanks for your help.

    My dev environment: Xcode 3.1.4, iPhone OS 3.1.2, OS X 10.5.8.

    I am getting
    ‘iPhone developer: no such identity’ error, when it is running the custom shell command:
    /Developer/iphoneentitlements30/gen_entitlements.py “my.company.${PROJECT_NAME}” “${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent”;
    codesign -f -s “iPhone developer”

Leave a Reply

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