== theos(作者:@DHowett) ==
越獄開發(fā)工具, 也可以為非越獄設(shè)備開發(fā)插件
- 設(shè)置xcode工具集路徑
查看命令:xcode-select --print-path
選擇xcode命令電腦上只安裝了一個(gè)xcode,打印出一個(gè)路徑 /Applications/Xcode.app/Contents/Developersudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer - theos安裝
- 查看theos教程
- 安裝theos在opt目錄(網(wǎng)上大多數(shù)安裝目錄,便于資料查找)
創(chuàng)建/opt目錄:sudo mkdir opt
進(jìn)入到opt目錄:cd opt
git安裝命令:$ sudo git clone --recursive https://github.com/theos/theos.git
修改所有者權(quán)限
修改權(quán)限命令:$ sudo chown -R $(id -u):$(id -g) theos-
設(shè)置環(huán)境變量(默認(rèn)搜索路徑的指定)
手動(dòng)設(shè)置環(huán)境變量(每次啟動(dòng),都要寫一遍來指定路徑) export THEOS=/opt/theos 查看環(huán)境變量 echo $THEOS /opt/theos 寫入:~/.bash_profile 避免每次都指定路徑 1、打開文件:命令:vim ~/.bash_profile 2、敲 i 插入 3、將export THEOS=/opt/theos復(fù)制進(jìn)去 4、esc ==> :wq 保存退出 5、執(zhí)行命令:source ~/.bash_profile 生效
== 創(chuàng)建逆向程序 ==
前面的準(zhǔn)備工作都做好后,開始創(chuàng)建我們的逆向程序
1、開啟我們的theos:$/opt/theos/bin/nic.pl

image.png
2、選擇你要?jiǎng)?chuàng)建的工程類型:11
3、填寫項(xiàng)目信息
//選擇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作用對(duì)象的bundle identifier
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.apple.springboard
//tweak安裝完成后需要重啟的應(yīng)用,這里填寫應(yīng)用運(yùn)行時(shí)的名稱
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: SpringBoard
創(chuàng)建完成結(jié)果:
Instantiating iphone/tweak in myfirstreproject/...
Done.
== 工程文件結(jié)構(gòu)介紹 ==
項(xiàng)目創(chuàng)建完后,會(huì)得到如下文件:

- Makefile
//工程包含的通用頭文件
include $(THEOS)/makefiles/common.mk
//創(chuàng)建工程時(shí)指定的“Project Name,指定好之后一般不要再更改
TWEAK_NAME = yochifirstProject
//tweak包含的源文件,指定多個(gè)文件時(shí)用空格隔開
yochifirstProject_FILES = Tweak.xm
//tweak工程的頭文件,一般有application.mk、tweak.mk和tool.mk幾類
include $(THEOS_MAKE_PATH)/tweak.mk
//指定tweak安裝之后,需要做的事情,這里是殺掉SpringBoard進(jìn)程
after-install::
install.exec "killall -9 springBarod"
補(bǔ)充:
//編譯debug或者release
DEBUG = 0
//越獄iPhone的ip地址,打包時(shí),可以自動(dòng)安裝到iPhone
THEOS_DEVICE_IP = 192.168.1.2
//指定支持的處理器架構(gòu)
ARCHS = armv7 arm64
//指定需要的SDK版本iphone:Base SDK:Deployment Target
TARGET = iphone:latest:8.0 //最新的SDK,程序發(fā)布在iOS8.0以上
//導(dǎo)入框架,多個(gè)框架時(shí)用空格隔開
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”代表這個(gè)文件支持Logos語法,如果后綴名是單獨(dú)一個(gè)“x”,說明源文件支持Logos和C語法;如果后綴名是“xm”
,說明源文件支持Logos和C/C++語法。
Tweak.xm自動(dòng)生成的內(nèi)容:
/* 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結(jié)尾
==%log 該指令在%hook內(nèi)部使用,將函數(shù)的類名、參數(shù)等信息寫入syslog
==Cydia內(nèi)搜索安裝syslogd可以查看系統(tǒng)日志
==%orig該指令在%hook內(nèi)部使用,執(zhí)行被鉤?。╤ook)的函數(shù)的原始代碼。
- control文件
control文件記錄了deb包管理系統(tǒng)所需的基本信息,會(huì)被打包進(jìn)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工程作用的對(duì)象
查看plist文件系統(tǒng):plutil -p yochifirstProject.plist

== 編譯工程得到安裝包 ==
要運(yùn)行工程,我們首先得寫上需要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 對(duì)工程進(jìn)行編譯
make package 打包
查看工程目錄會(huì)多個(gè)packages文件夾,這里就是放的我們剛才編譯好的deb安裝包make install 安裝