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. kp
    July 10, 2011

    Hi Dieg, I am not sure what the problem was and why I was getting those errors. After setting up the certificates, I restarted the machine and created a brand new project, that solved the problem. But still I am not sure what the problem was.

  2. CamiloSot
    July 10, 2011

    hi there guys, i have done the process with luck :D, so nice, now its probably that join a company so there i need back xcode, to the init point, so if i reinstall, evrything its as the first time install??

  3. Jake
    July 12, 2011

    Mine keeps saying

    iPhone Developer: this identity cannot be used for signing code

    Command /bin/sh failed with exit code 1

    Any help?

  4. Xcoder
    July 15, 2011

    With Xcode 4, the process can be simplified:

    1. Create the self-signed cert.
    2. Install AppSync on your device.
    3. Edit /Developer/Platforms/iPhoneOS.platform/Info.plist
    4. For each project, copy /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/Entitlements.plist to your project and add get-task-allow to the bottom before . Edit Build Settings -> Code Signing -> Code Signing Entitlements and set it to Entitlements.plist

    This removes some old steps:

    1. There is no need to edit SDKSettings.plist because we’re letting Xcode do the signing/entitlements.
    2. There is no need for the Xcode binary patch.
    3. There is no need for custom build phases or the gen_entitlements.py script.

  5. James
    July 18, 2011

    I have followed everything here, but the first time I did it, I clicked on link device and gave it my username and password which came back saying it is not do-able as you not on the team.

    then i read the rest of tutorial and trying to get it done, as I press cancel but no luck. Any advice on how to turn this orange light, green please.

    thank you

  6. Ripflame
    July 22, 2011

    I tested this after installing Lion OS and Xcode 4.1 it works just fine, if you updated from Xcode 4.0 then you’ll have to do this again, great post for us starting in iPhone Development

  7. wetwilly
    July 27, 2011

    I am using Xcode 4.1 and unable to build. I did click “Don’t Sign” on two different areas (SDK “debug” and “release”), but i assume that the screen shot above that only had one was due to an earlier version of Xcode. Any advice?

    My error:
    Check dependencies
    [BEROR]CodeSign error: code signing is required for product type ‘Application’ in SDK ‘iOS 4.3’

  8. JamesA
    July 27, 2011

    I’m trying (and failing) with Xcode 4.1 and iOS SDK 4.3 also. My situation is I can get the project to build but I can’t find the .app to install. I’ve done a little digging and there appear to be some cached .app files in ~/Library/Developer/Xcode/DerivedData/… but they don’t run on my device (instant crash). I’m not sure if these are the actual build files? Any ideas?

  9. JamesA
    July 29, 2011

    I figured it out. Here’s help for the next newbie, beside the the “Run” button there is a drop-down list containing a list of devices to build for “iOS Device”, “iPad Simulator 4.3”, “iPhone Simulator 4.2”. Plug in your device and choose “iOS Device” before building.

  10. July 30, 2011

    No, you have to have an official certificate to sign in prep for the official Apple App Store. No way around it. But keep in mind, even if you could get around it, you still have to be a paying developer to have all the online access to the app store to get your stuff listed anyway, so it’s not even logical that there’d be a way to avoid it.

  11. Artyom
    July 31, 2011

    I want to send demo version of app to customer for testing …
    so anyway I need certificate ? :/ 🙂

  12. Sachin Ahirrao
    August 5, 2011

    Hi Alex,
    I have done all procedure above,but when i debug still code sign error occure.
    I used iphone 4,iphone os 4.3,macos 10.6.8.

    So please help me.

  13. daPeeper
    August 5, 2011

    @Xcoder

    Thanks for your recent comment. I have just installed the latest Lion on VMWare and latest Xcode 4.1.1 on my XP computer and had managed to get everything to work except the running of an app on my iPad. It would build and install but then close immediately with the usual error message. The App worked fine if I ran it manually.

    Then I read your comment and made the change to my Entitlements.plist.

    Except for Lion, on my VM, it only allows the binary key

    “Can be debugged” = YES

    It will not accept “get-task-allow” even if I try to type it in.

    Anyway I decided to keep the “Can be debugged” key and added the plist to my project and changed the project code signing Entitlements to this file as you suggested. Run and lo and behold it installs the APP and then for the first time ever, runs it in debug mode on my iPad. Yahhh!

    Thanks again for that little gem. Saved me a lot of searching and hair pulling.

  14. Horst
    August 10, 2011

    Does this still work with current Xcode And iOS?

  15. Sam
    August 13, 2011

    Thanks Alex for the continued support!

    @Xcoder (and Alex ofcourse!) – I cant seem to deploy to the phone (4.3.3. JB) it compains about the certificate.. (I had this working on a previous release).

    1. IF I wanted to follow Xcoder amendments, what if I already modified the binary, am I in trouble?

    2. I dont understand step 4..
    “4. For each project, copy /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/Entitlements.plist to your project and add get-task-allow to the bottom before . Edit Build Settings -> Code Signing -> Code Signing Entitlements and set it to Entitlements.plist”

    So basically do I drag the “Entitlements.plist” into the project hierarchy, and add “get-task-allow” before the “.”, note I dont see the fullstop in Entitlements.plist atm..

    Thanks
    Sam

  16. Sam
    August 13, 2011

    To also clarify.. I deleted my original certificate – was still current, about to expire tho.
    Re-created using these steps: http://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html (from Alex’s instructions)

    1. The second part of the tute “Adding an Info.plist to Single-File Tools” is not required yeah? i.e. the code signing business is handled by xcode and the required configurations i.e. build phase script etc.

    Thanks
    Sam

  17. Hung Le
    August 18, 2011

    Thanks for your tutorial. But after following these steps, I get this when I build my project:
    Code Signing Identity ‘iPhone Developer: Devin Doty (294DDWXTAY)’ does not match any valid, non-expired, code-signing certificate in your keychain.
    Can you please help?
    Thanks.

  18. philions
    August 20, 2011

    before Lion, it works perfectly, but after updating to Lion and xcode4.1, it failed, anyone work it out?

    Check dependencies
