Developing for a Jailbroken iPhone A to Z (iOS 4.0.1)

Jailbreak Development for iOS4!

Vital Stats:
iOS 4.0.1
Xcode 3.2.3
Mac OSX 10.6.4 Snow Leopard
iPhones 3G, 3GS, 4 (I finally have the whole lineup!)

PROBLEM: I still can’t get iPhone 4 working. If you have one, please try it and help me out! UPDATE: Found the cause of the problem to be certain status bar libraries installed alongside other apps. I’m not sure why they cause the problem, but see full notes at the bottom of the post.

The Goal: As usual, we want to be able to click “build and go” in Xcode and get the app we’re working on to load to the phone and start up. Also, we want to be able to debug from within Xcode itself. After all, Xcode is cool, and terminal+makefiles+gcc+gdb is lame.

Abstract: The plan remains unchanged from the 3.x method. In fact, you commenters practically wrote this one for me. This time we’re going to tell Xcode that it doesn’t need to codesign for iPhoneOS targets, then we’re going to tell it don’tcodesign for iPhoneOS targets, then we’re going to tell it, well, actually, codesign but do it using our script, not your built in method.

The Process: With Xcode closed and your device unplugged from the computer,

    1. If you’ve done this step before for previous guides, you may ignore it. You’ll need a code signing identity in order to sign code to run on the device. Normally, this would be issued by Apple, but later on we’ll break the signature check so you can make a “Self-Signing Identity” using this guide from apple (coral). Note that you should name the identity “iPhone Developer” EXACTLY to avoid having to change a bunch of the steps below.
    2. On your jailbroken iPhone, install the app AppSync. Add the source http://cydia.hackulo.us to cydia. You’ll get a warning about pirating software: this patch, by virtue of breaking Apple’s DRM so that we can install our own app, also enables us to install cracked App Store apps. Don’t do that. It’s immoral, fails to support legitimate developers who should be rewarded for their effort, and perhaps above all, pirating $2 cell phone apps is just ultra lame. But since our purposes are not nefarious, dismiss the warning. From this repo, install the package AppSync for OS 4.0, and for good measure, reboot the device.
    3. Make some Plist adjustments, starting with SDKSettings.plist:
      cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
      sudo cp SDKSettings.plist SDKSettings.plist.orig
      sudo vi SDKSettings.plist

      Find

      CODE_SIGNING_REQUIRED
      YES

      and change YES to NO
      then find

      ENTITLEMENTS_REQUIRED
      YES

      and change YES to NO again. HINT: in vi, you can type the ‘/’ key in order to “Cmd-F”

    4. Now, move on to the platform Info.plist
      cd /Developer/Platforms/iPhoneOS.platform/
      sudo cp Info.plist Info.plist.orig
      sudo vi Info.plist

      Two times, the following appears:

      CODE_SIGN_CONTEXT_CLASS
      XCiPhoneOSCodeSignContext

      Find each occurrence and replace the block

      XCiPhoneOSCodeSignContext

      with

      XCCodeSignContext
    5. And now the real bad boy, some binary patching of Xcode:
      cd ~/Desktop
      vi script

      hit the “i” key and copy/paste:

      #!/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
      /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

      type the keys, in order: “:” “x” “enter”

      chmod 777 script
      ./script

      If it works right, you should see something like

      $ ./script
      223+1 records in
      223+1 records out
      111648 bytes transferred in 0.002678 secs (41692099 bytes/sec)

