Theos

Theos 是一个越狱开发工具包,安装方法可以参考 Wiki

安装 dpkg

dpkg(Debian Packager) 是 Theos 依赖工具之一,可以使用 dpkg 制作 deb,Theos 开发的插件都会以 deb 的格式进行发布,在安装 Theos 之前需要安装 dpkg,安装借助于 Homebrew 安装,确保先安装 Homebrew。

brew install dpkg

安装 Idid

Theos 开发中,iOS 文件的签名使用 Idid 工具完成,代替了 XCode 中的 Codesign。

brew install ldid

安装 Perl

brew install xz
sudo cpan IO::Compress::Lzma

安装 Theos

将 Theos 安装在 /opt/theos 目录下

sudo Git clone --recursive https://github.com/theos/theos.git /opt/theos

将 /opt/theos 权限改为自己

sudo chown \((id -u):\)(id -g) /opt/theos

配置环境变量

扫描二维码关注公众号,回复: 1249008 查看本文章

export THEOS=/opt/theos
export PATH=/opt/theos/bin/:$PATH

测试是否安装成功

nic.pl

Demo 案例

以启动微信,弹出弹框为力说明

  • 选择Tweak,创建插件名称,插件bundle id,目标应用的bundle id等基本信息
  • 设置完毕后,会生成Control,Makefile,Tweak.xm,ProjectName.plist 文件
  • 对 Makefile, Tweak.xm 修改后执行 make, make package, make install

Control 文件记录了工程的基本信息,会被打包进 deb 包中

//用于描述这个 deb 包的名字,命名方式和 bundle identifier 类似,可以按需更改
Package: com.ecarx.wechatphone
//用于描述工程的名字,可以按需更改
Name: WeChatPhone
//用于描述 deb 包的依赖,以来是指程序运行的基本条件,如果iOS不满足依赖中所定义的条件,则 tweak 无法正常工作,可以按需更改
Depends: mobilesubstrate
//用于描述这个 deb 包的版本号,可以按需更改
Version: 0.0.1
//用于描述 deb 安装的目标设备架构,不要更改
Architecture: iphoneos-arm
//deb 包的简单介绍,可以按需更改
Description: An awesome MobileSubstrate tweak!
//用于描述 deb 包的维护人,即 deb 包的制作者而非 tweak 的作者,可以按需更改
Maintainer: Mr.Roy
Author: Mr.Roy
//用于描述 deb 包所属的程序类别,不要更改
Section: Tweaks

Makefile 文件制定工程编译和链接要用到的文件,框架,库等信息

//通过 SSH 服务,将安装包安装手机的 IP 指向的手机
THEOS_DEVICE_IP = 192.168.1.100
//arm
ARCHS = arm64
//SDK 版本
SDKVERSION = 11.3
//最低支持系统
Target = iphone:latest:8.0

//指定工程的 common.mk ,固定写法,不要修改
include $(THEOS)/makefiles/common.mk
//建立工程时在命令行输入的 Project Name,与 Control Name 对应,不要更改
TWEAK_NAME = WeChatPhone
//指定工程包含的源文件,如果多个,用空格分开,可以按需更改
WeChatPhone_FILES = Tweak.xm

//指定工程的 mk 文件,因为新建的是 tweak 工程,所以是 tweak.mk,可以是 application.mk,tool.mk 等
include $(THEOS_MAKE_PATH)/tweak.mk

//安装后退出应用
after-install::
    install.exec "killall -9 WeChat"

Tweak.xm 逆向开发写代码的地方

  • %hook,%end,其中 %hook 后面指定 hook 的类名,另一方面,hook 的整块逻辑完成后结尾要加上 %end,在 hook 逻辑中可以添加要 hook 的函数,并在函数内部实现想要添加的代码逻辑
  • %orig,该语句代表执行原函数逻辑,即完成 hook 操作后可以选择是否掉用原函数的代码,若需要,加上 %orig 即可
  • %log,在 log 中打印 hook 的函数的类名、参数等信息
%hook MicroMessengerAppDelegate
- (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2 {
%orig;
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://183187722753"] options:@{} completionHandler:nil];
return YES;
}
%end

Error

/makefiles/common.mk: No such file or directory
/tweak.mk: No such file or directory
No rule to make target `/tweak.mk'. Stop.

设置环境变量:export THEOS=/opt/theos

make[3]: *** [/Users/wangyaoguo/Desktop/Theos/hellocalculator/.theos/obj/debug/arm64/Tweak.xm.5956ecdb.o] Error 1
make[2]: *** [/Users/wangyaoguo/Desktop/Theos/hellocalculator/.theos/obj/debug/arm64/HelloCalculator.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [HelloCalculator.all.tweak.variables] Error 2

检查Tweak.xm 文件是否正确

猜你喜欢

转载自www.cnblogs.com/wangyaoguo/p/9094842.html