iOS逆向工具-Theos

1,192 阅读2分钟

阅读此文前,请确保iOS设备已越狱,否则一切都是空谈!

1.环境安装

a.指定xcode(根据自己xcode路径来):

sudo xcode-select -s/Applications/Xcode.app/Contents/Developer

b.下载Theos(export很重要):

export THEOS=/opt/theos sudo git clone git://github.com/theos/theos.git $THEOS

c.下载ldid : http://joedj.net/ldid 然后复制到/opt/theos/bin 然后sudo chmod 777 /opt/theos/bin/ldid

d.配置CydiaSubstrate:

注意
新版本Theos请直接跳过 运行Theos自动化配置脚本 直接使用iFunBox提取CydiaSubstrate

用iFunBox等iPhone上的工具,将iOS上/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate拷贝到电脑上 然后改名为libsubstrate.dylib , 然后拷贝到/opt/theos/lib 中.

e.配置dkpg

deb 是越狱开发安装包的标准格式,而 dpkg-deb 是操作 deb 文件的工具,有了这个工具,Theos 才能将工程正确地打包成 deb 包。
从[下载](https://raw.githubusercontent.com/DHowett/dm.pl/master/dm.pl)下载dm.pl,将其重命名为 dpkg-deb 后(如果后缀名还是.pl,显示简介中可以修改),
放到 “/opt/theos/bin/“ 目录下,然后设置它的可执行权限:

sudo chmod 777 /opt/theos/bin/dpkg-deb

其实,Theos 已经是一个 tweak 的开发环境了,但是由于这里只是因为需要编译 tweak 而用到它,所以它的很多后续配置也没有详细讲解了。

至此,我们的安装环境就搭建完了,下一步可以正式地开始安装 tweak 了。

2.Theos用法

输入
/opt/theos/bin/nic.pl 
NIC 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_service
Choose a Template (required):

选择  [11.] iphone/tweak

Choose a Template (required): 11
Project Name (required): iOSREProject
Package Name [com.yourcompany.iosreproject]: com.yuhao.iosreproject
Author/Maintainer Name [yuhao]: sthyuhao
[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 iosreproject/...
Done.

第一个相当于工程文件夹的名字
第二个相当于bundle id
第三个就是作者
第四个是作用对象的bundle identifier
第五个是要重启的应用

完成这几步之后,一个iosreproject文件夹就在当前目录生成了,该文件夹就是刚创建的tweak工程。

编写Tweak

%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome"message:@"Welcome to your iPhone!"delegate:nilcancelButtonTitle:@"Thanks"otherButtonTitles:nil];
[alert show];
[alert release];
%orig;
}
%end

为什么要release 因为Tweak默认编码方式是MRC 如果需要ARC的话 在MakeFile中插入TweakName_CFLAGS = -fobjc-arc

在Tweak注入之前需要先在终端执行

export THEOS=/opt/theos/
export THEOS_DEVICE_IP=xxx.xxx.xxx.xxx(手机的ip地址)

3.构建工程

make package install

过程会让你输入两次iphoen密码 , 默认是alpine