一、使用Xcode创建自己的一个用于测试的App。
拦截一个按钮的点击方法: - (void)buttonClick { UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@'提示' message:@'未被HOOK' preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@'取消' style:UIAlertActionStyleCancel handler:nil]; [alerView addAction:cancelAction]; [self presentViewController:alerView animated:YES completion:nil];} 二、下载和配置theos大家可自己手动下载官方theos然后放入ldid、CydiaSubstrate、dpkg-deb等等到目录中,或者使用脚本下载我这边已经放入好的theos。 三、创建theos项目1,首先我们配置和准备好theos后,我们进入终端,然后cd进入你要放工程的文件夹目录比如桌面上我新建好的一个文件夹iosDev,然后执行启动 NIC(New Instance Creator),如下:。 zhangdasendeMacBook-Pro:iOS Dev zhangdasen$ cd /Users/zhangdasen/Desktop/iOSDevzhangdasendeMacBook-Pro:iOSDev zhangdasen$ /opt/theos/bin/nic.plNIC 2.0 - New Instance Creator------------------------------ [1.] iphone/activator_event [2.] iphone/application_modern [3.] iphone/cydget [4.] iphone/flipswitch_switch [5.] iphone/framework [6.] iphone/ios7_notification_center_widget [7.] iphone/library [8.] iphone/notification_center_widget [9.] iphone/preference_bundle_modern [10.] iphone/tool [11.] iphone/tweak [12.] iphone/xpc_serviceChoose a Template (required): 我们可以看到
THEOS_DEVICE_IP = 10.10.243.124 ARCHS = armv7 arm64TARGET = iphone:latest:8.0include $(THEOS)/makefiles/common.mkTWEAK_NAME = HOOKAPPHOOKAPP_FILES = Tweak.xmHOOKAPP_FRAMEWORKS = UIKitinclude $(THEOS_MAKE_PATH)/tweak.mkafter-install:: install.exec 'killall -9 SpringBoard' 2, Tweak.xm %hook ViewController- (void)buttonClick{ UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@'提示' message:@'已经被HOOK了' preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@'取消' style:UIAlertActionStyleCancel handler:nil]; [alerView addAction:cancelAction]; [self presentViewController:alerView animated:YES completion:nil];}%end 其它这两个文件 control 和 iosproject.plist 可以保持原样。 三、打包并安装dylib到设备中.
1,这个时候我们差不多都配置好了,可以把自己写的APP,然后运行到设备上了,运行之后点击测试下未HOOK之前的按钮点击方法:
sudo git clone https://github.com/theos/headers /opt/theos/include 或者重新更新下我上传的theos git pull 一下,
(由于上传图片大小限制5M,我分了两个GIF来演示,下面演示HOOK成功后)
下面进行一一说明 四、基本原理说明1,Cydia Substrate 和 Mobile Substrate * Cydia Substrate 原名为 Mobile Substrate 已经正式更名为 Cydia Substrate。* 它是越狱后cydia插件/软件运行的一个基础依赖包。提供软件运行的公共库,可以用来动态替换 内存中的代码、数据等所以iOS系统越狱环境下安装绝大部分插件,必须首先安装Cydia Substrate。* Cydia Substrate主要由3部分组成:MobileHooker,MobileLoader 和 safe mode。 2,MobileHooker、Logos * MobileHooker用于替换覆盖系统的方法,这个过程被称为Hooking(挂钩)* 它主要包含两个函数:void MSHookMessageEx(Class class, SEL selector, IMP replacement, IMP *result);void MSHookFunction(void*function,void* replacement,void** p_original);MSHookMessageEx 主要作用于Objective-C函数MSHookFunction 主要作用于C和C++函数Logos语法就是对此函数做了一层封装,让编写hook代码变的更直观,上面的例子用的就是logos语法。MSHookMessageEx 和MSHookFunction 使用方法这里就不介绍了,大家可去看书籍或者查询相关资料。 3,MobileLoader * MobileLoader用于加载第三方dylib在运行的应用程序中。* 启动时MobileLoader会根据dylib的同名plist文件指定的作用范围,有选择的在不同进程里通过dlopen函数打开目录/Library/MobileSubstrate/DynamicLibraries/ 下的所有dylib。 4,safe mode * 因为APP程序质量参差不齐崩溃再所难免,tweak本质是dylib,寄生在别人进程里,如果注入Springboard等。 系统进程一旦出错,可能导致整个进程崩溃,崩溃后就会造成iOS瘫痪。* 所以CydiaSubstrate引入了安全模式,在安全模 式下所有基于CydiaSubstratede 的三方dylib都会被禁用,便于查错与修复。* 本人建议自己测试的时候如果HOOK Springboard的时候一定要注意!如果出错,进入安全模式删除插件即可。 总结: 下面我们可以来验证一下,我用PP助手连接pad, 进入 然后看下HOOKAPP.plist文件:
待续。。。。。。
著作权归作者所有
|
|