Theos

theos

  1. 安装签名工具
brew install ldid
  1. 安装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
  1. 创建tweak,配置环境变量 ipexport 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  # 安装到手机
  1. 卸载插件
rm /Library/MoblieSubstrate/DynamicLibraries/xxx.dylib [xxx.plist]
  1. 资源文件
# thoes会把layout当成根目录 把下面的文件copy到手机上
layout/Library/PreferencelLoader/Prefrence/

tweak原理

  1. make操作,把代码编译成.dylib
  2. make package, 把动态库打包进.deb软件安装包,即cydia下载安装的插件
  3. make install,通过ssh连接ip:port的手机传输deb,并安装,把动态库解压出来,安装到/Library/MobileSubstrate/DynamicLibraries,一个dylib,一个plist。plist记录需要使用插件的bunldid。
  4. cydia substrate来查看上述文件夹,发现打开应用程序的标题和plist一样,就加载指定的dylib。内存中的代码执行流程将发生改变。并没有把代码注入到macho文件
  5. 多文件开发
# 编译文件
tweak_xx_file= src/*.xm src/Model/*.m
tweak_xx_file = $(wildcard src/*xm)
# 资源文件
layout/Library/Caches
  1. 构造器方法
%ctor {
    NSLog("-----加载动态库时运行-----")
}
%dtor {
    NSLog("-----程序结束时运行-----")
}
  1. make package包含make编译操作

插件开发

  1. 创建
nic.pl #选iphone/tweak
tree
## 输出如下
testiphone
├── Makefile
├── Tweak.x
├── control
└── testiphone.plist
  1. 修改.plist
{ Filter = { Bundles = ( "com.dsx.brother11.OCEmpty" ); }; }
  1. 编写Tweak.x
#import <UIKit/UIKit.h>

@interface ViewController: UIViewController
@end 

%hook ViewController
- (void)viewDidLoad {
	%orig;
	self.view.backgroundColor = UIColor.blueColor;
}
%end
  1. 编译打包安装完后 /Library/MobileSubstrate/DynamicLibraries下多了testiphone.dylib,testiphone.plist文件。
make package instal

手机命令行工具开发

  • 原生项目
  1. 新建iOSapp项目,删除其它留下main,plist
// argc:参数个数
// argv 参数,第一个是可执行文件路径
int main(int argc, char * argv[]) {
    @autoreleasepool {
        return 0;
    }
}
  1. 给可执行文件签上权限
# 查看权限
ldid -e file > file.entitlements
# 签权限
ldid -SSpringBoard.entitlements file
  • theos
  1. 创建
nic.pl #选iphone/tool
tree
# 输出
./testtool
├── Makefile
├── control
├── entitlements.plist
└── main.m
  1. 编写main.m
int main(int argc, char *argv[], char *envp[]) {
	printf("Hello world!\n");
	return 0;
}
  1. 编译安装后,在/usr/local/bin文件下多了一个testtool命令。这个path可以在makefiletesttool_INSTALL_PATH修改。

系统级应用开发

  1. 创建项目
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
  1. 修改makfile,增加下面内容
ARCHS = arm64
after-install::
	install.exec "uicache"
	install.exec "killall \"PYGiOSReBookApp\"" || true 
  1. 执行安装,安装到/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>
  1. 安装运行后会在pygiosrebookd_INSTALL_PATH = /usr/bin下生成工具。
  2. 加载/卸载
launchctl load  /Library/LaunchDaemons/com.yourcompany.pygiosrebookd.plist

launchctl unload  /Library/LaunchDaemons/com.yourcompany.pygiosrebookd.plist