一、安装签名工具ldid
- 先确保安装了brew
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- 利用brew安装ldid
% brew install ldid
二、修改环境变量
- 编辑用户的配置文件
% vim ~/.bash_profile
- 在.bash_profie文件后面加入以下两行
export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
- 让.bash_profile配置的环境变量立即生效(或者重新打开终端)
% source ~/.bash_profile
- 检查环境变量是否生效
% echo $THEOS
三、下载theos
建议在$THEOS目录下载代码(也就是刚才配置的~/theos目录)
%git clone --recursive https://github.com/theos/theos.git $THEOS
四、新建tweak项目
-
cd到一个存放项目的文件夹(比如桌面)
% cd ~/Desktop
% nic.pl
-
选择 iphone/tweak
NIC 2.0 - New Instance Creator
------------------------------
[1.] iphone/activator_event
[2.] iphone/activator_listener
[3.] iphone/application_modern
[4.] iphone/application_swift
[5.] iphone/cydget
[6.] iphone/flipswitch_switch
[7.] iphone/framework
[8.] iphone/library
[9.] iphone/notification_center_widget
[10.] iphone/notification_center_widget-7up
[11.] iphone/preference_bundle_modern
[12.] iphone/theme
[13.] iphone/tool
[14.] iphone/tool_swift
[15.] iphone/tweak
[16.] iphone/tweak_with_simple_preferences
[17.] iphone/xpc_service
Choose a Template (required): 15
- 填写项目信息
- Project Name:项目名称
- Package Name:项目ID
- Author/Maintainer Name:作者
- [iphone/tweak] MobileSubstrate Bundle filter:
需要hook的APP的Bundle Identifier - [iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]:
直接敲回车默认做法就行
Project Name (required): springBoard_tweak
Package Name [com.yourcompany.springboard_tweak]: com.lingli.springborad
Author/Maintainer Name [lingli]: lingliz
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]:
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]:
Instantiating iphone/tweak in springboard_tweak/...
Done.
五、编辑Makefile
- 在前面加入环境变量、写清楚通过哪个IP和端口访问手机
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=10010
- 如果不希望每个项目的Makefile都编写IP和端口环境变量,也可以添加到用户配置文件
~/.bash_profile
中
六、编写代码
- 编写Tweak.xm文件
%hook SBIconParallaxBadgeView
- (id)init
{
return nil;
}
%end
七、编译-打包-安装
- 编译
make
- 打包成deb
make package
:make package 包含make操作,
make package debug=0
:安装release版本 - 安装(默认会自动重启SpringBoard)
make install
- 清理缓存
make clean
八、theos-tweak的实现过程
- 编写Tweak代码
-
%make
:编译Tweak代码为动态库(.dylib) -
%make package
:将dylib打包为deb文件 -
%make install
:将deb文件传送到手机上,通过Cydia安装deb - 插件将会安装在/Library/MobileSubstrate/DynamicLibraries文件夹中
- .dylib:编译后的Tweak代码
- .plist:存放着需要hook的APP ID
- 当打开APP时,Cydia Substrate会通过.plist文件中的APP ID让APP去加载对应的dylib,修改APP内存中的代码逻辑,去执行dylib中的函数代码
- 所以,theos的tweak并不会对APP原来的可执行文件进行修改,仅仅是修改了内存中的代码逻辑
疑问
- 未脱壳的APP是否支持tweak?
支持,因为tweak是在内存中实现的,并没有修改.app包中的可执行文件 - tweak效果是否永久性的?/一旦更新App,tweak会不会失效?
取决于tweak中用到的app代码是否被修改过 - 未越狱的手机是否支持tweak?
不支持 - 能否对Swift/C函数进行tweak?能否对游戏项目进行tweak?
可以
网友评论