Showing posts with label iPhone GCC. Show all posts
Showing posts with label iPhone GCC. Show all posts

Thursday, January 9, 2014

How to install perl, theos and llvm-clang in iOS for iOS SDK6.1

(1) Install the following packages in Cydia
    APT 0.6 Transitional (and all its dependencies)

(2) If you have previous installation of odcctools, iPhone-gcc, theos and perl, you should first use SSH login shell and remove the packages by using commands
    apt-get remove iphone-gcc odcctools
    apt-get remove perl net.howett.theos

(3) Use SSH login shell commands to install perl & theos & llvm-clang
    apt-get install org.coolstar.cctools org.coolstar.ld64 org.coolstar.llvm-clang
    apt-get install coreutils wget make ldid zip unzip git subversion com.ericasadun.utilities
    cd /var
    git clone git://github.com/coolstar/theos
    wget --no-check-certificate -O org.coolstar.perl.deb 'http://d.pr/f/R0nx+'
    dpkg -i org.coolstar.perl.deb

(4) Download iPhoneOS6.1.sdk.tgz from here

(5) copy iPhoneOS6.1.sdk.tgz to iPhone

(6) Install SDK and additional libraries to sdks under theos

    tar xzvf iPhoneOS6.1.sdk.tgz
    mkdir -p /var/theos/sdks
    mv iPhoneOS6.1.sdk /var/theos/sdks/

# if your device is arm64 (that is iPad Mini 2, iPad Air or iPhone 5s)
    cd /var/theos/makefiles/targets
    ln -s Darwin-arm Darwin-arm64
    cd /var/theos/makefiles/platform
    ln -s Darwin-arm Darwin-arm64

