- 安装签名工具
brew install ldid
- 安装theos
vs ~/.zshrc
export THEOS=/opt/theos
export PATH=$THEOS/bin:$PATH
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=2222
git clone --recursive https://github.com/theos/theos.git $THEOS
- 创建tweak,配置环境变量 ip
export THEOS_DEVICE_IP=127.0.0.1
port,export THEOS_DEVICE_PORT=2222
。直接把环境变量写到~/.zshrc
文件省事。可修改
nic.pl #选iphone/tweak
make #编译
make package debug=0[默认+1] #打包输出 .deb
make install # 安装到手机
- 卸载插件
rm /Library/MoblieSubstrate/DynamicLibraries/xxx.dylib [xxx.plist]
- 资源文件
# thoes会把layout当成根目录 把下面的文件copy到手机上
layout/Library/PreferencelLoader/Prefrence/
tweak原理
- make操作,把代码编译成
.dylib
- make package, 把动态库打包进
.deb
软件安装包,即cydia下载安装的插件
- make install,通过ssh连接ip:port的手机传输deb,并安装,把动态库解压出来,安装到
/Library/MobileSubstrate/DynamicLibraries
,一个dylib,一个plist。plist记录需要使用插件的bunldid。
cydia substrate
来查看上述文件夹,发现打开应用程序的标题和plist一样,就加载指定的dylib。内存中的代码执行流程将发生改变。并没有把代码注入到macho文件
- 多文件开发
# 编译文件
tweak_xx_file= src/*.xm src/Model/*.m
tweak_xx_file = $(wildcard src/*xm)
# 资源文件
layout/Library/Caches
- 构造器方法
%ctor {
NSLog("-----加载动态库时运行-----")
}
%dtor {
NSLog("-----程序结束时运行-----")
}
- make package包含make编译操作
插件开发
- 创建
nic.pl #选iphone/tweak
tree
## 输出如下
testiphone
├── Makefile
├── Tweak.x
├── control
└── testiphone.plist
- 修改
.plist
{ Filter = { Bundles = ( "com.dsx.brother11.OCEmpty" ); }; }
- 编写
Tweak.x
#import <UIKit/UIKit.h>
@interface ViewController: UIViewController
@end
%hook ViewController
- (void)viewDidLoad {
%orig;
self.view.backgroundColor = UIColor.blueColor;
}
%end
- 编译打包安装完后
/Library/MobileSubstrate/DynamicLibraries
下多了testiphone.dylib
,testiphone.plist
文件。
make package instal
手机命令行工具开发
- 新建iOSapp项目,删除其它留下main,plist
// argc:参数个数
// argv 参数,第一个是可执行文件路径
int main(int argc, char * argv[]) {
@autoreleasepool {
return 0;
}
}
- 给可执行文件签上权限
# 查看权限
ldid -e file > file.entitlements
# 签权限
ldid -SSpringBoard.entitlements file
- 创建
nic.pl #选iphone/tool
tree
# 输出
./testtool
├── Makefile
├── control
├── entitlements.plist
└── main.m
- 编写main.m
int main(int argc, char *argv[], char *envp[]) {
printf("Hello world!\n");
return 0;
}
- 编译安装后,在
/usr/local/bin
文件下多了一个testtool命令。这个path可以在makefile
中testtool_INSTALL_PATH
修改。
系统级应用开发
- 创建项目
nic.pl #选iphone/application_modern
tree
# 输出
tree
.
├── LZAppDelegate.h
├── LZAppDelegate.m
├── LZRootViewController.h
├── LZRootViewController.m
├── Makefile
├── Resources
│ ├── AppIcon.png
│ ├── Info.plist
│ └── LaunchImage@2x.png
├── control
└── main.m
- 修改makfile,增加下面内容
ARCHS = arm64
after-install::
install.exec "uicache"
install.exec "killall \"PYGiOSReBookApp\"" || true
- 执行安装,安装到
/Applications
文件夹下,可在Cydia
进行卸载。
守护进程(Daemon)
- iOS的根进程
launchd
会在开机时检查/System/Library/LaunchDaemons
和/Library/LaunchDaemons
下所有符合条件的plist
文件,然后启动对应的守护进程。
·. 创建。nic.pl #选iphone/tool
,创建com.yourcompany.pygiosrebookd.plist
文件放到./layout/Library/LaunchDaemons
中。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.yourcompany.pygiosrebookd</string>
<key>Program</key>
<string>/usr/bin/pygiosrebookd</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
- 安装运行后会在
pygiosrebookd_INSTALL_PATH = /usr/bin
下生成工具。
- 加载/卸载
launchctl load /Library/LaunchDaemons/com.yourcompany.pygiosrebookd.plist
launchctl unload /Library/LaunchDaemons/com.yourcompany.pygiosrebookd.plist