开发环境:
macbookpro
macOS 12.7.6
Intel芯片
步骤:
1、安装工具
(1)打开终端,安装必要工具:
brew install perl ldid make git dpkg
(2)安装最新的theos到系统的"~/theos"路径下
git clone --recursive https://github.com/theos/theos.git ~/theos
设置环境变量(建议写入 ~/.zshrc 或 ~/.bash_profile):
export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
然后运行:
source ~/.zshrc # 或 source ~/.bash_profile
2、配置 SDK(用于编译插件)
需要 iOS SDK,一般可以从 Xcode 提取:
cp -r /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk ~/theos/sdks/iPhoneOS16.0.sdk
3、创建 Tweak 项目(Rootless)
(1)在终端执行创建命令
$THEOS/bin/nic.pl
输出:
NIC 2.0 - New Instance Creator
------------------------------
[1.] iphone/application_modern
[2.] iphone/application_swift_modern
[3.] iphone/application_swiftui
[4.] iphone/control_center_module-11up
[5.] iphone/framework
[6.] iphone/library
[7.] iphone/null
[8.] iphone/preference_bundle
[9.] iphone/preference_bundle_swift
[10.] iphone/theme
[11.] iphone/tool
[12.] iphone/tool_swift
[13.] iphone/tweak
[14.] iphone/tweak_swift
[15.] iphone/tweak_with_simple_preferences
[16.] iphone/xpc_service_modern
选择模板13,然后填写包名和其他信息。
(2)修改 Makefile 为 Rootless 格式
在Makefile文件中增加内容:
ARCHS = arm64
THEOS_PACKAGE_SCHEME = rootless
(3)编写代码
在tweak.x中编写代码:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
//手机自动点击”信任“
%hook UIAlertController
- (void)viewDidAppear:(BOOL)animated {
%orig(animated); // 调用原始方法
if ([self.title isEqualToString:@"要信任此电脑吗?"] || [self.title isEqualToString:@"Trust This Computer?"]) {
NSLog(@"hook--[AutoTrust] 发现信任弹窗,尝试自动点击信任按钮");
// 遍历 UIAlertController 的 actions
for (UIAlertAction *action in self.actions) {
if ([action.title isEqualToString:@"信任"] || [action.title isEqualToString:@"Trust"]) {
NSLog(@"hook--[AutoTrust] 找到信任按钮,自动点击");
// 使用 KVC 获取 handler
id handler = [action valueForKey:@"handler"];
if (handler) {
((void(^)(UIAlertAction *))handler)(action); // 执行 handler
}
break;
}
}
}
}
%end
(4)构建与打包
执行命令:
make clean package
打包结果:
4、安装
(1)通过爱思助手拷贝deb文件到手机路径下:
/var/mobile/Documents
(2)可以用手机上的Filza文件管理插件,安装这个deb
(3)用Sileo查看安装路径
(4)重启SpringBoard
(5)手机连接电脑后自动点击“信任”按钮