== theos(作者:@DHowett) ==
越狱开发工具, 也可以为非越狱设备开发插件
- 设置xcode工具集路径
查看命令:xcode-select --print-path
选择xcode命令电脑上只安装了一个xcode,打印出一个路径 /Applications/Xcode.app/Contents/Developer
sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer
- theos安装
- 查看theos教程
- 安装theos在opt目录(网上大多数安装目录,便于资料查找)
创建/opt目录:sudo mkdir opt
进入到opt目录:cd opt
git安装命令:$ sudo git clone --recursive https://github.com/theos/theos.git
修改所有者权限
修改权限命令:$ sudo chown -R $(id -u):$(id -g) theos
-
设置环境变量(默认搜索路径的指定)
手动设置环境变量(每次启动,都要写一遍来指定路径) export THEOS=/opt/theos 查看环境变量 echo $THEOS /opt/theos 写入:~/.bash_profile 避免每次都指定路径 1、打开文件:命令:vim ~/.bash_profile 2、敲 i 插入 3、将export THEOS=/opt/theos复制进去 4、esc ==> :wq 保存退出 5、执行命令:source ~/.bash_profile 生效
== 创建逆向程序 ==
前面的准备工作都做好后,开始创建我们的逆向程序
1、开启我们的theos:$/opt/theos/bin/nic.pl
2、选择你要创建的工程类型:11
3、填写项目信息
//选择tweak工程
Choose a Template (required): 11
//工程名称
Project Name (required): MyFirstReProject
//deb包的名字(类似于bundle identifier)
Package Name [com.yourcompany.myfirstreproject]: com.iosre.myfirstreproject
//tweak作者
Author/Maintainer Name [System Administrator]: luz
//tweak作用对象的bundle identifier
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.springboard
//tweak安装完成后需要重启的应用,这里填写应用运行时的名称
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: SpringBoard
创建完成结果:
Instantiating iphone/tweak in myfirstreproject/...
Done.
== 工程文件结构介绍 ==
项目创建完后,会得到如下文件:
- Makefile
//工程包含的通用头文件
include $(THEOS)/makefiles/common.mk
//创建工程时指定的“Project Name,指定好之后一般不要再更改
TWEAK_NAME = yochifirstProject
//tweak包含的源文件,指定多个文件时用空格隔开
yochifirstProject_FILES = Tweak.xm
//tweak工程的头文件,一般有application.mk、tweak.mk和tool.mk几类
include $(THEOS_MAKE_PATH)/tweak.mk
//指定tweak安装之后,需要做的事情,这里是杀掉SpringBoard进程
after-install::
install.exec "killall -9 springBarod"
补充:
//编译debug或者release
DEBUG = 0
//越狱iPhone的ip地址,打包时,可以自动安装到iPhone
THEOS_DEVICE_IP = 192.168.1.2
//指定支持的处理器架构
ARCHS = armv7 arm64
//指定需要的SDK版本iphone:Base SDK:Deployment Target
TARGET = iphone:latest:8.0 //最新的SDK,程序发布在iOS8.0以上
//导入框架,多个框架时用空格隔开
yochifirstProject_FRAMEWORKS = UIKit
// 私有框架
yochifirstProject_PRIVATE_FRAMEWORKS = AppSupport
//链接libsqlite3.0.dylib、libz.dylib和dylib1.o
yochifirstProject_LDFLAGS = -lz –lsqlite3.0 –dylib1.o
//make clean
clean::
rm -rf ./packages/*
- Tweak.xm
“xm”中的“x”代表这个文件支持Logos语法,如果后缀名是单独一个“x”,说明源文件支持Logos和C语法;如果后缀名是“xm”
,说明源文件支持Logos和C/C++语法。
Tweak.xm自动生成的内容:
/* How to Hook with Logos
Hooks are written with syntax similar to that of an Objective-C @implementation.
You don't need to #include <substrate.h>, it will be done automatically, as will
the generation of a class list and an automatic constructor.
%hook ClassName
// Hooking a class method
+ (id)sharedInstance {
return %orig;
}
// Hooking an instance method with an argument.
- (void)messageName:(int)argument {
%log; // Write a message about this call, including its class, name and arguments, to the system log.
%orig; // Call through to the original function with its original arguments.
%orig(nil); // Call through to the original function with a custom argument.
// If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
}
// Hooking an instance method with no arguments.
- (id)noArguments {
%log;
id awesome = %orig;
[awesome doSomethingElse];
return awesome;
}
// Always make sure you clean up after yourself; Not doing so could have grave consequences!
%end
*/
== %hook 指定需要hook的class,必须以%end结尾
==%log 该指令在%hook内部使用,将函数的类名、参数等信息写入syslog
==Cydia内搜索安装syslogd可以查看系统日志
==%orig该指令在%hook内部使用,执行被钩住(hook)的函数的原始代码。
- control文件
control文件记录了deb包管理系统所需的基本信息,会被打包进deb包里。
Package: com.yochi.firstProject
Name: yochifirstProject
Depends: mobilesubstrate
Version: 0.0.1
Architecture: iphoneos-arm
Description: An awesome MobileSubstrate tweak!
Maintainer: Yochi
Author: Yochi
Section: Tweaks
- projectName.plist
表示tweak工程作用的对象
查看plist文件系统:plutil -p yochifirstProject.plist
== 编译工程得到安装包 ==
要运行工程,我们首先得写上需要hook的功能代码
打开Tweak.xm文件,删除里面的代码,可以使用sublime工具打开
写上我们hook的代码,使用logos语法
-
hook按下home键的方法
%hook SpringBoard - (void)_menuButtonDown:(id)arg1 { NSLog(@"x=%d,y=%d", 10,20); %log((NSString *)@"iosre",(NSString *)@"hello,Yochi") %orig; } %end
make 对工程进行编译
make package 打包
查看工程目录会多个packages文件夹,这里就是放的我们刚才编译好的deb安装包make install 安装