iOS逆向开发-theos安装配置使用简单说明

iOS逆向开发-脱壳工具dumpdecrypted与frida-ios-dump的安装与使用

导语:上一篇说的是脱壳工具,今天说的是theos,因为安装这个也废了很多脑细胞,clone了N加1遍,都是失败的。记录一下怎么解决的,希望有兴趣学习逆向的朋友们看了这篇文章可以少掉坑。

安装

简单梳理一下步骤:

  1. brew install ldid
  2. 设置环境变量

命令 open ~/.zprofile ,把这两句放到.profile文件后面

export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
复制代码

关闭.profile文件,命令 source ~/.zprofile

  • 环境变量配置说明:
  1. 我在网上看到的资料是把环境变量放在.bash_profile文件,我也试过,发现一个问题,如果终端使用zsh加载,放在.bash_profile每次在打开终端都要source ~/.bash_profile环境变量才生效。查了资料,把source ~/.bash_profile命令,放在~/.zshrc文件后面,可以解决这个问题。(或者设置bash加载)
  1. 不直接使用命令设置环境变量,是因为使用命令echo "export PATH=$THEOS/bin:$PATH" >> ~/.zprofile,在.zprofile文件里路径直接展开了,感觉不是很好,所以手动写入。
  1. 如果按官方方法clone失败,直接下载theos的zip压缩包,解压放到~/theos路径。

  2. 手动clone依赖包,命令 cd $THEOS/vendor

git clone git://github.com/theos/dm.pl.git
git clone git://github.com/theos/headers.git/   //clone完成需要将headers改成include,其他的依赖直接用默认名称就可以
git clone git://github.com/theos/lib.git
git clone git://github.com/theos/logos.git
git clone git://github.com/theos/nic.git
git clone git://github.com/theos/templates.git
复制代码
  1. 直接下载sdks ==>传送门,解压放到theos的sdks文件夹中。

  2. 终端命令 nic.pl,如果安装成功直接可以创建项目。

创建项目

  1. cd 到你需要创建项目的目录中
  2. 命令 nic.pl
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/activator_listener
  [3.] iphone/application_modern
  [4.] iphone/application_swift
  [5.] iphone/cydget
  [6.] iphone/flipswitch_switch
  [7.] iphone/framework
  [8.] iphone/library
  [9.] iphone/notification_center_widget
  [10.] iphone/notification_center_widget-7up
  [11.] iphone/preference_bundle_modern
  [12.] iphone/theme
  [13.] iphone/tool
  [14.] iphone/tool_swift
  [15.] iphone/tweak
  [16.] iphone/tweak_with_simple_preferences
  [17.] iphone/xpc_service
Choose a Template (required): 15 -->如果是hook,直接填写 15
Project Name (required): xxx --->项目名随便填
Package Name [com.yourcompany.xxx]: yourcompany.xxx --->随便填
Author/Maintainer Name [FRZeng]: nnn --->随便填
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: bundle ID --->需要hook什么App,就填写该App的bundle ID
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: --->直接跳过
Instantiating iphone/tweak in xxx/...
Done. --->项目创建完成
复制代码

使用

  1. 把整个项目拖进 Sublime Text

  2. 配置Makefile

添加 THEOS_DEVICE_IP 和 THEOS_DEVICE_PORT

export THEOS_DEVICE_IP = localhost  //配置IP
export THEOS_DEVICE_PORT = 10010 //端口

TARGET := iphone:clang:latest:7.0
INSTALL_TARGET_PROCESSES = SpringBoard


include $(THEOS)/makefiles/common.mk

TWEAK_NAME = xxx

xxx_FILES = Tweak.x
xxx_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/tweak.mk
复制代码
  1. 配置完成,在Tweak.x文件写代码。
%hook XMLiveOrListenTogetherView //引用需要hook的App里的头文件

//拦截方法
- (id)init{
	return nil;
}

%end 

复制代码
  1. 代码完成后,终端cd 到theos项目文件夹(保持手机与电脑的连接)
  1. 命令 make
  2. 命令 make package
  3. 命令 make install
frzeng@192 tingTweak % make  <========
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building
> Making all for tweak tingTweak…
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (armv7)…
==> Linking tweak tingTweak (armv7)…
ld: warning: building for iOS, but linking in .tbd file (/Users/frzeng/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for tingTweak…
rm /Users/frzeng/Desktop/nixiangCode/tingTweak/.theos/obj/debug/armv7/Tweak.x.m
==> Preprocessing Tweak.x…
==> Compiling Tweak.x (arm64)…
==> Linking tweak tingTweak (arm64)…
ld: warning: building for iOS, but linking in .tbd file (/Users/frzeng/theos/vendor/lib/CydiaSubstrate.framework/CydiaSubstrate.tbd) built for iOS Simulator
==> Generating debug symbols for tingTweak…
rm /Users/frzeng/Desktop/nixiangCode/tingTweak/.theos/obj/debug/arm64/Tweak.x.m
==> Merging tweak tingTweak…
==> Signing tingTweak… <<<<<<<==============
frzeng@192 tingTweak % make package  <========
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: https://github.com/theos/theos/wiki/Parallel-Building
> Making all for tweak tingTweak…
make[2]: Nothing to be done for `internal-library-compile'.
> Making stage for tweak tingTweak…
dm.pl: building package `com.gemd.iting:iphoneos-arm' in `./packages/com.gemd.iting_0.0.1-1+debug_iphoneos-arm.deb' <<<<<<<==============
frzeng@192 tingTweak % make install  <========
==> Installing…
(Reading database ... 5368 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.gemd.iting (0.0.1-1+debug) over (0.0.1-1+debug) ...
Setting up com.gemd.iting (0.0.1-1+debug) ...
==> Unloading SpringBoard…  <<<<<<<==============
frzeng@192 tingTweak %
复制代码

<<<<<<<============== 指向每个命令最后一步,都没有问题,hook成功。

删除插件

如果需要删除hook在手机的插件

在手机 Library/MobileSubstrate/DynamicLibraries/中查找

有两个文件: 一个plist文件,一个dylib文件 直接删除

》》》至于theos的开发,我也是个小白,如果有朋友一起学习逆向的,欢迎一起交流。

猜你喜欢

转载自juejin.im/post/6961975578631241765