arm64架構php
檢查手機及對應版本是否能夠越獄:jailbreak.25pp.com/iospython
$ 爲 Mac 終端命令,# 爲 iPhone 終端命令ios
默認密碼 alpine
git
$ ssh root@<iPhone-IP-Address>
複製代碼
刪除公鑰信息(~/.ssh/known_hosts
)github
$ ssh-keygen -R <iPhone-IP-Address>
複製代碼
$ ssh-keygen
$ ssh-copy-id root@<iPhone-IP-Address>
$ scp ~/.ssh/id_rsa.pub root@<iPhone-IP-Address>:~
$ ssh root@<iPhone-IP-Address>
# mkdir .ssh
# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
# rm ~/id_rsa.pub
# chmod 755 ~
# chmod 755 ~/.ssh
# chmod 644 ~/.ssh/authorized_keys
複製代碼
下載 usbmuxd 到 ~/Documents
,把 iPhone 的 22 端口映射到本機 localhost 的 10010 端口objective-c
$ cd ~/Documents/usbmuxd-1.0.8/python-client
$ python tcprelay.py -t 22:10010 10011:10011
複製代碼
新建一個命令行窗口,經過鏈接 localhost 的 10010 端口即鏈接 iPhone 的 22 端口express
$ ssh root@localhost -p 10010
複製代碼
在 ~/.inputrc
裏添加如下內容:sass
set convert-meta off
set output-meta on
set meta-flag on
set input-meta on
複製代碼
經常使用工具:mjcriptbash
列出全部進程服務器
# ps -A
複製代碼
進入 App 的 Cycript 環境
# cycript -p <pid or app_exec_name>
複製代碼
經常使用語法
[UIApplication sharedApplication]
UIApp
var app = UIApp.keyWindow
#<address_value>
ObjectiveC.classes
*UIApp
UIApp.keyWindow.recursiveDescription().toString()
choose(UIViewController)
複製代碼
#define MH_OBJECT 0x1 /* relocatable object file */
#define MH_EXECUTE 0x2 /* demand paged executable file */
#define MH_FVMLIB 0x3 /* fixed VM shared library file */
#define MH_CORE 0x4 /* core file */
#define MH_PRELOAD 0x5 /* preloaded executable file */
#define MH_DYLIB 0x6 /* dynamically bound shared library */
#define MH_DYLINKER 0x7 /* dynamic link editor */
#define MH_BUNDLE 0x8 /* dynamically bound bundle file */
#define MH_DYLIB_STUB 0x9 /* shared library stub for static */
/* linking only, no section contents */
#define MH_DSYM 0xa /* companion file with only debug */
/* sections */
#define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */
複製代碼
常見 Mach-O | 描述 |
---|---|
MH_OBJECT | 目標文件(.o)靜態庫文件(.a)即多個 .o 合併在一塊兒 |
MH_DYLIB | 動態庫 dylib 和 framework |
MH_DYLINKER | 動態連接編輯器 /usr/lib/dyld |
MH_DSYM | 存儲二進制文件符號信息的文件.dSYM/Contents/Resources/DWARF/xxx (經常使用於分析APP的崩潰信息) |
查看Mach-O的文件類型
$ file <file_dir>
複製代碼
導出某種特定架構
$ lipo <mach_o_file_dir> -thin arm64 -output <output_dir>
複製代碼
合併多種架構
$ lipo <mach_o_file_1> <mach_o_file_2> -output <output_dir>
複製代碼
工具
查看可執行文件是否已脫殼
$ otool -l <exec_dir> | grep crypt
複製代碼
crypt
爲 0
則已脫殼
將 make
編譯後獲得的 dumpdecrypted.dylib
放到 /var/root/
下,使用 ps -A
獲取 App 可執行文件
# DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib <exec_dir>
複製代碼
使用工具 class-dump 導出 Objective-C 編寫的 App 的頭文件
$ class-dump -H <app_exec_dir> -o <headers_folder_output_dir>
複製代碼
安裝簽名工具 ldid
$ brew install ldid
複製代碼
配置環境變量,在 .bash_profile
里加入:
$ export THEOS=~/theos
$ export PATH=$THEOS/bin:$PATH
$ export THEOS_DEVICE_IP=127.0.0.1
$ export THEOS_DEVICE_PORT=10010
複製代碼
下載 theos
$ cd ~ && git clone --recursive https://github.com/theos/theos.git $THEOS
複製代碼
建立 tweak
項目
$ nic.pl
複製代碼
選擇 [iphone/tweak]
MobileSubstrate Bundle filter: 破解 App 的 Bundle ID
打開 Tweak.xm
文件編寫代碼
%hook XXXView
- (id)initWithFrame:(struct CGRect)arg1 {
return nil;
}
%end
複製代碼
編譯打包安裝
$ make clean && make && make package && make install
複製代碼
其餘資料:
目錄結構:github.com/theos/theos… 環境變量:iphonedevwiki.net/index.php/T… Logos語法:iphonedevwiki.net/index.php/L…
複製 iPhone 上 /Developer
裏的 debugserver
,導出 entitlements
權限文件
$ ldid -e debugserver > debugserver.entitlements
複製代碼
打開 entitlements
文件,增長如下兩項:
Boolen
值,設爲 YES
而後把 entitlements
權限從新籤給 debugserver
$ ldid -Sdebugserver.entitlements debugserver
複製代碼
再把 debugserver
移動到 iPhone 的 /usr/bin
下
# debugserver *:10011 -a <pid or app_exec_name>
複製代碼
啓動 lldb
並鏈接 debugserver
$ lldb
(lldb) process connect connect://<iPhone-IP-Address>:10011
複製代碼
# debugserver -x auto *:10011 <app_exec_dir>
複製代碼
執行一個表達式
(lldb) expression self.view.backgroundColor = [UIColor redColor]
複製代碼
--
爲命令選項結束符
打印線程堆棧信息
(lldb) thread backtrace
(lldb) bt
複製代碼
讓函數不執行斷電後的內容並直接返回
(lldb) thread return
複製代碼
打印當前棧幀變量
(lldb) frame variable
複製代碼
繼續運行
(lldb) thread continue
(lldb) continue
(lldb) c
複製代碼
單步運行(子函數爲一步)
(lldb) thread step-over
(lldb) next
(lldb) n
(lldb) ni # instruction
複製代碼
單步運行(遇到子函數則進入)
(lldb) thread step-in
(lldb) step
(lldb) s
(lldb) si # instructios
複製代碼
執行完當前函數全部代碼,返回上一個函數
(lldb) thread step-out
(lldb) finish
複製代碼
斷點
(lldb) breakpoint set -n test
(lldb) breakpoint set -n touchesBegan:withEvent:
(lldb) breakpoint set -n "-[ViewController touchesBegan:withEvent:]"
(lldb) breakpoint set -r <regex_expression>
(lldb) breakpoint list
(lldb) breakpoint enable <bpt_no>
(lldb) breakpoint disable <bpt_no>
(lldb) breakpoint delete <bpt_no>
複製代碼
內存斷點(在內存數據發生改變時觸發)
(lldb) watchpoint set variable self->age
(lldb) watchpoint set expression &(self->_age)
複製代碼
查找某個類型的信息
(lldb) image lookup -t <type>
複製代碼
根據內存地址查找在模塊中的位置
(lldb) image lookup -a <address>
複製代碼
查找某個符號或者函數的位置
(lldb) image lookup -n <symbol_name or func_name>
複製代碼
列出所加載模塊的信息
(lldb) image list
(lldb) image list -o -f # 打印模塊全路徑和偏移地址
複製代碼
獲取使用付費證書在 Xcode 編譯後的 App 包中的 embedded.mobileprovision
文件
從 embedded.mobileprovision
提取 entitlements.plist
權限文件
$ security cms -D -i embedded.mobileprovision > tmp.plist
$ /usr/libexec/PlistBuddy -x -c 'Print :Entitlements' tmp.plist > entitlements.plist
複製代碼
查看可用證書
$ security find-identity -v -p codesigning
複製代碼
對 .app
包內的動態庫,AppExtension 等進行重簽名
$ codesign -fs <cer_id or cer_str> <dylib_dir>
複製代碼
對 .app
包進行重簽名
$ codesign -fs <cer_id or cer_str> --entitlements entitlements.plist <app_file>
複製代碼
GUI工具:
提取
embedded.mobileprovision
拷貝到.app
內部後,再使用 iOS App Signer 工具進行重簽名
下載工具包 insert_dylib,編譯後把可執行文件放入 /usr/local/bin
$ cd <app_file_exec_dir>
複製代碼
在 iPhone 的 /Library/MobileSubstrate/DynamicLibararies
目錄下找到把編寫的 tweak
項目生成的動態庫,把它拷貝出來,注入到 App 可執行文件中
$ insert_dylib @executable_path/<tweak_dylib_name> <app_exec_name> --all-yes --waek <app_exec_name>
複製代碼
拷貝 iPhone 的 /Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate
到 tweak
項目生成的動態庫同級目錄下
更改 tweak
項目生成的動態庫依賴項目錄
$ install_name_tool -change /Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate @loader_path/CydiaSubstrate <tweak_dylib_name>
複製代碼
重簽名後安裝 ipa
文件到非越獄手機上
關於更多內容能夠查看個人我的博客
以上大部分代碼和工具包能夠在個人 GitHub 裏找到