0、說到越獄插件開發,一般搜下去 都是 Tweak、Theos 之類的。按我學習的流水記錄下。
1、終端安裝theos(相當於宏定義一個路徑為THEOS,把這個git的東西下載到這個宏/路徑)
export THEOS=/opt/theos git clone --recursive https://github.com/theos/theos.git $THEOS
2、安裝brew(前提是ruby已安裝,一般安裝過cocoapods,就已經安裝過ruby了)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
注:這個時候,可能下載不下來。可能需要添加hosts
sudo vi /etc/hosts
然后把這個網址 https://site.ip138.com/raw.Githubusercontent.com/ 解析的IP加進去
# GitHub Start 52.74.223.119 github.com 192.30.253.119 gist.github.com 54.169.195.247 api.github.com 185.199.111.153 assets-cdn.github.com 151.101.76.133 raw.githubusercontent.com 151.101.108.133 user-images.githubusercontent.com 151.101.76.133 gist.githubusercontent.com 151.101.76.133 cloud.githubusercontent.com 151.101.76.133 camo.githubusercontent.com 151.101.76.133 avatars0.githubusercontent.com 151.101.76.133 avatars1.githubusercontent.com 151.101.76.133 avatars2.githubusercontent.com 151.101.76.133 avatars3.githubusercontent.com 151.101.76.133 avatars4.githubusercontent.com 151.101.76.133 avatars5.githubusercontent.com 151.101.76.133 avatars6.githubusercontent.com 151.101.76.133 avatars7.githubusercontent.com 151.101.76.133 avatars8.githubusercontent.com # GitHub End
注:hosts解析 參考自該文章 https://blog.csdn.net/laoxuan2011/article/details/106177126?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160459280619724838554874%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160459280619724838554874&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_click~default-1-106177126.pc_v1_rank_blog_v1&utm_term=raw.githubusercontent.com&spm=1018.2118.3001.4450
3、安裝ldid(簽名用)
brew install ldid
4、安裝dpkg(打包成deb)
brew install dpkg
5 、安裝 command line tools(不清楚用在哪里,照着教程裝)
https://developer.apple.com/downloads/?=Command%20Line%20Tools%20
6、安裝 sshpass(應該不需要,先跳過,有需要再看)
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
基本會報錯,
Error: Calling Non-checksummed download of sshpass formula file from an arbitrary URL is disabled! Use 'brew extract' or 'brew create' and 'brew tap-new' to create a formula file in a tap on GitHub instead.
網上的資料,都是 waring ,直接跳過,我的終端卻是 error ,安裝失敗。這個時候可以下載至本地再次執行安裝
wget https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb brew install sshpass.rb
注:如果 wget 指令沒有的話,還需要先裝 wget
brew install wget
7、安裝 openssh(好像有git的,基本都有裝openssh了。ssh-copy-id 要裝,以后在終端執行ssh root@ip,就不用再輸密碼了)
brew install openssl
brew install ssh-copy-id
============================================== 安裝 完成 ==============================================
0、開始創建第一個demo
1、每次打開終端,都需要對路徑進行“宏定義”一次(第二行才是創建)
export THEOS=/opt/theos
$THEOS/bin/nic.pl
2、然后根據返回的列表,輸入 iphone/tweal 的序號。
3、然后是 項目名、包名、開發者、監聽領域、回車。
注:好像 1)包名不能大寫,不然編譯有問題。
2)監聽領域:默認 om.apple.springboard ,iOS的桌面app
com.apple.UIKit ,作用於所有的app
4、這個時候,會在 /Users,生成 項目名的文件夾。(為什么是/Users ? 因為,每次打開終端,都默認 /Users ,除非,自己再 cd )
5、對 .x 或者 .xm 編程(版本不同 后綴不同,其實一樣的)。
編程內容為 %hook 開機類名,然后是方法名,%orig 是繼續執行原來代碼的意思,相當於[super xxx],最后%end。
#import <SpringBoard/SpringBoard.h> %hook SpringBoard -(void)applicationDidFinishLaunching:(id)application { %orig; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你好" message:@"歡迎使用" delegate:nil cancelButtonTitle:@"hook成功了" otherButtonTitles:nil]; [alert show]; } %end
注:網上寫,如果不%orig,沒辦法進入系統,因為iOS桌面app沒法執行下一步。
(分支)、手機第一次用openssh,需要設置密碼(手機端,也要記得從 cydia 下 openssh )
獲得手機控制權(SSH),終端輸入
ssh root@同一Wi-Fi下的越獄手機ip
再設置/輸入密碼,一般都是 alpine(可修改),連接成功,光標處就變成 root 。(如輸入 reboot ,手機將立即重啟,這里只是說ssh root 后可以做什么,不是要你 reboot 重啟手機)
reboot
注:網上資料看到的修改密碼指令,是這樣的,暫未驗證。
passwd root 修改root用戶密碼 passwd mobile 修改mobile用戶密碼 ssh登錄手機后,在命令行輸入passwd root# passwd Changing password for root. New password: Retype new password: root#
6、打開makefile,填入如下( 手機的IP,直接通過wifi下載/燒寫,項目的UIAlertView 依賴UIKit庫)
export THEOS = /opt/theos export THEOS_DEVICE_IP = 同一Wi-Fi下越獄手機的ip 項目名_FRAMEWORKS = UIKit 放最后 after-install:: install.exec "killall -9 SpringBoard"
7-1、編譯( 先cd 項目文件夾 )
make
注:如果在上面(分支)步驟,終端進入了手機root模式,請先按ctl+D退出,或開新終端窗口
7-2、編譯 帶 Wi-Fi下載( 先cd 項目文件夾 )
make package install
如果上面有裝 openssl、ssh-copy-id ,可以避免輸兩次密碼安裝
1)、生成密鑰保存(如果使用過git,應該是有生成過了)
ssh-keygen -t rsa -b 2048
2)、復制到手機(有多種寫法,選擇一種即可)
ssh-copy-id -i /Users/用戶名/.ssh/id_rsa root@同一Wi-Fi下的越獄手機ip ssh-copy-id -i root@同一Wi-Fi下的越獄手機ip ssh-copy-id root@同一Wi-Fi下的越獄手機ip
============================================== 出現的坑 ==============================================
1、make 編譯 失敗
==> Error: You do not have any SDKs in /Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/SDKs or /opt/theos/sdks. make: *** [before-all] Error 1
解決
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
2、即使在 makefile 文件寫,庫依賴,但是還是make失敗。
項目名_FRAMEWORKS = UIKit
解決:在 .xm或 .x 文件引入頭文件
#import <UIKit/UIKit.h>
注:可能一些環境配置有問題,導致這個問題的原因還沒找,有空再找找。看別人的案例,都是只設置_FRAMEWORKS。
3、make package install 下載后,無效果(插件沒運行),查了網上一些資料,發現類似的,是下載到根目錄了,需要移動到這個位置(可用愛思助手/iFile 手機越獄軟件)。
/Library/MobileSubstrate/DynamicLibraries/
注:好像是版本的問題(用下面“參考自” - “新:”安裝thoes,沒再出現了)
============================================== 參考自 ==============================================
舊:搭舊版本環境麻煩,要從手機拷貝文件,還要去下載ios頭文件,但第一個demo比較詳細
https://www.jianshu.com/p/b546e26bddb1
新:搭新版本環境 比較快上手
https://www.jianshu.com/p/a5435650e828