[BEROR]CodeSign error: code signing is required for product type ‘Application’ in SDK ‘iOS 4.3′

  19. gambitasdf
    August 27, 2011

    So these instructions no longer work for Lion and Xcode 4.1?
    Anyone have a tried and proven method for deploying to JB iphone4 with latest lion and Xcode?

  20. Sam
    August 28, 2011

    Hi all,
    I used to have this working, I re-installed mac os, and installed xcode 4.0 with sdk 4.3.
    I have a jb 3gs 4.3.3.. should this work?

    I get a certificate error.. but cant see what I have done wrong.. any ideas?

    Error: “the identity used to sign the executable is no longer valid”

    Thanks
    Sam

  21. developer
    August 28, 2011

    works very well using xcode 4,10.6.8 and ipad with ios 4.3.5

    thanks a bunch 🙂

  22. September 3, 2011

    Hi! It actually works with the new Lion and xCode 4.1..

    Change this line:
    cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk
    to:
    cd /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk

    and make sure you do the xCode patching (the “bad boy”) again.

    That’s it!

  23. Yero
    September 11, 2011

    Nice Work,
    Ok with Lion & XCode 4.1

  24. Luqman
    September 17, 2011

    help me, I don’t get step 5.
    any screenshot?

    I’m new to terminal. thanks.

  25. mikje
    September 18, 2011

    i get a message: “iPhone developer: this identity cannot be used for signing code”, and my build failed

  26. mikje
    September 18, 2011

    already works for me since i made an error with creating the cerificate. However build and archive is not creating an ipa file, but crashes. Any solutions to this? I run mac os 10.6.6 under vmware

  27. Andrey Roth Ehrenberg
    September 25, 2011

    I Have xcode 3.2.6, and I did all the steps above, but now my XCode gives 3 error alerts when I open a new project, and my iPod touch isn’t recognized by the system anymore. Any help?

    XCODE ERRORS:
    File: /SourceCache/DevToolsBase/DevToolsBase-1809/pbxcore/Target.subproj/PBXTarget.m
    Line: 1613
    Object:
    Method: createPropertyExpansionContextWithBuildState:

    Platform failed to completely load. Examine Console Log for error messages.

    File: /SourceCache/DevToolsBase/DevToolsBase-1809/pbxcore/Target.subproj/PBXTarget.m
    Line: 1613
    Object:
    Method: createPropertyExpansionContextWithBuildState:

    Platform failed to completely load. Examine Console Log for error messages.

    File: /SourceCache/DevToolsBase/DevToolsBase-1809/pbxcore/Target.subproj/PBXTarget.m
    Line: 1613
    Object:
    Method: createPropertyExpansionContextWithBuildState:

    Platform failed to completely load. Examine Console Log for error messages.

  28. dev34
    October 14, 2011

    Did anyone try to run this with xcode 4.2 and ios sdk 5.0 ?

  29. ANASS
    October 15, 2011

    works with xcode 4.2 – ios sdk5.0

  30. zach
    October 15, 2011

    works in Xcode 4.2, except the plugin you patch moved to here:

    /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin

  31. Fal
    October 17, 2011

    If you get an error 0xE8008018, you have to install AppSync 5.0 from Hackulous

  32. ernipiggy
    October 18, 2011

    Still works with Xcode 4.2 and iOS 5! (iPhone 4)
    I had Xcode 4.X already binary patched for iOS 4.3 before so I only skipped Step 5 and it worked =o)

  33. Spak
    October 20, 2011

    Not working with iPhone 3G (4.2.1) and XCode 4.2 with iOS 5… Everything works but the application doesn’t get installed on the device, and instead I see “Finished debugging on iPhone of …”. I tried many times (reinstalling XCode too). Everything fine with XCode 4.1 and SDK 4.3.1 until the update to 4.2. Maybe my ‘old’ iDevice isn’t fully supported by iOS SDK? I used this method for months and many different SDKs, it always worked. Does debugging work with a real provisioning profile on 3G and 4.2??

  34. Eskyo
    October 20, 2011

    Hey there, trying to run on xcode 3.2.6 with iphoneSDK 4.3 on Snow Leo 10.6.8 and after following all the steps I got this error:

    Env: python\r: No such file or directory

    /Users/xxxxx/Documents/graphene/build/Release-iphoneos/graphene.app/graphene.xcent: cannot read entitlement data

    I’ll really apreciate if someone could help me.
    Thanks

  35. Spak
    October 23, 2011

    @Eskyo
    Try checking if you’ve done step 7 correctly… gen_entitlements is a python script that creates the .xcent entitlement file (I think 😉 ) .. It seems that your system cannot run the python script.

  36. Ryan
    October 24, 2011

    Sorry if this seems terribly basic, but do I just put those commands into terminal?
    Thanks

  37. elestigio
    October 26, 2011

    Good morning fellow, I am new to the Mac OS terminal and I have some difficulties in step 5 in order to run the script. after making a copy / paste. I am using the sdk xcode 3.2.5 and 41. Thanks in advance for your help and guidance.

  38. eskyo
    October 26, 2011

    @Spak

    Hey,
    I’ve repeated all the process a couple of times and still the same result. Once It seemed to work but after restar I’ve got the same message.

  39. eskyo
    October 26, 2011

    Finally solved the problem, /r was a “invisible” character, just deleted the space before python and added it again.

  40. Ludger Heide
    October 29, 2011

    @Spak:
    In my case, the architecture was automatically changed to armv7 even in old projects and that kept my App from running. I had to manually change the architecture to armv6 *only* (Build Settings –> Architecture –> Architecture), and then it worked like before.

  41. Spak
    October 31, 2011

    @Ludger Heide
    Thanks for the suggestion, I didn’t notices the change. I had to change also another option:

    1) Project>Targets>Info
    Required device capabilities
    -> Item 0: “armv6” (instead of “armv7”)

    2) Project>Targets>Build Settings
    Architectures
    ->Choose “Other” and leave in the list only “armv6”
    [instead of “$(ARCHS_STANDARD_32_BIT)”]

    as you said.

    …so now XCode 4.2 + iOS 5.0 + iPhone 3G 4.2.1 is working!

  42. TechniX
    November 2, 2011

    Attempting to do this trick on Xcode 4.2, iOS 5.0 and non-jailbroken iPad 2 running iOS 5 GM, but WHERE IS THE FILE TO CHANGE?!?

  43. Mr
    November 2, 2011

    I GET an error

    ″his provisioning profile does not have a valid signature (or it has a valid, but untrusted signature).″

    help needed

  44. November 2, 2011

    It’s kind of irrelevant, since you won’t be able to load the compiled project to a non-jailbroken device anyway. That’s pretty much the point of this whole exercise. I expect that iOS 5 will be a little different, but I don’t know exactly how, since there is no untethered iOS 5 jailbreak yet (I’m not a fan of tethered, so I haven’t updated yet).

  45. hexdump
    November 10, 2011

    @Ludger Heide

    Thanks for the tip buddy. I was getting crazy with my projects not running anymore.

  46. avi lugassy
    November 12, 2011

    Hi,

    Just successfully built this on iOS4 using SLeopard 10.6.8 with SDK (xcode_3.2.5_and_ios_sdk_4.2).

    I built and ran the application no problem 🙂 Fantastic walk through, I want to develop and will purchase the licence when I am ready to roll, thanks so much for helping me develop my applications on my Own Device, this was awesome.

    NOTE:
    For new comers,

    Step 2) Run Cydia, click on Manage, Select Sources, Click “edit”, Click “add” and type: http://cydia.hackulo.us
    After, Click Manage, Select Sources, Click that source and install AppSync.

    also
    Step 3 is referring to an application on your Mac and not your iphone, that application is called the “terminal” and can be found under utilities in your Finder-applications-Utilities window.

    Thanks again for the fantastic guide,
    My above comments are to help those who are not so familiar with hacking their macs, or phones.
    Be well

  47. Mihael
    November 15, 2011

    Hey i just wanted to thank you for this article!
    After many attempts with all different methods on all different sites and blogs this
    method finnaly did job right.

    My configuration>

    Jailbroken Iphone iOS 4.3.2
    VMWare Mac OSX Lion
    XCode 3.2.3

    I could debug run and deploy on device. Thank you!

Leave a Reply

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