一、确定目标APP
找个目标APP,确定HOOK的点,笔者找了某APP的注册按钮,要制作一个简单的破坏注册的插件。

二、分析准备
通过USB实现ssh登录,拿到手机的root权限,使用cycript调试APP,命令:cycript -p zhsApp
,使用自己封装的psy.cy(@import com.Panshuyan.psy
),查看APPID(得到com.shikee.zhsApp
),获取当前控制器:PSYCurrentVC()
;在importy一个cycript的md,如下图:
#"<MineViewController: 0x10283f000>"

三、静态分析
手机进入要HOOK的按钮的界面,终端cy#
输入:pviews()
,首先从字面入手,找到“注册买家账号”这几个字,因为pviews
打印出的都是编码的,我们可以进入python
环境获得“注册买家账号”这几个字的编码(python3
支持中文输出,所以使用Mac自带的Python2.7.10
)'\xe6\xb3\xa8\xe5\x86\x8c\xe4\xb9\xb0\xe5\xae\xb6\xe8\xb4\xa6\xe5\x8f\xb7'
然后回来搜一下,可以得到可能按钮的内存地址UIButton: 0x101c65080


我们说了,我们得到按钮的内存地址只是可能的,为了严谨性,我们验证一下,直接通过
#0x101c65080.backgroundColor=[UIColor blackColor]
和#0x101c65080.backgroundColor=[UIColor redColor]
修改按钮的颜色验证一下我们的猜测,很明显是对的。
![]() |
![]() |
---|
此时可以开始分析了,通过#0x101c65080.allTargets
拿到内存的所有响应者,可以发现只有一个,我们可以通过rp(#0x101c65080)
查看整条响应链验证LoginGuideBtnCell: 0x102814a00
也在整条响应链当中。然后在查一下事件类型#0x101c65080.allControlEvents
,64代表的是26,位运算1<<6,对应的是:UIControlEventTouchUpInside
,最后通过[#0x101c65080 actionsForTarget:#0x102814a00 forControlEvent:64]
拿到对应按钮的方法名("regBtnAction:"
)。



为了进一步验证我们可以对该APP砸壳拿到所有头文件,如下:
砸壳:dump.py MachO
导出头文件:class-dump -H MachO -o ./MachOHeaders
搜索LoginGuideBtnCell
,查看该头中是否有regBtnAction:
方法,以及返回值类型,一切都指向我们的分析是正确的。

四、编写插件
通过nic.pl
开始选择生成插件工程,选择第15个tmplate
--> iphone/tweak
--> 工程名
--> 包名
(包名全部使用小写,否侧打包的时候出现问题,可以看其给出的建议示例)--> 作者
--> 插件针对的APP的bundle id
--> 安装后重启SpringBoard
还是只重启对应的APP(默认是重启SpringBoard
)。此时在对应的目录下生成了一个插件工程。


在MakeFIle中最前面添加,意思是通过设备的IP和端口,笔者这里通过USB的localhost和端口2222。
export THEOS_DEVICE_IP=localhost
export THEOS_DEVICE_PORT=2222
(优化:因为每次写插件都要写这两句,那我就把这两句写到.zshrc里面,这里和以后就不用每次都要写了,一劳永逸)

然后开始使用Logos语法,并根据我们上面的分析,在Tweak.x中编写HOOK代码如下:
#import <UIKit/UIKit.h>
%hook LoginGuideBtnCell
- (void)regBtnAction:(id)btn
{
NSLog(@"\n\n\n🍺🍺停一下喝一杯酒先别注册了🍺🍺\n\n\n\n");
}
%end
完成后保存,使用make指令编译工程,注意工程的路径不要包含空格,否则make的时候出现如下错误:最好也不要包含中文,因为有些情况下也会包错。然后剩下的就是make(编译)
-->make package(打包)
--> make install(安装)
,等待SpringBoard
重启。
Your project is located at “/Volumes/500g/sbiuab/bxsiai sbuas/ussn/zhsappdemo”, which contains spaces. Spaces are not supported in the project path. Stop.


此时我们的越狱设备上打开Cydia,找到已安装,发现我们的插件已经安装到设备上了,我们迫不及待的打开目标APP,找到对应的界面,点击我们HOOK的按钮,可在控制台看到进程我们NSLog的东西了。


网友评论