At this point, you’re done telling Xcode it doesn’t need to codesign. Now, we tell it don’t codesign:

    1. With a new project open and ready to go (presumably you want to debug this one, though once you change these settings once, they’ll persist from project to project) open Project>Edit Project Settings (from the menu). Click on the “Build” tab.
      Find “Code Signing Identity” and its child “Any iPhoneOS Device” in the list, and set both to the entry “don’t code sign”

      Screen shot 2010-01-11 at 1.05.42 AM
      Should look like this

      Now you’ve told Xcode “don’t codesign.”

 

  1. Almost done: time to tell Xcode “well, actually you should codesign.”
    mkdir /Developer/iphoneentitlements401
    cd /Developer/iphoneentitlements401
    curl -O http://www.alexwhittemore.com/iphone/gen_entitlements.txt
    mv gen_entitlements.txt gen_entitlements.py
    chmod 777 gen_entitlements.py
  2. Just hit cancel.

    And finally, to link the device and computer. Plug your iPhone in and open Xcode. Open Window>Organizer. Select the device from the list on the left hand side, and click “Use for development.” You’ll be prompted for a provisioning website login, click cancel. It’s there to make legitimate provisioning easier, but doesn’t make illegitimate not-provisioning more difficult.

Now you’re good to go! But there’s just one last thing. You have to do this last part for every new project you make. Go to the menu Project > New Build Phase > New Run Script Build Phase. In the window, copy/paste this:

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

That will call the script you just downloaded in step 5 to sign our app with a fake signature. This is important only for debugging. If you do build and go otherwise, the app will load to the phone, but the app will fail to launch and you’ll get:

Error from debugger: The program being debugged is not being run

That should do it. Take all those steps and you should be home free for JBDev without paying $99.

CREDITS: Once again, credit for this process goes to various posters in this forum thread at iphonedevsdk.com. All of these steps are there somewhere, it just took a while to re piece them together in the right combination.

iPhone 4 Issue (UPDATE see below): So the method above has been tested working for my 3G and my 3GS. I don’t have my 2G right with me, but I expect it’s no different from the previous method, given that it can’t run iOS4.

The problem that I run into is this:

[Session started at 2010-08-04 20:35:02 -0400.]
//GDB stuff
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-93925-69
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
run
Running…
[Switching to thread 11523]
[Switching to thread 11523]
continue
warning: Unable to read symbols for "/Library/MobileSubstrate/MobileSubstrate.dylib" (file not found).
// A bunch of other lib load warnings like this here...
warning: Unable to read symbols for "/Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.0.1/Symbols/usr/lib/libcrypto.0.9.8.dylib" (file not found).

Debugger stopped.
Program exited with status value:45.

The killer is that the app installs, launches, crashes, and then launches fine manually. But I also can’t connect GDB to the running process after the fact either, GDB claims the process isn’t running. I have no idea what’s going on. Anyone?

What gives?!

UPDATE (8/3/10): Totally by chance I happened to read this article on TUAW today about FaceTime. I didn’t pay much attention until about half way down something caught my eye:

…rather significant My3G bug — when installed, you cannot use your iPhone for native software development….

I had initially thought that maybe third party software was to blame but I meticulously disabled each MobileSubstrate extension I had one at a time and ruled them all out. Turns out that wasn’t good enough. The (since fixed) My3G bug was exactly the source of this issue, but I had actually uninstalled My3G and the problem persisted. The issue, it turns out, is with the status bar library Intelliborn uses in their products, IntelliStatusBarIcons. BUT, it doesn’t stop there. By individually uninstalling apps, I’ve found that Backgrounder (and NOT libstatusbar) also cause a dealbreaking bug. Instead of the program exiting with status:45, the new error is “Program received signal: “SIGUSR1”. at which point the application hangs. Conveniently, the workaround is easy, if annoying: For your particular project title, add an Override in Backgrounder. Hopefully this IS a bug in Backgrounder and not a byproduct of its function. But at least now you can debug again!

So partly I’m dumb and partly this is just a bummer. Full story in this post, but the general idea is that gdb catches a SIGUSR1 from Backgrounder and you have to ‘continue’ through it. And obviously, disabling Backgrounder for your app prevents the signal from getting sent.

