以OS X 10.9.3为例,手机系统为iOS 5.1.1。
准备工作
1.Mac上需安装常规开发的工具(git、make、perl等),还需要iOS的SDK。
2.iPhone中安装OpenSSH服务器。
安装Theos
以安装在~/theos目录下为例。
1.设置THEOS环境变量:
1 |
export THEOS=~/theos |
2.下载Theos:
1 |
git clone git://github.com/DHowett/theos.git $THEOS |
3.下载ldid源码并编译,复制到$THEOS/bin目录下:
1 2 3 4 5 |
git clone git://git.saurik.com/ldid.git cd ldid git submodule update --init ./make.sh cp -f ./ldid $THEOS/bin/ldid |
4.下载所需的头文件:
1 2 |
git clone https://github.com/rpetrich/iphoneheaders mv ./iphoneheaders/* $THEOS/include |
5.OS X Lion以上的系统需修改头文件IOSurfaceAPI.h,注释掉下面4行代码:
1 2 3 4 5 6 7 8 9 |
/* This call lets you get an xpcobject_t that holds a reference to the IOSurface. Note: Any live XPC objects created from an IOSurfaceRef implicity increase the IOSurface's global use count by one until the object is destroyed. */ // xpc_object_t IOSurfaceCreateXPCObject(IOSurfaceRef aSurface) // IOSFC_AVAILABLE_STARTING(_MAC_10_7, __IPHONE_NA); /* This call lets you take an xpcobject_t created via IOSurfaceCreatePort() and recreate an IOSurfaceRef from it. */ // IOSurfaceRef IOSurfaceLookupFromXPCObject(xpc_object_t xobj) // IOSFC_AVAILABLE_STARTING(_MAC_10_7, __IPHONE_NA); |
创建应用编译并安装
1.运行New Instance Creator:
1 |
$THEOS/bin/nic.pl |
2.选择tweak模板:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
NIC 2.0 - New Instance Creator —————————— [1.] iphone/application [2.] iphone/library [3.] iphone/preference_bundle [4.] iphone/tool [5.] iphone/tweak Choose a Template (required): 5 Project Name (required): WelcomeWagon Package Name [com.yourcompany.welcomewagon]: Author/Maintainer Name [Brandon Trebitowski]: MobileSubstrate Bundle filter [com.apple.springboard]: Instantiating iphone/tweak in welcomewagon/… Done. |
3.添加代码至Tweak.xm,Hook SpringBoard的init方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#import <SpringBoard/SpringBoard.h> %hook SpringBoard -(void)applicationDidFinishLaunching:(id)application { %orig; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Welcome to your iPhone Brandon!" delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil]; [alert show]; [alert release]; } %end |
4.Makefile中添加一行:
1 |
WelcomeWagon_FRAMEWORKS = UIKit |
5.编译、打包并安装:
1 2 |
export THEOS_DEVICE_IP=iPhone的IP make package install |
6.安装后开机将弹出“Welcome to your iPhone Brandon!”的对话框。
参考链接
使用Theos做一个简单的Mobile Substrate Tweak
iOS越狱程序开发(3)- Your First Tweak