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. August 2, 2009

    It’s alright, this post has 150 freaking comments. I’d try reinstalling from cydia, but other than that, I don’t exactly know since I’ve never tried this on a 3GS. I think others have succeeded, but I’m not sure. If that doesn’t work, I can try emailing the other guy to see if he can be more specific. That is, if the email address he used to comment was legit 🙂

  2. faktor
    August 2, 2009

    It’s a popular post :). Looks like installd had an issue. I keep getting an error trying to install it. I tried AppSync instead and was able to get my test app onto the phone! Awesome! Thanks for pointing me in the right direction.

  3. noob
    August 3, 2009

    Thanks Krit for the advice about “The identity used to sign the executable is no longer valid.” error.
    (I thought i had installed installd but hadn’t)

    If you are using OS 3.0.1, installd wont install. You need to install AppSync instead.

    to the OP, I think you should mention that the signing identity needs to be called “iPhone Developer” because thats what is used in the “New Run Script Build Phase”.

  4. noob
    August 3, 2009

    oh yaa and thanks Alex, it works!

  5. August 3, 2009

    No problem. I’ll make a mention of the possible need for AppSync instead of Installd if you’re on a 3GS or 3.0.1.

  6. mars
    August 4, 2009

    ive gone thru assignment 2B, im actually on 3 now, but my question is, in the awakeFromNib which they suggest we use, i call the

    PolygonShape *polygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];

    but when i do, everything runs fine, it compiles, runs, but with a warning saying that “unused variable polygon”. Which is not true, i use the polygon object in many places. i comment it out and it runs just the same but without the warning. any ideas why? its just buggin the crap outta me 🙂

  7. mars
    August 4, 2009

    one more question, again not critical but its buggin me. going thru the nib file and the property inspector/connections inspector, ive been analyzing it to get a grasp. the only thing i noticed that calls my attention is:

    1. Controller object has a change action which isnt connected to anything. Not like the increase or decrease actions are connected to the buttons. Why not?

    2. the window object doesnt show (window) as an outlet in the Window Identity Inspector like the controller and hellopolyappdelegate and the files owner show outlets. It only shows (window) as an outlet in the connections inspector. Why doesnt it show (polygon) as an outlet in the Identity Inspector under Class Outlets?

    3. the polygonshape object doesnt show (polygon) as an outlet either in the Window Identity Inspector. It only shows (polygon) as an outlet in the connections inspector. Why doesnt it show (polygon) as an outlet in the Identity Inspector under Class Outlets?

  8. mars
    August 4, 2009

    A more serious question from objC. Im reading this code in lecture 3:

    #import “Person.h”

    – (BOOL)canLegallyVote {
    return ([self age] >= 18);

    – (void)castBallot {
    if ([self canLegallyVote]) {
    // do voting stuff
    } else {
    NSLog (@“I’m not allowed to vote!”);
    }

    in the canLegallyVote method, does ([self age] >=18) EQUAL TO if([self age] >= 18) or did they just forget the IF keyword?

    in the castBallot method, shouldnt it read if ([self canLegallyVote = YES]) …

  9. August 4, 2009

    1. If you can comment it out and it runs the same (assuming you’ve tested every aspect) then, in fact, it’s never used. Could you perhaps be declaring it somewhere else, and that declaration is in a different scope?

    2. In order for methods to show up as actions in IB, they have to be declared as

    – (IBAction)doStuff; instead of as
    – (void)doStuff;

    They’re the same programatically (IBAction evaluates to void) but IB looks for those cues to include things. Similar for ivars: they have to be declared as (IBOutlet)s. That could be your confusion, but maybe not.

    3. Part 1: If you take the line
    return ([self age] >= 18); and break it down into sub pieces, the first thing to get evaluated is [self age]. Let’s say this returns 17. Then it’s (17 >= 18). It’s not, so this part evaluates to boolean NO (in other languages, this might be FALSE or 0). The whole line therefore equates, in this case, to

    return NO;

    which means the whole method returns boolean NO, this person can’t vote.

    Similarly, below is also a logical statement. You could do it your way, but it’d be redundant (That’s not actually true, you have a few mistakes). the IF structure simply evaluates its condition and looks for boolean YES or NO. Assuming our conditions above, [self canLegallyVote] will evaluate to YES, so the if statement is satisfied and will continue. Similarly, if we rework your statement so it’s correct:

    if ([self canLegallyVote] == YES) %note that I made it a comparison instead of an assignment, this method isn’t set up to handle an assignment. Also, you have to bring the logic out of the message [] part. If you DID want to set this to yes, assuming you could, it’d be [self canLegallyVote:YES]

    [self canLegallyVote] evaluates to YES, and YES == YES evaluates to YES, so the if statement is similarly happy.

    Let’s say you wanted to check that the person COULD NOT vote, you’d have your coice of

    if ([self canLegallyVote] == NO)
    or
    if (![self canLegallyVote])

    I don’t think either is less or more efficient, although I’d probably choose the first one just to be really obvious in code.

    OH: Also, I’m sorry I never actually got back to you about your email, you said you figured it out and moved on?

  10. mars
    August 4, 2009

    1. Well, that statement includes the polygon definition, its alloc and its initwith. So yes, i suppose its declared in the controller.h and then also autoallocated and then inited. i have no idea where its autoallocated though.

    2. Not that it doesnt show up as an IBAction, what i mean is, HelloPolyAppDelegate has an outlet to Window Object, and Window Object references HPAD. Controller has an outlet to PolygonShape and PolygonShape references Controller. But how is Controller connected to the HAPD or Window? Or it just doesnt need to be? And then FilesOwner has a Class Outlet called delegate id type but HAPD shows no connection to FilesOwner, this may just be the way it is i guess. I was just trying to make sense of it visually thinking about the MVC diagram so that when i have to design an app from scratch i have a better understanding. And now that im trying to fit the PolyView into the picture, I am trying to hook it up and i cant. Ive plugged in all the code. Ive dragged the UITextView onto the window and when i try to hook it up to the controller it wont let me, i dont know what im doing wrong.

    3. DUH. its a boolean and i hadnt really noticed. Of course that evaluates to a YES or NO which is later used in the castBallot method.

    I dont rememebr what the email was about, but i did get thru assignment 2B. Im on 3 and im having quite a time with it. I wrote as far as i could, then i found an answer online, found my mistakes and now im trying to connect the view to IB, but it doesnt seem to be working. Thats why I was asking the IB outlets and connections question.

  11. mars
    August 5, 2009

    hi alex. i havent heard from you in a while and i wanted to let you know that i figured out how to hook up the MC to the V. I honestly just copied the code for the model because i have no idea what all that crap is, i know its somehow calculating the points and feeding them into an array which is then used to plot them on the screen, but i couldnt get it to display. I finally got it working by looking at a much simpler UIView subclassing example and then i understood what it means to use the UIView subclass created to go to IB and drag a view onto your window and class it as a polygonView object with its oulet to the polygonshape class object. anyway, i can only get it to display the first state, pentagon, not the others. but in the meantime i wanted to ask you for a favor. can you start a new thread on just coding questions for NOOBs? the thing is that you have 160 posts now in this thread and the iphone reads your blog page without allowing the scroll to bottom option by double tapping over the + icon in safari. so i have a heck of a time (as im sure others do) getting to the posts from an iphone :). plus it would be neater to have a coding post, of course if you agree…its actually a suggestion

  12. August 7, 2009

    Hey Mars, sorry for the absence, there’s a new post for off topic questions as per your suggestion, and there’ll be an email in your inbox in a minute.

  13. Thiago
    August 8, 2009

    Hi everyone…

    I used this excellent method with success but now I´m paid for the certificates to use the AppStore. I did all the certificates proccess but I´m receiving the message CSSMERR_TP_CERT_NOT_VALID_YET. Is this because that I did the “unlock” before? Is there a way to undo this? Thanks everyone!

  14. zhz44
    August 12, 2009

    hi,
    i followed ur method, but it doesnt work for me, i assume the problem is the xcode path: the following is my output after execute the script, do u have any suggestion? thanks

    255+0 records in
    255+0 records out
    127500 bytes transferred in 0.002999 secs (42513217 bytes/sec)
    31312+0 records in
    31312+0 records out
    31312 bytes transferred in 0.345301 secs (90680 bytes/sec)

  15. kevin
    August 19, 2009

    okay i did all these steps and i did build and go on device 3.0 debug on my xcode but it says no provisioning OS iphone device is connected…

    but i did my code signing and ssh stuff from the other posts

  16. !nk
    August 19, 2009

    i followed all your instructons but when i click on “build and go” i get this error “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.WhereAmI’ could not be found”!

    do you know what i did wrong?

  17. rico
    August 21, 2009

    Thanks a lot Alex. every things seem to be ok.

    I have a 3GS with 3.0 firmware. I install AppSync on my device directly and it works fine.

    (sorry for my poor english ^^)

  18. kevin
    August 22, 2009

    Kevin, try restarting your machine and do it again. I had the same problem, then it worked.

  19. megaNoob
    August 24, 2009

    i ran through the process and all i get is xcode crashing ever time i open a old project or open a new project any ideas y?

  20. BuddingDev
    August 25, 2009

    Thank you!! Thank you !! Thank you Zim/Alex.. god bless.

  21. Ari
    August 28, 2009

    I get the “no provisioned iphone OS connected” error. I followed the instructions on this page exactly then restarted my phone and computer and did not try any other instructions prior. What can I do to fix this?

  22. August 30, 2009

    Does this trick work on New SnowLeopard [Retail] and on iphone SDK 3.0 final for Snow Leopard?

  23. guy
    September 4, 2009

    Followed all the steps the project is built and i get Succeeded (thanks very much for the cool guide)
    But… when i press Build and go after transfering the file to the iphone (2.2) and trying to open it i get: error from debugger: error launching remote program: security policy error.

    when i try to open my application for my iphone i get : the application “xx” cannot be opened

    any idea?

  24. cupiii
    September 5, 2009

    I can’t get it to work on snow leopard. Has anybody managed to get it work on xcode 3.2?

  25. nooby
    September 5, 2009

    I can’t get it to work on xcode 3.2 neither. “a valid provisioning profile matching …” build error is raised.

    I hope you will find a solution.

    Thanks anyway for this great blog post.

  26. fpb
    September 5, 2009

    I’m on the same boat. Have the same provisioning profile error in Snow Leo.

  27. nooby
    September 8, 2009

    It does not work because xcode is now compiled in 64bit. Look in the thread referenced in this blog post. An updated script was posted.

  28. AngelHide
    September 8, 2009

    I made it work with snow leopard, but didn’t use the updated script.
    I removed /Developer/Platforms/iPhoneOS.platform

    installed xcode 3.1 with iphone sdk 3.0 for leopard
    upgrade with xcode 3.2 and then upgrade with iphone sdk 3.0 for snow leopard
    launch the script above
    and it worked.

    I know kind of weird but tell me if it works for you guys.
    Have fun with iPhone sdk 🙂

  29. AngelHide
    September 8, 2009

    I found the updated script with the link above from alex.

    you can try this script with xcode 3.2 and iphone sdk 3.0 for snow leopard.


    #!/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=1 count=300752
    printf "\xc8\x2f\x00\x00" >> working
    dd if=iPhoneOS\ Build\ System\ Support of=working bs=1 skip=300756 seek=300756
    /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

  30. Zeroshade
    September 11, 2009

    Hi, I followed all the steps but I-m getting “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.Touch’ could not be found”. What can I do?

  31. tesla
    September 12, 2009

    Hi!
    I have an iPhone 2G with 3.0.1 OS installed on board. But my XCode 3.1.3 doesn’t see it! I used Installd and AppSync. But nothing helps! Firstly, when I connect iPhone, Xcode says that iPhone has unsupported OS. After “upgrading” XCode, it says: “This device is not currently connected.”
    Anyone can help me?

  32. September 17, 2009

    I’m having the same problem with XCode 3.2:
    “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.-4’ could not be found”
    I don’t know what to do, i tried the updated script mentioned above, and now my xcode 3.2 doesn’t quit unexpectedly, but still I cannot get past this error.
    Please help

  33. September 18, 2009

    Hello there Alex,

    I stumbled upon your post and had a go it works great, I did have to use AngelHide’s script to get it working though, but it works none the less. I do have one problem though.

    My projects compile properly using GCC 4.2 but when I change the compiler to Clang/LLVM which I find is better and faster, the build log spits out this error:

    error: can’t exec ‘/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc-4.2’ (No such file or directory)

    Currently I’m using XCode 3.2 and compiling to the iPhone SDK 3.0, I do have the update to 3.1 though. Any help would be appreciated. I’ll continue trying to weed out the problem and if I find a way I’ll post it here.

  34. September 18, 2009

    David: are you using snow leopard?

  35. September 18, 2009

    Yeah, I’m using snow leopard, it seems that its just on my old projects that I can’t compile with Clang/LLVM. I saw something on stackoverflow about it I might just look there for answers, guess it has nothing to do with this code signing bypass.

    Ummm, so ZeroXX if you tried to get it working with the old script try and bring back the /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin
    from Time Machine and run the new script again. Also check to see if you have a billion build scripts in your target application, not that it’ll screw your application up, it just takes longer to compile if you’ve gone over the instructions fully on an app more than once.

  36. September 20, 2009

    I did a clean install of OS X 10.6 and iPhone OS 3.1, installed xcode 3.2 + iphone sdk 3.1, then tried the above steps, with the updated script, but still it says
    “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.Proba1′ could not be found”
    Proba1 is my application’s name btw.. I don’t have any idea, the project is a newly created project, with just the updated script, no other things done to it. I looked at the Code Signing Identity property, and it says iPhone Developer, and Any iPhone OS Device, so I assumed that’s good too.
    Please help…

  37. September 20, 2009

    To make this work for Xcode 3.1.4 with sdk3.1 in i386 architectures
    just change the printf command to

    printf “\xc3\x26\x00\x00” >> working

  38. September 21, 2009

    How do I revert this back? I was unable to publish my App Store apps because xcode would no longer sign them. I had to reinstall xcode to get it to work…

  39. September 25, 2009

    To revert just enter

    /bin/mv -n iPhoneOS\ Build\ System\ Support iPhoneOS\ Build\ System\ Support.patched
    /bin/mv -n iPhoneOS\ Build\ System\ Support.original iPhoneOS\ Build\ System\ Support

  40. Jan
    September 25, 2009

    Anyone updated this patch to XCode 3.2 yet? The plugin seems to have changed, the “Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.Proba1′ could not be found” message still appears after the patch.

    Apparently we’d need to insert the NOP’s (or whatever the patch does) somewhere else for that plugin. Any magicians out there?

  41. ulon
    September 27, 2009

    Hi! For those people getting the error: “No provisioned iPhone OS device is connected”. Do The following:

    Unplug Iphone / Ipod from computer

    Quit Xcode (quit really: Check in Dock that it’s not running)

    Plugin Iphon / Ipod to your mac

    Wait until that harrying iTunes starts automatically, wait until it has synched your iPhone / iPod touch, and then switch iTunes off (Check in Dock that it’s not running).

    Start Xcode

    Build & Go

    Pray & have fun (hopefully)

    NOTE: forget about that Installd Patch and the above XCode script. It will work with just AppSync and the XCode script doesn’t make any difference.

  42. September 27, 2009

    Wish it would be that simple… Naturally, the solution you provided, ulon, is not working.. Still waiting for a solution to the provisioning problem.

  43. September 27, 2009

    Ignore my previous post… somehow it works.. Well not the way it has to work, but… I managed to install the application to the iPhone via the plist hack, and in release version. I set that the xcode should not sign the app. Build & Run, and it worked.
    In debug mode, it works too, but it’s not that kind of debug.. XCode cannot attach to the process, but I can still see the NSLogs under XCode’s Organizer. So it’s almost as good..

  44. September 27, 2009

    Hello) what about this problem???
    Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.yourcompany.
    os – mac os snow leopard
    xcode 3.2
    please think about the solution

  45. Joshua
    September 27, 2009

    This guide helped me to skip the provisioning error with xcode 3.2.

  46. September 27, 2009

    please can you compile the libmiss.dylib file and sent it to me??? e-mail [email protected]
    when i compile i get an error
    ld: library not found for -lmis
    collect2: ld returned 1 exit status

  47. September 27, 2009

    i’ve done everuthing that was written in that article but it doesnt work
    could you send me the files (2) [ libmiss.dylib and installd] to my email ([email protected])

  48. Joshua
    September 27, 2009

    I didn’t compile anything. The steps before step 5 were enough for me to compile and install my app.

  49. September 27, 2009

    but it doesnt work(((

Leave a Reply

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