497 Comments

  1. dekz
    November 1, 2010

    Moses, it works for 4.1 you just have to change the build settings to use 4.1 instead of 4.0.

  2. Kevin
    November 1, 2010

    Heya
    Works like a charm on 4.1
    still some testing to do but it runs 😀

  3. November 3, 2010

    LUIS M and NIGEL I also have this reboot problem… I think it’s a problem that came from the iphone directly, (jailbreak?) because the behaviour is the same with an official xcode with another computer… so the solution must be there… perhaps a problem or bug from installd of mobile subsrate or installous …. donnt know… just leave me a comment if you found something (even over my web)

  4. Mattia Zanetti
    November 5, 2010

    Hi, i have this error when launch build and run ‘Command /bin/sh failed with exit code 1’. Any Suggestion? Thanks

  5. November 6, 2010

    working like a charm ! .. thnx zillions

  6. Wardster
    November 8, 2010

    Excellent work, very simple steps and worked first time for me with iOS 4.1, on an iPhone4

    Should tide me over until I get my developer account!

  7. Aadi
    November 12, 2010

    i got an error of provisioning profile does not have valid signature please help help

  8. Forve
    November 12, 2010

    People HELP!!!!

    such errors….how to fix????

    /Developer/iphoneentitlements401/gen_entitlements.py: line 1: {rtf1ansiansicpg1251cocoartf1038cocoasubrtf320: command not found

    /Developer/iphoneentitlements401/gen_entitlements.py: line 2: syntax error near unexpected token `}’

    /Developer/iphoneentitlements401/gen_entitlements.py: line 2: `{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}’

    /Users/user/Documents/test1/build/Debug-iphoneos/test1.app/test1.xcent: cannot read entitlement data

  9. Forve
    November 12, 2010

    anybidy please help….how to fix error that i posted above

  10. edson
    November 14, 2010

    it works!
    OSX 10.6.4
    iPhoneOS 4.1
    Xcode 3.2.4

  11. Anonymous
    November 18, 2010

    anonymous tip:

    i *heard* this works with Xcode4 and iOS4.2 by just modifying the paths that contain /Developer/ to /Xcode4/

  12. ikky
    November 19, 2010

    Can I tell you how much I HATE the VI editor?

  13. November 19, 2010

    THANK YOU SOOOOOO MUCH FOR THIS POST. MY3G Was causing the issue for me and I would never have figured that out if you hadn’t posted this.

  14. cloudlight
    November 22, 2010

    This worked for me too… IOS 4.1, iPod Touch 2g, Mac OSX 10.6.4, XCODE 3.2.4

  15. November 23, 2010

    Thanks!! great tutorial, though all seems to be right, the simulator keeps opening to debug instead of my iPhone.
    my specs: hackintosh 10.6.4
    xcode 3.2.4
    iPhone 3GS iOS 4.1

  16. November 23, 2010

    ha! mim mistake i forgot the simpliest of all change the dropdownlist from the left on xcode to deploy on device!

  17. Andy
    November 26, 2010

    Works with 3.2.5 iOS4.2.

  18. edoardo
    November 26, 2010

    it worked for me!!!!!
    OSX 10.6.5
    iPod Touch OS 4.1 (iTouch 2G)
    Xcode 3.2.4
    the only thing I would say, also if is obvious, is that in XCode we have to set “Device” in spite of “Simulator” in the menu in the top of the window project. Another little thing to know is that the iPod reboots after the installation. (no big deal btw 😉 )
    Thanks for the tutorial!!

  19. Lance
    November 27, 2010

    I have the same problem, the iPod reboots after the installation, and xcode says “YourApp has exited with status 15.” How could I fix this? because I really want to debug on ipod touch. Thanks!

  20. Jarina
    November 28, 2010

    Work perfectly!
    Thank you so much alex!.
    iPhone 4 (4.1)
    Xcode 3.2.4
    OS X 10.6.5 \o/

  21. Frank
    November 29, 2010

    Hi there – I got it working – almost. I get the following compiler error though (on a stock project):

    /bin/sh: /Users/my_name/Desktop/wipeme/Untitled/build/Untitled.build/Release-iphoneos/Untitled.build/Script-C10EE31412A3F2FE008C55CF.sh: export: bad interpreter: No such file or directory

  22. Frank
    November 29, 2010

    Actually – it is working now for some reason, however now I am getting this:
    Error from debugger: The program being debugged is not being run
    – despite the Script.
    To put it into your words: what gives?
    Cheers.

  23. Frank
    November 29, 2010

    Actually don’t worry – it seems it’s just my iPhone being a bit … wobbly-ish. Not sure, but every 2nd or 3rd time i build and run it works.
    Thanks a billion times for this! This is just too great!!!!

  24. Alberto
    December 3, 2010

    Hi Alex,

    I cannot mange it to work. My config is:
    – MacOSX 10.6.4 under VMWare
    – Xcode 3.2.4
    – IOS 4.1

    I´ve followed all the steps but when try to “Build” (not “Build & Run”, just “Build”) i get:

    /Users/user/Documents/CityGuide/build/CityGuide.build/Release-iphoneos/CityGuide.build/Script-CE184C9A12A979F20010C79E.sh: line 4: /Developer/iphoneentitlements401/gen_entitlements.py: Permission denied

    and the .xcent file inside the .app package is not generated. Any hint ???

  25. Alberto
    December 3, 2010

    Woooww !! Never mind !!!

    I had forgotten to chmod to 777 the .py script !!!!

    Shame on me !!!! (after all, it´s my 1st week on macos world !!)

  26. Zick
    December 3, 2010

    Hello,

    thanks for that. But, it is weird… I don’t have to add the build phase in order to make it work. I try to test my app in my iphone without adding this phase and it works like a charm…

    Anyway, thanks a lot

  27. December 5, 2010

    I have problems running my app after this method on my iphone 3G 4.2.1, the app won’t run! and the icons are not render well.

    specs:
    Macintosh 10.6.5
    xcode 3.2.4 (set to ios 4.1)
    device: iphone 3G 4.2.1

  28. EvaZq
    December 6, 2010

    hello
    First of all thanks for this tutorial i have been searching a lot until get here

    I am running a “hackintosh” using iAtkos

    and I have to develop this application for iOS for one of my classes

    my problem is that i can’t connect mi iPod touch to my “hackintosh” because this is not detected, i can use usb pen drivers usb mouse but not my ipod touch

    is there any way to connect my ipod touch via wifi ???

    thanks in advice

  29. Jacky
    December 6, 2010

    it work on SDK4.1 Thank you so much.
    How about new version (SDK iOS4.2)

  30. Andrzej
    December 10, 2010

    Hi.
    I have xcode 3.2.5 iOS 4.2

    I try to debug on ipod touch 1st gen ( 3.1.3)

    But so far no luck

    I get CodeSign error: code signing is required for product type ‘Application’ in SDK ‘iOS 4.2’

    Have anyone tried on iOS 4.2 ?

    Thanks in advance

  31. Andrzej
    December 11, 2010

    Never mind 🙂
    Works perfect now.
    Probably I’ve made some mistake during this process.

    Many thanks for this tutorial. Great job.

  32. shutupsitdown
    December 11, 2010

    I’m trying this with 4.2, aside from the directory changes, all seems well. Running under VMWare though, I run into issues with my OSX virtual machine. My iPhone is detected, but get’s stuck setting up the debugging symbols. During that second copy it consistently hangs. Disappointing. But at least I can manually bundle up an .ipa and sync it through iTunes. Thanks for the easy walk through on how it’s done.

  33. David Schiefer
    December 12, 2010

    Mine builds fine, but when I click on “Build & Run” it comes back with: Please verify that your device’s clock is properly set, and that your signing certificate is not expired. Looks like this doesn’t work on iOS 4.2.

  34. Drew Walter
    December 12, 2010

    With iOS 4.2.1, whenever I try to build and run I get a “/app/dir/xxxx.app/xxxx.xcent: cannot read entitlement data” error. Help?

  35. Drew Walter
    December 12, 2010

    Never mind, just had to change the directory of the Python script.

  36. ferdi
    December 14, 2010

    Hi, thx for the tutorial!
    everything worked well for me, but when i try to build and run the app, it says that the script exited with status 1.

  37. December 22, 2010

    It works, But I got a problem , I can’t build with simulator, just left “Device” to bulid, how to solve this? thx again

  38. kamax
    December 24, 2010

    doesn’t work for me. i get “iPhone Developer: this identity cannot be used for signing code” from the script.

  39. December 30, 2010

    Same as Kamax
    it must be something related with the certificate.
    The certificate assistant (the first page) differs from the apple.com tutorial
    it adds one thing that says “Certificate Type: S/MIME (Email)” as Default
    any idea?

    (I’m with the latest version of the SDK – 4.2)

  40. December 30, 2010

    Damn, it was easy
    Just changing the above mentioned option (Certificate Type) to Code Signing and that’s it
    WORKING 😉
    Thanks for the tut!! it’s excelent
    Maybe you consider this NOTE for people getting new Code Signing Certificates
    Thanks again!!!
    byee

  41. Leopold
    January 4, 2011

    Please someone help:
    Running Mac OSX 10.6.5 with Xcode 3.2.5 64-bit
    developing for iOS 4.2 on iPod3G with iOS 4.0 jailbroken with limera1n (unthetered)
    i made all the passages, but when I press cmd + B to build I get an error:
    Code Signing Identity ‘Real Apple Code Sign Here’ does not match any valid, non-expired, code-signing certificate in your keychain.

    In Certificate Assistant (i made this many times… I’m sure not to have forgotten anything)
    1. I make a new certificate with name “iPhone Developer”
    2. I change certificate type to Code Signing
    3. I override default settings
    4. I delete my email address from the third tab and leave “iPhone Developer” as name.
    5. I leave anything else as it is
    I’ve also tried to set the certificate as trusted, but I have always the same error.
    * I have my project ready and in the simulator it works.

    please also email me at [email protected]… I’m not sure to visit this site often

    Thanks

  42. Justin
    January 4, 2011

    Regarding the bug that produces the message Program exited with status value:45.

    Yes this is caused by My3G. No, it has not been fixed. I emailed Intelliborn and am waiting back for an answer.

    If you uninstall My3G, the problem goes away. You can always reinstall My3G when you need it, although that’s an awfully annoying fix.

    Running 4.7.1, the latest published version at this time. Maybe I’m missing something, any tips? I haven’t installed Backgrounder.

  43. xxx
    January 7, 2011

    Did someone have some luck with XCode 4 beta 5? Are there some further tricks?

  44. Lukasz
    January 8, 2011

    Worked on my iphone 4 (4.1) with SDK 4.1 OSX 10.6.4

    Thanks for the great info!!!

  45. Brainion
    January 9, 2011

    Running xcode 3.2.5 and 4.2 SDK … after going through the steps
    it doesnt see the iosdk anymore …
    Like the missing basesdk, except for that i cant fix it in Projectsettings 🙁
    everything else seems to have worked ok, only the script transferred some more bytes..
    231+1 records in
    231+1 records out
    115768 bytes transferred in 0.002458 secs (47096623 bytes/sec)

    Any ideas?

  46. Leopold
    January 9, 2011

    @Brainion: I noticed it transferred more bytes, but since I don’t exactly know what the script does, I thought it was just because I had a different version.
    I tried older version but I’m stuck at the same problem

  47. Daniel
    January 9, 2011

    CodeSign error: The entitlements file ‘/Users/XXXX/Desktop/daniel/cats/NO’ is missing

    Anyone get this error? :/
    using 3.2.5
    sdk 4.2

  48. Daniel
    January 9, 2011

    My bad, I missed a step when I actually tried using this.

    Thanks a lot! really appreciated!

Leave a Reply

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