Theos制作越狱插件

目的:给微信的设置页面添加一个按钮,点击弹出alert

Theos制作越狱插件_第1张图片
效果图

hook前先分析一下

进行hook之前需要先对目标app进行分析,找到注入点。我们要对设置页面进行hook,就需要先知道这个页面的代码是在哪里实现的,可以使用cycript进行动态的分析。

  1. 打开微信,进入到设置页面
  2. 通过ssh 连接到设备
  3. 用命令ps -e ,显示当前运行的所有进程
  4. 找到微信进程 ../WeChat.app/WeChat,在该行的最前面会有进程序列号
    Theos制作越狱插件_第2张图片
    微信进程
  5. 用命令cycript -p 进程序列号,进入cy#状态
  6. UIApp.keyWindow.recursiveDescription().toString() 显示设置页面的视图层级关系。找到MMTableView这个应该就是页面的TableView视图,复制一下对象的地址0x148108000
    Theos制作越狱插件_第3张图片
    视图层级关系
  7. 输入[#0x148108000 nextResponder],会得到一个View的信息,记录下view的地址,在执行[#0x148ac6060 nextResponder],得到了#"",看来NewSettingViewController就是实现设置页面的类了。

找到了目标文件,需要做的就是在NewSettingViewController执行viewDidLoad的时候,把右上角添加一个按钮就可以了,接下来就开始制作插件了。如果需要hook其他的方法可以先把app砸壳之后,用class-dump导出所有的的头文件,再选择需要hook的方法。


1、 Theos创建 tweak项目

Theos 一般都是在/opt/目录下,所以执行下面的命令创建一个Template

/opt/theos/bin/nic.pl

出现Template选择页面,输入5,选择iphone/tweak

NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/application
  [2.] iphone/library
  [3.] iphone/preference_bundle
  [4.] iphone/tool
  [5.] iphone/tweak
Choose a Template (required): 5
Project Name (required): Hook
Package Name [com.yourcompany.hook]: com.Hook.hook
Author/Maintainer Name []: name
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.tencent.xin /*app的bundle id*/
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: WeChat  /*程序进程中的名字,当tweak安装成功之后,需要kill掉WeChat*/
Instantiating iphone/tweak in hook/...
Done.

完整信息的填写之后,会生成以下的几个文件,可以大致看一没个文件的内容,里面的信息就是生成tweak项目时要填写的内容,接下里需要关注的就是Tweak.xmMakefile,会对其内容进行编辑

Theos制作越狱插件_第4张图片

2、修改Makefile

修改完之后像这样,就是一些配置信息

# 设备IP
THEOS_DEVICE_IP=10.1.15.238  
ARCHS = arm64
SDKVERSION=9.3
TARGET = iphone:latest:10.0

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = hook
hook_FILES = Tweak.xm

# 需要用到的框架
hook_FRAMEWORKS = UIKit Foundation 

# 指定生成动态库的版本
hook_LDFLAGS += -current_version 1.0 
hook_LDFLAGS += -compatibility_version 1.0

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
    install.exec "killall -9 WeChat"

3、制作Tweak.xm


%hook NewSettingViewController /* 对NewSettingViewController进行hook*/
- (void)viewDidLoad {
 %orig; /*执行原来的代码*/
 [[self navigationItem] setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"已关闭" style:UIBarButtonItemStylePlain target:self action:@selector(switchAuto:)]];
}

%new  /*添加新方法*/
- (void)switchAuto:(UIBarButtonItem *)barItem {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"自动抢红包设置" message:@"请设置延迟时间" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *openAutoAction = [UIAlertAction actionWithTitle:@"开启自动抢红包" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *closeAutoAction = [UIAlertAction actionWithTitle:@"关闭自动抢红包" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:openAutoAction];
    [alert addAction:closeAutoAction];
    [alert addAction:cancleAction];
    [self presentViewController:alert animated:YES completion:^{
    }];
}
%end /*结束标示*/

4、制作安装插件

配置一下环境变量

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

打包安装插件

make package install

中间会让输入两次密码,就是你ssh 的密码。如果没有改的话默认是:apline。
成功之后在Cydia就会出现安装的插件。打开微信在设置页面的右上角就会出现一个按钮了。


最后

但是现在只有一个插件,只能在越狱的设备上进行安装,如果需要安装在非越狱设备上,就需要进行注入动态库了。注入需要用到yololib,这个是源码需要自己编译。

./yololib [binary] [dylib file]
./yololib [被插入dylib的二进制文件] [要插入的dylib]

注入成功之后进行打包签名就可以了。

你可能感兴趣的:(Theos制作越狱插件)