# clone iphoneheaders.git
    cd /var/theos/
    mv include include.bak
    git clone git://github.com/rpetrich/iphoneheaders.git include
    for FILE in include.bak/*.h; do mv $FILE include/; done
    rmdir -fr include.bak/

(7) Create a command line tool project
    cd ~
    /var/theos/bin/nic.pl blocktest

(8) Choose [4.] iphone/tool

(9) Edit blocktest/main.mm like this to test block
main.mm Select all
#include <stdio.h> void EvalFuncOnGrid( double(^block)(float) ) { int i; for ( i = 0; i < 5 ; ++i ) { float x = i * 0.1; printf("%f %f\n", x, block(x)); } } void Caller(void) { float forceConst = 3.445; EvalFuncOnGrid(^(float x){ return 0.5 * forceConst * x * x; }); } int main(void) { Caller(); }


(10) Modify blocktest/Makefile like this
Makefile (Tool) Select all
TARGET := iphone:clang
TARGET_SDK_VERSION := 6.1 TARGET_IPHONEOS_DEPLOYMENT_VERSION := 6.1 ARCHS := armv7 include theos/makefiles/common.mk TOOL_NAME = blocktest blocktest_FILES = main.mm include $(THEOS_MAKE_PATH)/tool.mk

(11) Make and test run

    cd ~/blocktest
    make clean
    make
    ./obj/blocktest

(12) get ilogit for test build package
    cd ~
    wget --no-check-certificate https://dl.dropboxusercontent.com/u/15373/Other/iPhone/ilogit-tweak-ios7-example.tar
    tar -xf ilogit-tweak-ios7-example.tar

    #make symlink
    cd ~/ilogit
    ln -s /var/theos theos


(13) Modify Makefile, like this

Makefile    Select all
TARGET := iphone:clang TARGET_SDK_VERSION := 6.1 TARGET_IPHONEOS_DEPLOYMENT_VERSION = 6.1 ARCHS = armv6 armv7 # test build multiple archs include theos/makefiles/common.mk TWEAK_NAME = iLogIt iLogIt_FILES = Tweak.xm iLogIt_LIBRARIES = substrate
include $(THEOS_MAKE_PATH)/tweak.mk


(14) Test make package

    make clean
    make package


If you need gdb and debugserver for iOS see here



Sunday, February 24, 2013

Illegal instruction: 4

Some old arm v6 binaries that compiled using iPhone-gcc and old sdk have "Illegal instruction: 4" when using devices with A6/A6X CPU such as iPhone 5 / iPad 4 as discussed in http://code.google.com/p/iphone-gcc-full/issues/detail?id=6
The is how to patch these binaries without recompiling or when source code is not available

perl -pe 's/\x{00}\x{30}\x{93}\x{e4}/\x{00}\x{30}\x{93}\x{e5}/g;s/\x{00}\x{30}\x{d3}\x{e4}/\x{00}\x{30}\x{d3}\x{e5}/g;' < old_ios_binary > old_ios_binary_patched
chmod +x old_ios_binary_patched
ldid -s old_ios_binary_patched
mv old_ios_binary old_ios_binary_original
mv old_ios_binary_patched old_ios_binary


If you have gnu sed in iOS or OS X, you can patch directly without the temp file in one step
sed -i'' 's/\x00\x30\x93\xe4/\x00\x30\x93\xe5/g;s/\x00\x30\xd3\xe4/\x00\x30\xd3\xe5/g;' old_ios_binary
ldid -s old_ios_binary


iphone-gcc patched package for iPhone 5 / iPad 4 is here
http://code.google.com/p/apiexplorer/downloads/list

Sunday, October 30, 2011

How to install perl, theos and iphone-gcc in iPhone

(1) Install the following packages in Cydia
APT 0.6 Transitional (and all its dependencies)
wget

(2) Use SSH login shell commands to install perl & theos (or install them in Cydia by adding Sources)

echo "deb http://coredev.nl/cydia iphone main" > /etc/apt/sources.list.d/coredev.nl.list
wget http://coredev.nl/cydia/coredev.pub
apt-key add coredev.pub
apt-get update
apt-get install perl
echo "deb http://nix.howett.net/theos ./" > /etc/apt/sources.list.d/howett.net.list
apt-get update
apt-get install net.howett.theos rsync


If you have No space left on device error when installing perl , relocate /usr/local to /var/stash/local

(3) Use SSH login shell commands to install iphone-gcc and ldid (or install them in Cydia)

wget 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
apt-get update
apt-get install iphone-gcc
apt-get install make ldid zip unzip com.ericasadun.utilities


(4) Download SDK3.2 Headers and Libs from here
Please take note that the current iPhone-gcc does not support iOS SDK 4.0 or above

(5) copy iPhoneSDKHeadersAndLibs_32.pkg to iPhone

(6) Install SDK and additional libraries to sdk

apt-get update
apt-get install xar cpio
xar -xf iPhoneSDKHeadersAndLibs_32.pkg Payload
cat Payload | zcat | cpio -id
mv Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk /var/sdk
cd /var/sdk/usr/lib/
ln -s libstdc++.6.dylib libstdc++.dylib
ln -s crt1.o crt1.10.5.o
ln -s dylib1.o dylib1.10.5.o
cp -p /usr/lib/libgcc_s.10.5.dylib .



(7) Create a command line tool project

/var/theos/bin/nic.pl helloworld


(8) Choose [4.] iphone/tool

(9) Edit main.mm and add printf and cout like this
main.mm Select all

#include <iostream>
using namespace std;
int main(int argc, char **argv, char **envp) {
    printf("Hello World\n");
    cout << "Hello CPP" << endl;
    return 0;
}


(10) Add the ADDITIONAL_CFLAGS and ADDITIONAL_CCFLAGS in Makefile like this
Makefile (Tool) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

TOOL_NAME = helloworld
helloworld_FILES = main.mm

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tool.mk



(11) Make and test run

cd helloworld
make clean
make
./obj/helloworld


(12) For app, the sample Makefile is
Makefile (Application) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

APPLICATION_NAME = myapp
myapp_FILES = main.m
myapp_FILES += $(wildcard Classes/*.m)

myapp_FRAMEWORKS = UIKit

PCH:=$(wildcard *.pch)

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"
ifneq ($(PCH),)
ADDITIONAL_CFLAGS += -include $(PCH)
ADDITIONAL_CCFLAGS += -include $(PCH)
endif

include $(THEOS_MAKE_PATH)/application.mk

RESOURCESFOLDER=./Resources
PAYLOADFOLDER=$(THEOS_STAGING_DIR)
OBJFOLDER=./obj
INFOPLIST:=$(wildcard *Info.plist)
INFOPLIST+=$(wildcard Resources/*Info.plist)
PNGFILES:=$(wildcard Resources/*.png)
LPROJFILES:=$(wildcard Resources/*.lproj)
APPVERSION=$(shell plutil -key CFBundleVersion $(INFOPLIST) 2>&1)

# make ipa
# replace 4 spaces with TAB for below
ipa:    stage
    rm -fr $(PAYLOADFOLDER)/* $(APPLICATION_NAME)_$(APPVERSION).ipa
    rm -f Payload
    mkdir -p $(PAYLOADFOLDER)/$(APPLICATION_NAME).app
    cp $(OBJFOLDER)/$(APPLICATION_NAME) $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
ifneq ($(PNGFILES),)
    cp -rp $(RESOURCESFOLDER)/*.png $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
endif
ifneq ($(LPROJFILES),)
    cp -rp $(RESOURCESFOLDER)/*.lproj $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
endif
    @echo "APPL????" > $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/PkgInfo
    cp -p $(INFOPLIST) $(PAYLOADFOLDER)/$(APPLICATION_NAME).app/.
    ln -sf $(PAYLOADFOLDER) Payload
    zip -r $(APPLICATION_NAME)_$(APPVERSION).ipa Payload > /dev/null


(13) For mobilesubstrate extension, the sample Makefile is
Makefile (Tweak) Select all

export THEOS=/var/theos
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = mytweak
APP_ID = com.mycompany.mytweak
mytweak_FILES = Tweak.xm
mytweak_FRAMEWORKS = UIKit

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tweak.mk

# make package
# replace 4 spaces with TAB for below
after-stage::
    find $(THEOS_STAGING_DIR) -iname '*.plist' -exec plutil -convert binary1 {} \;
    $(FAKEROOT) chown -R 0:80 $(THEOS_STAGING_DIR)

PACKAGEFOLDER=./layout
CONTROLFILE=control
PACKAGENAME=$(shell grep ^Package: $(CONTROLFILE) | cut -d ' ' -f 2)
PACKAGEVERSION=$(shell grep ^Version: $(CONTROLFILE) | cut -d ' ' -f 2)
ARCH=$(shell grep ^Architecture: $(CONTROLFILE) | cut -d ' ' -f 2)
OBJFOLDER=./obj
_EXCLUDES ?= tmp _MTN .git .svn .DS_Store ._*
_EXCLUDE_COMMANDLINE := $(foreach exclude,$(_EXCLUDES),--exclude "$(exclude)")


# with dpkg-deb
# replace 4 spaces with TAB for below
deb: stage
    rm -fr $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb $(PACKAGEFOLDER)/control.tar.gz $(PACKAGEFOLDER)/data.tar.gz $(PACKAGEFOLDER)/tmp
    mkdir -p $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/
    mkdir -p $(PACKAGEFOLDER)/DEBIAN
    cp $(OBJFOLDER)/$(TWEAK_NAME).dylib $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/.
    cp $(CONTROLFILE) $(PACKAGEFOLDER)/DEBIAN/
    dpkg-deb -b $(PACKAGEFOLDER) $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb

# without dpkg-deb
# replace 4 spaces with TAB for below
deb2: stage
    mkdir -p $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/
    mkdir -p $(PACKAGEFOLDER)/DEBIAN
    cp $(CONTROLFILE) $(PACKAGEFOLDER)/DEBIAN/
    rm -f $(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb $(PACKAGEFOLDER)/control.tar.gz $(PACKAGEFOLDER)/data.tar.gz
    rm -f $(PACKAGEFOLDER)/tmp/*.gz
    mkdir -p $(PACKAGEFOLDER)/tmp
    echo "2.0" > $(PACKAGEFOLDER)/tmp/debian-binary
    cp $(OBJFOLDER)/$(TWEAK_NAME).dylib $(PACKAGEFOLDER)/Library/MobileSubstrate/DynamicLibraries/.
    cd $(PACKAGEFOLDER)/DEBIAN; tar -czf ../tmp/control.tar.gz ./
    cd $(PACKAGEFOLDER); tar -czf ./tmp/data.tar.gz $(_EXCLUDE_COMMANDLINE) ./
    cd $(PACKAGEFOLDER)/tmp; ar -rv ../../$(PACKAGENAME)_$(PACKAGEVERSION)_$(ARCH).deb ./debian-binary ./control.tar.gz ./data.tar.gz
    rm -fr $(PACKAGEFOLDER)/tmp/*.gz


For mobilesubstrate extension, download the iPhone headers from http://github.com/rpetrich/iphoneheaders/archives/master

and place the frameworks at top level (i.e. SpringBoard folder copy to /var/theos/include/SpringBoard).
libsubstrate.dylib is also needed in /var/theos/lib folder

Note: perl is needed for creating project folder and compiling mobilesubstrate extension, if you only develop app and command line tool, you could remove perl by using

apt-get remove perl


(14) This is how to combine Tweak and Settings Bundle in a project
/var/theos/bin/nic.pl MyTweak
and choose [5.] iphone/tweak
/var/theos/bin/nic.pl MyTweakSettings
and choose [3.] iphone/preference_bundle
mv mytweaksettings/*.mm mytweaksettings/Resources mytweaksettings/entry.plist mytweak/

Makefile (Tweak + Bundle) Select all

export THEOS=/var/theos
export GO_EASY_ON_ME=1
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = MyTweak
#MyTweak_FILES = MyTweak.xm
MyTweak_FRAMEWORKS = UIKit

BUNDLE_NAME = MyTweakSettings
MyTweakSettings_FILES = MyTweakSettings.mm
MyTweakSettings_INSTALL_PATH = /System/Library/PreferenceBundles
MyTweakSettings_FRAMEWORKS = UIKit
MyTweakSettings_PRIVATE_FRAMEWORKS = Preferences

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/tweak.mk
include $(THEOS_MAKE_PATH)/bundle.mk
include $(THEOS_MAKE_PATH)/aggregate.mk

# replace 4 spaces with TAB for below
internal-stage::
    $(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences$(ECHO_END)
    $(ECHO_NOTHING)cp entry.plist $(THEOS_STAGING_DIR)/Library/PreferenceLoader/Preferences/$(BUNDLE_NAME).plist$(ECHO_END)

# replace 4 spaces with TAB for below
after-stage::
    find $(THEOS_STAGING_DIR) -iname '*.plist' -exec plutil -convert binary1 {} \;
    $(FAKEROOT) chown -R 0:80 $(THEOS_STAGING_DIR)


(15) If you want to test the iOS5 Notification Center Widget
get it from http://github.com/WillFour20/WeeAppTest

git clone git://github.com/WillFour20/WeeAppTest.git

and modified with the following Makefile

Makefile (nc Tweak) Select all

export THEOS=/var/theos
SDKVERSION = 5.0
include $(THEOS)/makefiles/common.mk

BUNDLE_NAME = WeeAppTest
WeeAppTest_FILES = WeeAppTest.mm
WeeAppTest_INSTALL_PATH = /System/Library/WeeAppPlugins/
WeeAppTest_FRAMEWORKS = UIKit CoreGraphics
#WeeAppTest_PRIVATE_FRAMEWORKS = BulletinBoard

ADDITIONAL_CFLAGS = -I"$(SYSROOT)/usr/lib/gcc/arm-apple-darwin10/4.2.1/include"
ADDITIONAL_CCFLAGS = -I"$(SYSROOT)/usr/include/c++/4.2.1"
ADDITIONAL_CCFLAGS += -I"$(SYSROOT)/usr/include/c++/4.2.1/armv6-apple-darwin10"

include $(THEOS_MAKE_PATH)/bundle.mk

# replace 4 spaces with TAB for below
after-install::
    install.exec "killall -9 SpringBoard"


and make clean package install

(15) where is IOSurfaceAPI.h in Lion ?

Here
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceAPI.h





iphone-gcc patched package for iPhone 5 / iPad 4 is here below
http://code.google.com/p/apiexplorer/downloads/list

Monday, June 7, 2010

iPhone gcc for SDK 3.2 & iPad

iPhone gcc for SDK 3.2
(1) Install iphone gcc installed in your jailbroken iPad with firmware 3.2

iPhone gcc is available in Cydia. To install it in you need to do these


# assume you have installed APT 0.6 Transitional and Aptitude and wget in Cydia, so that you can use the command apt-get
# if libgcc is broken in Cydia, you have to install it manually before iphone-gcc
wget 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
# install iphone-gcc
apt-get install iphone-gcc


Moreover, install these utilities via apt-get as well


apt-get install make ldid zip unzip wget


for editor in iPad you could use vim or nano

(2) Header files for toolchain and SDK 3.2

the header files for SDK 3.2 is available in one zipped tar file (sys32.tgz). You can download it (about 147M) here

(3) copy and untar the required headers and libraries (first copy to /var/mobile/sys32.tgz) and install it in iPad say

mkdir -p /var/toolchain/
cd /var/toolchain/
tar -xzvf /var/mobile/sys32.tgz


(4) Use this sample TabBarSample.zip and unzip it to test.

This TabBar sample source code is compatible with iPad and iPhone gcc, with auto-rotation and auto-resizing support.

http://apiexplorer.googlecode.com/files/TabBarSample.zip

wget http://apiexplorer.googlecode.com/files/TabBarSample.zip
unzip TabBarSample.zip
cd TabBarSample
make install





The package includes a new command line utility called appinstall, it is used to install compiled app to /var/mobile/Applications/* directory for iPad, it simulates the app install process via XCode.
.
.
.

Wednesday, December 9, 2009

[How-to] compile SmartScreen widget in iphone gcc

Here is a sample clock widget source from SmartScreen sdk http://media-phone.ch/en/software/smartscreen/sdk/ , I added a Makefile so that it can be compiled under iphone gcc

http://apiexplorer.googlecode.com/files/ClockWidget.zip

Make sure you have installed iphone gcc and 3.0 headers (refer here for the 3.0 headers) and also SmartScreen (Lite or full version) before your testing.

If you have installed toolchain and 3.0 headers under cygwin or linux, just modify the sdk location in the Makefile and it should compile as well.

SmartScreen widget will be installed under the folder /var/mobile/Library/SmartScreen

To compile and install this sample clock widget under iphone gcc

make
make install


To uninstall the clock widget

make uninstall


This is the updated Makefile for SmartScreen ClockWidget
Makefile Select all

# Makefile for gcc compiler for iPhone (SmartScreen Widget)

PROJECTNAME:=Clock
PRINCIPALCLASS:=$(PROJECTNAME)Widget
WIDGETFOLDER:=$(PROJECTNAME).wdgt
INSTALLFOLDER:=/var/mobile/Library/SmartScreen
MINIMUMVERSION:=3.0

CC:=arm-apple-darwin9-gcc
CPP:=arm-apple-darwin9-g++
LD:=$(CC)
SDK:=/var/toolchain/sys30

LDFLAGS = -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
//LDFLAGS += -framework AddressBook
//LDFLAGS += -framework AddressBookUI
//LDFLAGS += -framework AudioToolbox
//LDFLAGS += -framework AudioUnit
//LDFLAGS += -framework AVFoundation
//LDFLAGS += -framework CoreSurface
//LDFLAGS += -framework CoreAudio
//LDFLAGS += -framework CoreData
//LDFLAGS += -framework CFNetwork
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework OpenAL
//LDFLAGS += -framework OpenGLES
//LDFLAGS += -framework MediaPlayer
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework Security
//LDFLAGS += -framework SystemConfiguration
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
//LDFLAGS += -framework SpringBoardUI
//LDFLAGS += -framework TelephonyUI
//LDFLAGS += -framework JavaScriptCore
//LDFLAGS += -framework PhotoLibrary
LDFLAGS += -L"$(SDK)/usr/lib"
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress
LDFLAGS += -march=armv6
LDFLAGS += -mcpu=arm1176jzf-s
LDFLAGS += -mmacosx-version-min=10.5
LDFLAGS += -dynamiclib

CFLAGS += -I"$(SDK)/usr/include"
CFLAGS += -DDEBUG -std=gnu99 -O0
CFLAGS += -Diphoneos_version_min=$(MINIMUMVERSION)
CFLAGS += -Wno-attributes -Wno-trigraphs -Wreturn-type -Wunused-variable

BUILDDIR=./build/$(MINIMUMVERSION)
SRCDIR=./
RESDIR=./Resources
OBJS+=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.mm,%.o,$(wildcard $(SRCDIR)/*.mm))
OBJS+=$(patsubst %.cpp,%.o,$(wildcard $(SRCDIR)/*.cpp))
OBJS+=$(patsubst %.m,%.o,$(wildcard ./*.m))
PCH=$(wildcard *.pch)
RESOURCES=$(wildcard $(RESDIR)/*)

CFLAGS += $(addprefix -I,$(SRCDIR))

CPPFLAGS=$CFLAGS

all: $(PROJECTNAME)

$(PROJECTNAME): $(OBJS) Makefile
    $(LD) $(LDFLAGS) $(filter %.o,$^) -o $@

%.o: %.m %.h $(PCH) $(filter-out $(patsubst %.o,%.h,$(OBJS)), $(wildcard $(SRCDIR)/*.h))
    $(CC) --include $(PCH) -c $(CFLAGS) $< -o $@

%.o: %.c %.h $(PCH)
    $(CC) --include $(PCH) -c $(CFLAGS) $< -o $@

%.o: %.mm %.h $(PCH) $(filter-out $(patsubst %.o,%.h,$(OBJS)), $(wildcard $(SRCDIR)/*.h))
    $(CPP) --include $(PCH) -c $(CPPFLAGS) $< -o $@

%.o: %.cpp %.h $(PCH)
    $(CPP) --include $(PCH) -c $(CPPFLAGS) $< -o $@

dist: $(PROJECTNAME) Info.plist Makefile $(RESOURCES)
    @rm -rf $(BUILDDIR)
    @mkdir -p $(BUILDDIR)/$(WIDGETFOLDER)
ifneq ($(RESOURCES),)
    @-cp -r $(RESOURCES) $(BUILDDIR)/$(WIDGETFOLDER)
    @-$(foreach DIR, .svn .DS_Store .git* , find $(BUILDDIR)/$(APPFOLDER) -name '$(DIR)' -prune -exec rm -rfv {} \;;)
endif
    @cp Info.plist $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key CFBundleExecutable -value $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key CFBundleName -value $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    @./plutil -key NSPrincipalClass -value $(PRINCIPALCLASS) $(BUILDDIR)/$(WIDGETFOLDER)/Info.plist
    ldid -S $(PROJECTNAME)
    @mv $(PROJECTNAME) $(BUILDDIR)/$(WIDGETFOLDER)

install: dist
    @rm -fr $(INSTALLFOLDER)/$(WIDGETFOLDER)
    cp -r $(BUILDDIR)/$(WIDGETFOLDER) $(INSTALLFOLDER)/
    @chown -R mobile:mobile $(INSTALLFOLDER)/$(WIDGETFOLDER)
    @echo "Widget $(WIDGETFOLDER) installed, please respring device"
    @./respring

uninstall:
    @rm -fr $(INSTALLFOLDER)/$(WIDGETFOLDER)
    @./respring
    @echo "Widget $(WIDGETFOLDER) uninstalled, please respring device"

install_respring:
    cp ./respring /usr/bin/respring

distclean:
    @rm -rf $(BUILDDIR)

clean:
    @rm -f $(OBJS)
    @rm -rf $(BUILDDIR)
    @rm -f $(PROJECTNAME)

.PHONY: all dist install uninstall install_respring distclean clean





Sunday, October 4, 2009

How to compile mobilesubstrate extension in iPhone gcc for OS 3.0

(1) You need iphone gcc installed in your jailbroken iPhone / iPod Touch with firmware 3.0 or above

iPhone gcc is available in Cydia. To install it in you need to do these


# assume you have installed APT 0.6 Transitional and Aptitude and wget in Cydia, so that you can use the command apt-get
# if libgcc is broken in Cydia, you have to install it manually before iphone-gcc
wget 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
# install iphone-gcc
apt-get install iphone-gcc


Moreover, you need these utilities as well


apt-get install make ldid zip unzip wget


for editor in iPhone you can use vim or nano

(2) You need the header files of toolchain and SDK 3.0, libsubstrate and classdump the SpringBoard and UIKit headers

The building of iPhone gcc in Linux and header files (updated for OS 3.0) is here in
http://www.saurik.com/id/4

The updated mobilesubtrate header files are here

The classdump procedure is here

But all these involved a lot of downloading and patching, so I put all the downloading/classdump/patching in one zipped tar file (sys30.tgz). You can download it (about 96M) here

(3) copy and untar the required headers and libraries (say copy to /var/mobile/sys30.tgz) and install it in iPhone / iPod Touch say

mkdir /var/toolchain/
cd /var/toolchain/
tar -xzvf /var/mobile/sys30.tgz


(4) Use this sample mobilesubstrate extension (ExampleHook.zip) and unzip it to test. You need to apt-get install mobilesubstrate in iPhone / iPod Touch first

http://apiexplorer.googlecode.com/files/ExampleHook.zip

apt-get install mobilesubstrate
wget http://apiexplorer.googlecode.com/files/ExampleHook.zip
unzip ExampleHook.zip
cd ExampleHook

make (to compile and codesign)
make install (to install), after install you need respring the device to test
make uninstall (to uninstall), after uninstall you need respring as well

respring utility is available from my cydia source http://cydia.iphone.org.hk/apt/

(5) You can also checkout a copy of the iphone backgrounder to test your iphone gcc and mobilesubstrate development environment
http://code.google.com/p/iphone-backgrounder/source/checkout

Install subversion before using svn in iPhone / iPod Touch

apt-get install subversion
svn checkout http://iphone-backgrounder.googlecode.com/svn/trunk/ iphone-backgrounder
cd iphone-backgrounder



I use this modified Makefile to compile iphone-backgrounder
MakefileSelect all

NAME = Backgrounder
APP_ID = jp.ashikase.backgrounder

# These paths must be changed to match the compilation environment
TOOLCHAIN = /var/toolchain/sys30/dump
SYS_PATH = /var/toolchain/sys30
MS_PATH = /var/toolchain/sys30/mobilesubstrate
INC_PATH = /var/toolchain/sys30/usr/include
LDID = /usr/bin/ldid

CXX = arm-apple-darwin9-g++
CXXFLAGS = -g0 -O2 -Wall -Werror -Wno-write-strings -include common.h -DAPP_ID=\"$(APP_ID)\"
LD = $(CXX)
LDFLAGS = -march=armv6 \
-mcpu=arm1176jzf-s \
-bind_at_load \
-multiply_defined suppress \
-framework CoreFoundation \
-framework Foundation \
-framework UIKit \
-framework GraphicsServices \
-framework CoreGraphics \
-F$(SYS_PATH)/System/Library/Frameworks \
-F$(SYS_PATH)/System/Library/PrivateFrameworks \
-L$(SYS_PATH)/usr/lib -lsubstrate \
-lobjc

INCLUDES = -I$(INC_PATH) -I$(MS_PATH) -I$(TOOLCHAIN) \
-I./Classes

SUBDIRS = . Classes

DIRLIST := $(SUBDIRS:%=%)
SRCS := $(foreach dir,$(DIRLIST), $(wildcard $(dir)/*.mm))
HDRS := $(foreach dir,$(DIRLIST), $(wildcard $(dir)/*.h))
OBJS := $(SRCS:.mm=.o)

all: $(NAME).dylib

config:
ln -snf $(TOOLCHAIN) $(SYS_PATH)

# Replace 'iphone' with the IP or hostname of your device
install: config $(NAME).dylib
ssh root@iphone rm -f /Library/MobileSubstrate/DynamicLibraries/$(NAME).dylib
scp $(NAME).dylib root@iphone:/Library/MobileSubstrate/DynamicLibraries/
ssh root@iphone restart

$(NAME).dylib: $(OBJS) $(HDRS)
$(LD) -dynamiclib $(LDFLAGS) $(OBJS) -init _$(NAME)Initialize -o $@
$(LDID) -S $@

%.o: %.mm
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

clean:
rm -f $(OBJS) $(NAME).dylib


P.S. This is how to compile a standard c++ program in iPhone gcc
test.cppSelect all

arm-apple-darwin9-g++ -I"/var/toolchain/sys30/usr/include" -I"/var/toolchain/sys30/usr/include/c++/4.2.1" -I"/var/toolchain/sys30/usr/include/c++/4.2.1/armv6-apple-darwin9" -g0 -O2 -Wall -L"/var/toolchain/sys30/usr/lib" -march=armv6 -mcpu=arm1176jzf-s test.cpp -o test






Sunday, July 5, 2009

How to compile command line utility for iPhone using XCode gcc

hello.c

echo 'main() { printf("Hello, world!\n"); }' > hello.c


compile hello.c

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.0 -arch armv6 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk -o hello hello.c


compile with framework

/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.0 -arch armv6 -mthumb -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.sdk -framework Foundation -framework CoreFoundation -lobjc -std=c99 main.m -o main


codesign in Mac, if you have developer or self-signed certificate (can't codesign it when in ssh session)

export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate; codesign -f -s "iPhone Developer" hello


or you can codesign in iPhone, that is, send the binary to iPhone and then fake codesign it

ldid -S hello



This is how to use as (assembler) to compile hello.s to ARM thumb binary
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as -arch armv6 hello.s -o hello


# GAS filename : hello.s
# use as to compile
# /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as -arch armv6 hello.s -o hello
# use otool to disassemble
# otool -tv hello

  .globl _main
  .code 16
  .thumb_func _main
_main:
  push {r7, lr}
  add r7, sp, #0
  add r3, pc
  mov ip, r3
  mov r3, ip
  mov r0, r3
  pop {r7, pc}


.
.
.

Monday, January 12, 2009

How-to do ARM GCC Inline Assembler for iPhone

The following code demonstrates an example to write Inline Assembler in llvm-gcc for iPhone ARM

arithmetic_shift_right.c Select all

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
int i = atoi(argv[1]);
asm volatile ("mov %0, %1, ASR #1" : "=r"(i) : "r"(i));
printf("arithmetic_shift_right is %d\n", i);
exit(0);
}


The general format (ref) is
asm volatile (assembler instructions : output operands (optional) : input operands (optional) : clobbered registers (optional) );

e.g.
asm volatile ("mul %0, %1, %2" : "=r" (result) : "r" (number1) , "r" (number2));


This version is for Assembler Macro

arithmetic_shift_right.c Select all

#include <stdio.h>
#include <stdlib.h>

inline int arithmetic_shift_right(int a) {
int y;
__asm__("mov %0, %1, ASR #1" : "=r" (y) : "r" (a));
// Register R0 will become the value of register R1 shifted to the right by 1 bit, with the sign maintained.
return y;
}

int main(int argc, char *argv[]) {
int i = atoi(argv[1]);
printf("arithmetic_shift_right %d is %d\n", i, arithmetic_shift_right(i));
exit(0);
}



Below is the otool output for Assembler Macro
otool -tV Select all

_arithmetic_shift_right:
00001eb4 e92d4080 stmdb sp!, {r7, lr}
00001eb8 e28d7000 add r7, sp, #0 ; 0x0
00001ebc e24dd008 sub sp, sp, #8 ; 0x8
00001ec0 e58d0000 str r0, [sp]
00001ec4 e59d3000 ldr r3, [sp]
00001ec8 e1a030c3 mov r3, r3, asr #1       @@ arithmetic shift right
00001ecc e58d3004 str r3, [sp, #4]
00001ed0 e59d3004 ldr r3, [sp, #4]
00001ed4 e1a00003 mov r0, r3
00001ed8 e247d000 sub sp, r7, #0 ; 0x0
00001edc e8bd8080 ldmia sp!, {r7, pc}


Below is the otool output for Assembler Macro (after full optimzation -O2)
otool -tV Select all

_arithmetic_shift_right:
00001f04 e1a000c0 mov r0, r0, asr #1
00001f08 e12fff1e bx lr




Assembler Macro for more than one assembler instruction
arithmetic shift right then perform 16 bit binary multiplication

Assembler Macros Select all

__asm__("mov %0, %1, ASR #1\n\t"
"mul %0, %0, %1"
: "=r" (y) : "r" (a));





Saturday, October 18, 2008

[How-To] Install llvm-gcc for iPhone SDK 2.0 in Linux

The building of iPhone gcc in Linux is described in
http://www.saurik.com/id/4

But this guide involved a lot of downloading and patching, so I put all the downloading in one zipped tar file. All you have to do is download it and run the build script in your Linux

I used the Asus eeepc Linux as an example, but others Linux variant / cygwin should be very similar.

Asus eeepc comes with xandros Debian Linux but does not have development tools. This part(A) shows you how to setup the development tools first. Other Linux variant does have development tools and you might want to skip this part and continue on Part B

(A) Install the development tools in eeepc

(1) Launch Terminal (Ctrl-Alt-T) in eeepc

(2) edit the file/etc/apt/sources.list
sudo vi /etc/apt/sources.list

and add this line to the end of the file "sources.list"
deb http://http.us.debian.org/debian/ stable main

(3) Run these commands in Terminal to install building tools

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential bison flex


(B) Download the file to your Linux
UpgradeToolChain2.tgz

The package is very large (about 200M)
You should first goto this websever
http://www.iphonefix.de/

and click the DOWNLOADS menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3
and download the file UpgradeToolChain2.tgz

MD5 (UpgradeToolChain2.tgz) = b373c0e600d45b1019e2894614b5979b
Size (UpgradeToolChain2.tgz) = 202278454




and extract to /usr

cd /usr
sudo tar -xzvf ~/UpgradeToolChain2.tgz


(C) login in as superuser and build the Darwin CC tools and llvm-gcc in Linux

su
cd /usr/toolchain2
./build_20.sh

wait for 10+ minutes to complete the building of tools and gcc

If you extract the tgz to different folder and want to build it in some other folder, please modify the environment variable toolchain in build_20.sh

(D) Test build your project in Linux
The include files have the iPhone SDK headers so you can test it using some available open source project (without Interface Builder) that using SDK 2.0 headers

If you want ti upgrade to SDK 2.1/2.2 headers just copy and replace the 2.0 headers.

For example, download this WinterBoard App Source code from the developer and compile it in Linux

wget http://svn.saurik.com/repos/menes/trunk/winterboard/Application.mm

/usr/toolchain2/pre/bin/arm-apple-darwin9-g++ -g0 -O2 -Wall -Werror -o WinterBoard Application.mm \
-framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics


If you want to deploy the app to iPhone, you have to codesign it (using ldid in iPhone) and provide the additional required project file in the .app folder e.g. (Info.plist, Icon.png etc)

Enjoy compiling and building iPhone App

Moreover, I have modified a previous VMWare image based on Debian Linux and build the llvm-gcc for iPhone and the toolchain and SDK20 headers there. If you have VMWare workstation or player / VMWare Fusion (Mac OS X), you can use it to build 2.0 iPhone app using ssh or samba mount access. The VMWare image is very large (about 1.2G compressed).

You should first goto this websever
http://www.iphonefix.de/

and click the download menu
and username password is generated for every visitor on the fly when you click on the ftp sever link

Inside the ftp server goto the folder
iPhoneToolchain VMWare Image / V3



and download the file
iPhoneToolchian_SDK20.rar

MD5 (iPhoneToolchain_SDK20.rar) = 29888ad8a73cf0a9674152c64961c02a
Size (iPhoneToolchain_SDK20.rar) = 1304054096

unrar the file and then use VMWare workstation or VMWare Fusion to open it

login: root
password: toolchain

The instructions are in the README.txt There are 3 sample projects inside the VMWare image

new!!
Install ldid in Linux, so that you can fake codesign it

cd ~/Projects
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.476.tgz
tar -zxf ldid-1.0.476.tgz
cd ldid-1.0.476
g++ -I . -o util/ldid{,.cpp} -x c util/{lookup2,sha1}.c
sudo cp -a util/ldid /usr/bin


Updates : The source of of ldid is moved to here
wget http://www.telesphoreo.org/export/477/trunk/data/ldid/ldid-1.0.476.tgz
or updated one here
wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.610.tgz

Updates : If you compiled it in cgywin, you need to add (uint32_t) in the source code ldid.cpp that has ambiguous overload call error message like this

error: call of overloaded 'Swap(int)' is ambiguous



If you need to codesign the iPhone binary in Linux add this (as one line) to your build script

export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)

A sample Makefile for Linux toolchain

Makefile: Select all

# Makefile for gcc compiler for Linux iPhone toolchain (SDK Headers)

PROJECTNAME=HelloWorld
APPFOLDER=$(PROJECTNAME).app
INSTALLFOLDER=$(PROJECTNAME).app

IPHONE_IP=10.0.2.2

SDK=/usr/toolchain2/sys
CC=/usr/toolchain2/pre/bin/arm-apple-darwin9-gcc
LD=$(CC)
LDFLAGS += -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework CoreGraphics
//LDFLAGS += -framework QuartzCore
//LDFLAGS += -framework GraphicsServices
//LDFLAGS += -framework CoreSurface
//LDFLAGS += -framework CoreAudio
//LDFLAGS += -framework Celestial
//LDFLAGS += -framework AudioToolbox
//LDFLAGS += -framework WebCore
//LDFLAGS += -framework WebKit
//LDFLAGS += -framework SystemConfiguration
LDFLAGS += -isysroot $(SDK)
LDFLAGS += -F"$(SDK)/System/Library/Frameworks"
LDFLAGS += -F"$(SDK)/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress
LDFLAGS += -march=armv6
LDFLAGS += -mcpu=arm1176jzf-s

CFLAGS += -isysroot $(SDK)
CFLAGS += -DDEBUG -Wall -std=c99
CFLAGS += -Diphoneos_version_min=2.0

BUILDDIR=./build/2.0
SRCDIR=./Classes
RESDIR=./Resources
OBJS+=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.m,%.o,$(wildcard ./*.m))
RESOURCES=$(wildcard $(RESDIR)/*)
RESOURCES+=$(wildcard ./*.png)

all: $(PROJECTNAME)

$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^

%.o: %.m
$(CC) -c $(CFLAGS) $< -o $@

%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@

dist: $(PROJECTNAME)
rm -rf $(BUILDDIR)
mkdir -p $(BUILDDIR)/$(APPFOLDER)
cp -r $(RESOURCES) $(BUILDDIR)/$(APPFOLDER)
cp Info.plist $(BUILDDIR)/$(APPFOLDER)/Info.plist
@echo "APPL????" > $(BUILDDIR)/$(APPFOLDER)/PkgInfo
export CODESIGN_ALLOCATE=/usr/toolchain2/pre/bin/arm-apple-darwin9-codesign_allocate; ldid -S $(PROJECTNAME)
cp $(PROJECTNAME) $(BUILDDIR)/$(APPFOLDER)

install: dist
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER)'
scp -r $(BUILDDIR)/$(APPFOLDER) root@$(IPHONE_IP):/Applications/$(INSTALLFOLDER)
ssh root@$(IPHONE_IP) 'respring'
@echo "Application $(INSTALLFOLDER) installed"

uninstall:
ping -t 3 -c 1 $(IPHONE_IP)
ssh root@$(IPHONE_IP) 'rm -fr /Applications/$(INSTALLFOLDER); respring'
@echo "Application $(INSTALLFOLDER) uninstalled"

clean:
@rm -f $(SRCDIR)/*.o
@rm -rf $(BUILDDIR)
@rm -f $(PROJECTNAME)






Sunday, September 14, 2008

Copy iPhone SDK headers from Mac to iPhone

Use this shell script in Mac Terminal to copy the installed SDK header files (firmware 2.1) to iPhone , if you have installed the iPhone SDK (build 9M2517) for (2.0 & 2.1 development)
directly and you have to change IPHONEIP for your actual iPhone IP address

copySDKHeaders2.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
#SDKVER=2.0
#SDKVER=2.1
SDKVER=2.2
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[3]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[5]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[6]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[10]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[11]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[12]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[13]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[14]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[15]=$sdkroot/Security.framework/Headers/*
sdkframeworks[16]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[17]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[18]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[3]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[4]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[5]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[6]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[7]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[8]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[9]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[10]=$iphoneframeworksroot/Foundation/
iphoneframeworks[11]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[12]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[13]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[14]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[15]=$iphoneframeworksroot/Security/
iphoneframeworks[16]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[17]=$iphoneframeworksroot/UIKit/
iphoneframeworks[18]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done


This is for SDK 3.0 header files to iPhone

copySDKHeaders3.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
SDKVER=3.0
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AVFoundation.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[3]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[5]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[6]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreData.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[10]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[11]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[12]=$sdkroot/ExternalAccessory.framework/Headers/*
sdkframeworks[13]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[14]=$sdkroot/GameKit.framework/Headers/*
sdkframeworks[15]=$sdkroot/MapKit.framework/Headers/*
sdkframeworks[16]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[17]=$sdkroot/MessageUI.framework/Headers/*
sdkframeworks[18]=$sdkroot/MobileCoreServices.framework/Headers/*
sdkframeworks[19]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[20]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[21]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[22]=$sdkroot/Security.framework/Headers/*
sdkframeworks[23]=$sdkroot/StoreKit.framework/Headers/*
sdkframeworks[24]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[25]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[26]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVER}.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AVFoundation/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[3]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[4]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[5]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[6]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[7]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[8]=$iphoneframeworksroot/CoreData/
iphoneframeworks[9]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[10]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[11]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[12]=$iphoneframeworksroot/ExternalAccessory/
iphoneframeworks[13]=$iphoneframeworksroot/Foundation/
iphoneframeworks[14]=$iphoneframeworksroot/GameKit/
iphoneframeworks[15]=$iphoneframeworksroot/MapKit/
iphoneframeworks[16]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[17]=$iphoneframeworksroot/MessageUI/
iphoneframeworks[18]=$iphoneframeworksroot/MobileCoreServices/
iphoneframeworks[19]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[20]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[21]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[22]=$iphoneframeworksroot/Security/
iphoneframeworks[23]=$iphoneframeworksroot/StoreKit/
iphoneframeworks[24]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[25]=$iphoneframeworksroot/UIKit/
iphoneframeworks[26]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVER}.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done

.
.
.

Wednesday, September 10, 2008

[How-to] Install gcc compiler and build toolchain app for pwned iPhone 2.0.x firmware

The gcc in iPhone procedure is updated here for the pwned iPhone firmware 2.0/2.0.1/2.0.2

If you install iPhone GCC, it is important to set root partition to about 700M in pwnage, if you set it too small your will get into trouble whenever there is an upgrade of GCC, as some of the libexec cannot be symlink to second partition.

You have to install the following packages in Cydia
  • GNU C Compiler 
  • iPhone 2.0 Toolchain 
  • Make 
  • Link Indentity Editor
  • wget (... in order to download the following sample in iPhone)
  • zip (... in order to unzip the following sample in iPhone)

then download the following zip file in your iPhone to test build your iPhone toolchain app

shellscript: Select all

wget http://www.iphone.org.hk/attach/38270-HelloWorld2.zip
unzip 38270-HelloWorld2.zip



shellscript: Select all

cd HelloWorld
make
make install


Restart your springboard, then you will have the HelloWorld app on your springboard

To uninstall HelloWorld.app
shellscript: Select all

cd HelloWorld
make uninstall

Wednesday, August 27, 2008

How-To copy SDK headers to iPhone and compile SDK applications in iPhone

Pre-requisites:
(1) jailbreak iPhone with pwned firmware 2.0.x
(2) Install the following packages in Cydia Installer

  • GNU C Compiler

  • iPhone 2.0 Toolchain

  • Make

  • Link Indentity Editor

  • wget (... in order to download the following sample in iPhone)

  • zip (... in order to unzip the following sample in iPhone)



Here is the procedure on how to copy the iPhone SDK headers from your mac to iPhone GCC to have a SDK development environment in iPhone

I have installed the sdk header files to /var/sdk of iPhone

If you use Linux / Microsoft Windows, see this on how to get the header files from the SDK
http://www.theiphonewiki.com/wiki/index.php?title=Toolchain_2.0

Use this shell script in Mac Terminal to copy the installed SDK header files to iPhone directly
and you have to change IPHONEIP for your actual iPhone IP address

copySDKHeaders.sh : Select all

#!/bin/sh
IPHONEIP=10.0.2.2
sdkroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/System/Library/Frameworks
sdkframeworks[1]=$sdkroot/AddressBook.framework/Headers/*
sdkframeworks[2]=$sdkroot/AddressBookUI.framework/Headers/*
sdkframeworks[3]=$sdkroot/AudioToolbox.framework/Headers/*
sdkframeworks[4]=$sdkroot/AudioUnit.framework/Headers/*
sdkframeworks[5]=$sdkroot/CFNetwork.framework/Headers/*
sdkframeworks[6]=$sdkroot/CoreAudio.framework/Headers/*
sdkframeworks[7]=$sdkroot/CoreFoundation.framework/Headers/*
sdkframeworks[8]=$sdkroot/CoreGraphics.framework/Headers/*
sdkframeworks[9]=$sdkroot/CoreLocation.framework/Headers/*
sdkframeworks[10]=$sdkroot/Foundation.framework/Headers/*
sdkframeworks[11]=$sdkroot/MediaPlayer.framework/Headers/*
sdkframeworks[12]=$sdkroot/OpenAL.framework/Headers/*
sdkframeworks[13]=$sdkroot/OpenGLES.framework/Headers/*
sdkframeworks[14]=$sdkroot/QuartzCore.framework/Headers/*
sdkframeworks[15]=$sdkroot/Security.framework/Headers/*
sdkframeworks[16]=$sdkroot/SystemConfiguration.framework/Headers/*
sdkframeworks[17]=$sdkroot/UIKit.framework/Headers/*
sdkframeworks[18]=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk/System/Library/Frameworks/IOKit.framework/Headers/*
iphonesdkroot=/var/sdk
iphoneframeworksroot=$iphonesdkroot/include
iphoneframeworks[1]=$iphoneframeworksroot/AddressBook/
iphoneframeworks[2]=$iphoneframeworksroot/AddressBookUI/
iphoneframeworks[3]=$iphoneframeworksroot/AudioToolbox/
iphoneframeworks[4]=$iphoneframeworksroot/AudioUnit/
iphoneframeworks[5]=$iphoneframeworksroot/CFNetwork/
iphoneframeworks[6]=$iphoneframeworksroot/CoreAudio/
iphoneframeworks[7]=$iphoneframeworksroot/CoreFoundation/
iphoneframeworks[8]=$iphoneframeworksroot/CoreGraphics/
iphoneframeworks[9]=$iphoneframeworksroot/CoreLocation/
iphoneframeworks[10]=$iphoneframeworksroot/Foundation/
iphoneframeworks[11]=$iphoneframeworksroot/MediaPlayer/
iphoneframeworks[12]=$iphoneframeworksroot/OpenAL/
iphoneframeworks[13]=$iphoneframeworksroot/OpenGLES/
iphoneframeworks[14]=$iphoneframeworksroot/QuartzCore/
iphoneframeworks[15]=$iphoneframeworksroot/Security/
iphoneframeworks[16]=$iphoneframeworksroot/SystemConfiguration/
iphoneframeworks[17]=$iphoneframeworksroot/UIKit/
iphoneframeworks[18]=$iphoneframeworksroot/IOKit/

ssh root@$IPHONEIP "mkdir -p $iphoneframeworksroot"
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include root@$IPHONEIP:$iphonesdkroot
scp -r /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/lib root@$IPHONEIP:$iphonesdkroot

for index in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
do
echo "copying ${sdkframeworks[index]} to ${iphoneframeworks[index]}"
ssh root@$IPHONEIP "mkdir -p ${iphoneframeworks[index]}"
scp -r ${sdkframeworks[index]} root@$IPHONEIP:${iphoneframeworks[index]}
done


In order to avoid typing the password using ssh, you can install the ssh public key of your Mac to your iPhone using the following method

(a) keygen in Mac terminal and type (if you haven't generated it before)
Select all

ssh-keygen -t rsa


(b) create .ssh directory in iPhone (assume ip address of iPhone is 10.0.2.2)
Select all

ssh root@10.0.2.2 'mkdir -p .ssh'

then enter iPhone root password (alpine)

(c) copy mac public key to iPhone, and in Mac Terminal type
Select all
cat ~/.ssh/id_rsa.pub | ssh root@10.0.2.2 'cat >> .ssh/authorized_keys'

then enter iPhone root password (alpine)

(d) Edit the file /etc/ssh/sshd_config in iPhone

change these
Select all

#StrictModes yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys


to

Select all

StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys


(e)reboot iPhone

I have successfully compiled a modified SDK sample app UICategory (non-Interface Builder verison)

Here is the project folder to test your installation.

(i) copy it (using wget) and unzip it in iPhone
Select all

wget http://www.iphone.org.hk/attach/39773-UICatalog.zip
unzip 39773-UICatalog.zip


(ii) then run
Select all

cd UICatalog
make
make install


to build and install the project in iPhone

Saturday, June 28, 2008

[How-To] Install gcc compiler in iPhone (1.1.x firmware)

Cydia is a new package management replacement to the existing Installer.app. And it now also brings the gcc compiler to iPhone in firmware 1.1.x

Although it is slow to compile in iPhone but it is stable and very native.

You can follow these steps to install the compiler and related headers and utilities:

1. Set your iPhone Auto-Lock to "Never"
2. Goto Installer and install the package called "Cydia Installer" (version 1.0). It will take some time to download and install, so you should have connected your iPhone to Wifi
3. After installation of Cydia, iPhone will reboot and you will find a new icon "Cydia" in your Home Screen. Start "Cydia" and it will tell you to update Critical Packages. Follow the instructions to "Update All"
4. After update of Critical Packages in Cydia, install the following 3 packages

GNU C Compiler
Make
iPhone 1.1.1 Headers

5. Then you can have gcc compiler in your iPhone now. You can use Mac Terminal or putty to access the terminal of iPhone and start building your application.

Please take note that after the installation of Cydia, your BSD subsystem is now changed to Fake BSD subsystem and also fixed a number of bugs. So don't update BSD subsystem from the Installer.app

You may want to try some HelloWorld example, and here is the project that you can try

copy and unzip it to your iPhone
then

cd HelloWorld
make install
./restart


Then you will have a new program HelloWorld.

To uninstall this HelloWorld

make uninstall



Enjoy!