您的位置:首页 > 移动开发 > IOS开发

ios逆向学习过程——使用theos创建第一个tweak

2019-06-08 16:54 2695 查看

使用Theos创建、编译、安装tweak

1.使用theos目录下的nic.pl创建工程

$

theos/bin/nic.pl

选择 [10.] iphone/tweak ,按照提示填入内容:
Project Name :工程名
Package Name :包名,类似于bundle identifier,命名规则一般倒着写,如com.xxhook.firsttweak
Author/Maintainer Name:作者名
MobileSubstrate Bundle filte :tweak作用的对象的bundle identifier,如com.apple.springboard
List of applications to terminate upon installation :tweak安装完成后需要重启的应用,以进程名表示,如SpringBoard

LongdeMac-mini:~ long$ theos/bin/nic.pl
NIC 2.0 - New Instance Creator
------------------------------
[1.] iphone/activator_event
[2.] iphone/application_modern
[3.] iphone/application_swift
[4.] iphone/flipswitch_switch
[5.] iphone/framework
[6.] iphone/library
[7.] iphone/preference_bundle_modern
[8.] iphone/tool
[9.] iphone/tool_swift
[10.] iphone/tweak
[11.] iphone/xpc_service
Choose a Template (required): 10
Project Name (required): FirstTweak
Package Name [com.yourcompany.firsttweak]: com.xxhook.firsttweak
Author/Maintainer Name [Long]: longzei
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]:com.apple.springboard
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: SpringBoard
Instantiating iphone/tweak in firsttweak/...
Done.
LongdeMac-mini:~ long$

2.各文件讲解:

(1)Makefile文件指定工程用到的文件、框架、库等信息,将整个过程自动化。修改其中内容:
指定处理器架构,添加:ARCHS=armv7 arm64
指定SDK版本:TARGET = iphone:latest:12.0 //该语句指定以Xcode附带的最新版本SDK编译,发布对象为ios12.0及以上版本。
(2)Tweak.xm。hook内容的主要文件。
%hook 指定需要hook的class,以%hook开头,以%end结尾(注意是百分号%)。
%log 该语句在%hook内部使用,可以将函数的类名、参数等信息写入syslog,可以以 %log([(),…]) 的格式追加打印其他信息
%orig 该语句在%hook内部使用,执行原函数中的原始代码(若无%orig 则原函数的原始代码不执行)。如下

%hook SpringBoard
- (void)_menuButtonDown:(id)down
{
%log((NSString*)@"iOSRE",(NSString*)@"Debug");
%orig;
}
%end

3.编译

make

注1:若未配置sdk环境,会提示以下错误
==> Error: You do not have any SDKs in /Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/SDKs or /Users/long/theos/sdks

解决办法:

sudo xcode-select --switch /Applications/Xcode.app

注2:在文本编辑器中编辑文件,有可能因为字符格式与Xcode中的不一致导致错误。不要再使用文本编辑器编辑。
error: nonASCII characters are not allowed outside of literals and identifiers

4.打包

make package

编译后打包,打包后生成后缀名为deb的安装包

5.安装

make install

将该安装包,安装到相应的越狱设备。若之前没在Makefile中添加指定设备ip,则重新修改Makefile文件,添加

THEOS_DEVICE_IP = xxx.xxx.xxx.xxx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: