How to develop on jailbroken iPhoneOS 3.1.3 using XCode 3.2.1

Hey there! I was exciting with my jailbroken iPhone 3.1.3 and even more excited that I can develop on it. In this post i’ll share how to develop on it using XCode 3.2.1 (or XCode 4.2) without provisioning profile.
This tutorial I combine from networkpx Project Blog and alexwhittemore blog as i couldn’t make it works by following full step of either one of those blog. Ok, this is the step that i did :

Firstly, please make sure that your XCode has support for iPhoneOS 3.1.3 SDK by check these folder:
/Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.1.3 (7E18)

and make sure your device already installed AppSync3.1

Compile the code
To compile you still need a certificate that can code-sign. Here is the procedure to create a self-signed code-signing certificate using Keychain Access. Make sure you create the certificate in the “login” (default) keychain, not the “System” keychain and name the identity “iPhone Developer” EXACTLY to avoid having to change a bunch of the steps below. After the certificate is created, perform these steps:
1. Open /Developer/Platforms/iPhoneOS.platform/Info.plist. (Backup if you want to be safe.)
2. Go to line 46. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
3. Go to line 79. Replace the XCiPhoneOSCodeSignContext with XCCodeSignContext
4. Save the file.
5. Open /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/SDKSettings.plist

and change YES to NO
then find

and change YES to NO again.
7. Patching the XCode
cd ~/Desktop
vi script

hit the “i” key and copy/paste:
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

type the keys, in order: “:” “x” “enter”
chmod 777 script

If it works right, you should see something like
255+0 records in
255+0 records out
127500 bytes transferred in 0.020355 secs (6263821 bytes/sec)
189216+0 records in
189216+0 records out
189216 bytes transferred in 1.200354 secs (157633 bytes/sec)
5. Restart Xcode.
6. With New Project opened, Open Project > Edit Project Settings,
Find “Code Signing Identity” and its child “Any iPhoneOS Device” in the list, and set both to the entry “don’t code sign”

7. mkdir /Developer/iphoneentitlements312
cd /Developer/iphoneentitlements312
curl -O
mv gen_entitlements.txt
chmod 777

8. 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
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
if [ "${PLATFORM_NAME}" == "iphoneos" ]; then
/Developer/iphoneentitlements312/ "${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}/"

Install on your device
1. Open XCode, add your device to XCode in Window>Organizer
2. Make sure you have ldid on Mac. Place it in /usr/local/bin.
3. Create the file /usr/local/bin/ldid2. Make it executable. Fill it with:

hasGTA=`expr "$*" : '.* -gta .*'`;
objpath=${!#}/`expr ${!#} : '.*/\([^/]\{1,\}\)\.app$'`;

if [[ $hasGTA == 0 ]]; then
/usr/local/bin/ldid -S $objpath;
TF=`mktemp -t x`;
echo "get-task-allow" > $TF;
/usr/local/bin/ldid -S$TF $objpath;
rm $TF;

4. Open /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Plug-ins/iPhoneOS Build System Support.xcplugin/Contents/Resources/iPhoneCodeSign.xcspec
5. Replace the line saying CommandLine = “/usr/bin/codesign” with CommandLine = “/usr/local/bin/ldid2”
6. Restart XCode

if you experience still can’t install & debug the code to the device, please visit those blog i refer above.
Enjoy ! 🙂

About Thomas G

Thomas G is a founder and editor of Evenbright. He is a tech entusiast. Currently he is working as a Senior Software Developer in a travel company.