Showing posts with label mobilesubstrate. Show all posts
Showing posts with label mobilesubstrate. 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, 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