среда, 30 декабря 2009 г.

Open iPhone Development on any platform

All further instructions assumes that you have already did your jailbroke(blackra1n,redsn0w - no matter)
  1. Run cydia
  2. Install openSSH to be able to connect to your phone
  3. Install apt 0.7 strict - you will need this package handling utility to install additional libraries without using cydia.
  4. Connect to your phone via ssh(default password will be "alpine" without quotes)

    Example:

    $ ssh root@192.168.1.104
  5. Install essentials

    # apt-get install wget
    # apt-get install vim
  6. You will need libgcc(Thank you Saurik!)
    # cd /tmp
    # wget -c "http://apt.saurik.com/debs/libgcc_4.2-20080410-1-6_iphoneos-arm.deb"
    # dpkg -i libgcc_4.2-20080410-1-6_iphoneos-arm.deb
  7. Now it is toolchain's turn
    apt-get install com.bigboss.20toolchain
Almost done, let's try to compile our first application.
# vim main.c
Example:
#include <stdio.h> int main() {
printf("Hello world!");
return 0;
}
Compile:
gcc main.c -o main
Output:
ld: library not found for -lSystem collect2: ld returned 1 exit status
To get this step done you should copy {libobjc.dylib,libSystem.dylib} files from official iPhone SDK. Put these files into /usr/lib and create links to them.
ln /usr/lib/libSystem.B.dylib /usr/lib/libSystem.dylib ln /usr/lib/libobjc.A.dylib /usr/lib/libobjc.dylib
Now compilation will be successful!
./main Killed!
Oops...No luck... That's because you have not signed your application. iPhone OS have very strict rules to run applications on it. To sign your application you will need a provision profile(remember the story about official development)... Or... Let's say "THANK YOU" to Saurik again:
apt-get install ldid ldid -S main ./main Hello World!
ldid - is a tool that can sign your applications and make them runnable on the iphone.
Let's try with full weight iPhone application!
  1. You will need additional header files which can be found in official SDK or you can download it from here(link from http://antirez.com).
    Copy this folder into your iPhone and then to the /var/inculde
    $ scp -r include-2.0-sdk-ready-for-iphone/ root@192.168.1.104:~/
    # cp -r include-2.0-sdk-ready-for-iphone/* /var/include

  2. To avoid "framework not found" messages:
    ld: framework not found CoreFoundation

    You should copy frameworks folders from the official SDK to your phone.
    # scp -r PrivateFrameworks root@192.168.1.104:~/
    # scp -r Frameworks root@192.168.1.104:~/
    And install them:
    cd Frameworks
    ls | awk -F . '{print "mkdir -p /var/include/"$1";cp -r " $0"/Headers/* /var/include/"$1 ";rm -rf "$0"/Headers" }' | sh
    ls | awk -F . '{print "mkdir -p /System/Library/Frameworks/"$1"."$2";cp -r "$0"/* /System/Library/Frameworks/"$1"."$2}' | sh
    cd ../PrivateFrameworks
    ls | awk -F . '{print "mkdir -p /var/include/"$1";cp -r " $0"/Headers/* /var/include/"$1 ";rm -rf "$0"/Headers" }' | sh
    ls | awk -F . '{print "mkdir -p /System/Library/PrivateFrameworks/"$1"."$2";cp -r "$0"/* /System/Library/PrivateFrameworks/"$1"."$2}' | sh
    cd ../
    rm -rf PrivateFrameworks Frameworks
  3. Now you can download on of the sample applications to start from. You can find one at http://antirez.com or http://blog.aaronash.com

суббота, 5 декабря 2009 г.

How to restore your iPhone

I have just corrupted some files from /usr/lib directory on my iPhone... I was trying to get libgcc working on the 3.1.2 jailbroken firmware, but now I have deadPhone.
The are two possibilities to restore iPhone.

1. iPhone Restore Mode

Follow the steps below to turn your iPhone in Restore Mode.

  1. Shutdown your iphone with the hard reset "home button and power for 10 second"
  2. Connect the usb cable to the pc but NOT to the iphone"
  3. Open itunes
  4. While the iphone is off, press the home button for 5-10 seconds then plus the other end of the white connection cable into the iphone
  5. Do not remove your finger from the home button
  6. iTunes will detect it and you can now restore it

In restore mode iPhone will load some additional software to verify that u will not downgrade your firmware(remember that u can press "shift" to manually choose firmware in iTunes).
In my case lib folder was corrupted and no additional software can be started in recovery mode. So...

2. iPhone DFU mode

Follow the steps below


  1. Connect your iPhone to your computer.
  2. Turn iPhone off.
  3. Hold power and home together for 10 seconds (exactly).
  4. Release power but keep holding home until the computers beeps (observed on a PC) as a USB device is recognized.
  5. A few seconds later iTunes should detect your iPhone.
  6. If the Restore Logo is present on the screen, you are in Recovery Mode, not DFU.


DFU is absolutely PC/Mac side controlled process, so that was the catch.