閱讀此文前,請確保iOS裝置已越獄,否則一切都是空談!
1.環境安裝
a.指定xcode(根據自己xcode路徑來):
sudo xcode-select -s/Applications/Xcode.app/Contents/Developer
複製程式碼
b.下載Theos(export很重要):
export THEOS=/opt/theos sudo git clone git://github.com/theos/theos.git $THEOS
複製程式碼
c.下載ldid :
http://joedj.net/ldid 然後複製到/opt/theos/bin 然後sudo chmod 777 /opt/theos/bin/ldid
d.配置CydiaSubstrate:
注意
新版本Theos請直接跳過 執行Theos自動化配置指令碼 直接使用iFunBox提取CydiaSubstrate
複製程式碼
用iFunBox等iPhone上的工具,將iOS上/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate
拷貝到電腦上 然後改名為libsubstrate.dylib , 然後拷貝到/opt/theos/lib 中.
e.配置dkpg
deb 是越獄開發安裝包的標準格式,而 dpkg-deb 是操作 deb 檔案的工具,有了這個工具,Theos 才能將工程正確地打包成 deb 包。
從[下載](https://raw.githubusercontent.com/DHowett/dm.pl/master/dm.pl)下載dm.pl,將其重新命名為 dpkg-deb 後(如果字尾名還是.pl,顯示簡介中可以修改),
放到 “/opt/theos/bin/“ 目錄下,然後設定它的可執行許可權:
sudo chmod 777 /opt/theos/bin/dpkg-deb
其實,Theos 已經是一個 tweak 的開發環境了,但是由於這裡只是因為需要編譯 tweak 而用到它,所以它的很多後續配置也沒有詳細講解了。
複製程式碼
至此,我們的安裝環境就搭建完了,下一步可以正式地開始安裝 tweak 了。
2.Theos用法
輸入
/opt/theos/bin/nic.pl
複製程式碼
NIC 2.0 - New Instance Creator
------------------------------
[1.] iphone/activator_event
[2.] iphone/application_modern
[3.] iphone/cydget
[4.] iphone/flipswitch_switch
[5.] iphone/framework
[6.] iphone/ios7_notification_center_widget
[7.] iphone/library
[8.] iphone/notification_center_widget
[9.] iphone/preference_bundle_modern
[10.] iphone/tool
[11.] iphone/tweak
[12.] iphone/xpc_service
Choose a Template (required):
複製程式碼
選擇 [11.] iphone/tweak
Choose a Template (required): 11
Project Name (required): iOSREProject
Package Name [com.yourcompany.iosreproject]: com.yuhao.iosreproject
Author/Maintainer Name [yuhao]: sthyuhao
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.springboard
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: SpringBoard
Instantiating iphone/tweak in iosreproject/...
Done.
第一個相當於工程資料夾的名字
第二個相當於bundle id
第三個就是作者
第四個是作用物件的bundle identifier
第五個是要重啟的應用
複製程式碼
完成這幾步之後,一個iosreproject資料夾就在當前目錄生成了,該資料夾就是剛建立的tweak工程。
編寫Tweak
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome"message:@"Welcome to your iPhone!"delegate:nilcancelButtonTitle:@"Thanks"otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end
複製程式碼
為什麼要release
因為Tweak預設編碼方式是MRC
如果需要ARC的話 在MakeFile中插入TweakName_CFLAGS = -fobjc-arc
在Tweak注入之前需要先在終端執行
export THEOS=/opt/theos/
export THEOS_DEVICE_IP=xxx.xxx.xxx.xxx(手機的ip地址)
複製程式碼
3.構建工程
先
make package install
複製程式碼
過程會讓你輸入兩次iphoen密碼 , 預設是alpine