iOS逆向:Tweak 插件类 / 修改原有app功能方向(完结)(2020.11.12更)

0、说到越狱插件开发,一般搜下去 都是 Tweak、Thews 之类的。按我学习的流水记录下。

 

1、终端安装thews(相当于宏定义一个路径为THEOS,把这个git的东西下载到这个宏/路径)

export THEOS=/opt/theos

git clone --recursive https://github.com/theos/theos.git $THEOS

 

2、安装brew(前提是ruby已安装,一般安装过cocoapods,就已经安装过ruby了)

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 注:这个时候,可能下载不下来。可能需要添加hosts

sudo vi /etc/hosts

 然后把这个网址 https://site.ip138.com/raw.Githubusercontent.com/ 解析的IP加进去

# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End

 (注:hosts解析 参考自该文章 https://blog.csdn.net/laoxuan2011/article/details/106177126?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160459280619724838554874%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160459280619724838554874&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_click~default-1-106177126.pc_v1_rank_blog_v1&utm_term=raw.githubusercontent.com&spm=1018.2118.3001.4450 )

 

3、安装ldid(签名用)

brew install ldid

 

4、安装dpkg(打包成deb)

brew install dpkg

 

5 、安装 command line tools(看情况)

https://developer.apple.com/downloads/?=Command%20Line%20Tools%20

 

6、安装 sshpass(应该不需要,先跳过,有需要再看)

brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

基本会报错,

Error: Calling Non-checksummed download of sshpass formula file from an arbitrary URL is disabled! Use brew extract or brew create and brew tap-new to create a formula file in a tap on GitHub instead.

网上的资料,都是 waring ,直接跳过,我的终端却是 error ,安装失败。这个时候可以下载至本地再次执行安装

wget https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
brew install sshpass.rb

注:如果 wget 指令没有的话,还需要先装 wget

brew install wget

 

7、安装 openssh(选装,好像有git的,基本都有装了)

brew install openssl
brew install ssh-copy-id

 

 

 

============================================== 安装 完成 ==============================================

0、开始创建第一个demo

 

1、每次打开终端,都需要对路径进行“宏定义”一次(第二行才是创建)

export THEOS=/opt/theos
$THEOS/bin/nic.pl

2、然后根据返回的列表,输入 iphone/tweal 的序号。

3、然后是 项目名、包名、开发者、监听领域、回车。

注:好像 1)包名不能大写,不然编译有问题。

     2)监听领域:默认 om.apple.springboard ,iOS的桌面app

                  com.apple.UIKit ,作用于所有的app(网上资料这么写的,还没测)

4、这个时候,会在 /Users,生成 项目名的文件夹。(为什么是/Users ? 因为,每次打开终端,都默认 /Users ,除非,自己再 cd )

5、对 .x 或者 .xm 编程(版本不同 后缀不同,一样的)。

  编程内容为 %hook 开机方法,%orig 继续执行原来的代码,相当于[super xxx],最后%end。(听说不%orig会变砖,因为iOS桌面app没法执行下一步,具体没验证。)

#import <SpringBoard/SpringBoard.h>
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application {
    %orig;
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"你好" message:@"欢迎使用" delegate:nil cancelButtonTitle:@"hook成功了" otherButtonTitles:nil];
    [alert show];
}
%end

6、获得手机控制权( SSH),终端输入

ssh root@同一Wi-Fi下的越狱手机ip

再设置/输入密码,一般都是 alpine(可修改),连接成功,光标处就变成 root 。(如输入 reboot ,手机将立即重启,这里只是说ssh root 后的作用,不是要你 reboot 重启手机)

reboot

注:网上资料看到的修改密码指令,是这样的,暂未验证。

passwd root        修改root用户密码
passwd mobile    修改mobile用户密码

6、打开makefile,填入如下( 手机的IP,直接通过wifi下载/烧写,项目的UIAlertView 依赖UIKit库)

export THEOS = /opt/theos
export THEOS_DEVICE_IP = 同一Wi-Fi下越狱手机的ip

项目名_FRAMEWORKS = UIKit



放最后
after-install::
    install.exec "killall -9 SpringBoard"

7-1、编译( 先cd 项目文件夹 )

make

7-2、编译 带 Wi-Fi下载( 先cd 项目文件夹 )

make package install

 

7-3、如果上面有装 openssl、ssh-copy-id ,可以避免输两次密码安装(7-3我没验证,只是看到别人的文档有写,我后面接触了 MonkeyDev )

1、生成文件保存

ssh-keygen -t rsa -b 2048

 2、复制到手机

ssh-copy-id root@同一Wi-Fi下的越狱手机ip

2-1、好像也有这种写法

ssh-copy-id -i /Users/用户名/.ssh/id_rsa root@同一Wi-Fi下的越狱手机ip

ssh-copy-id -i  root@同一Wi-Fi下的越狱手机ip

 

 

============================================== 出现的坑 ==============================================

1、make 编译 失败

==> Error: You do not have any SDKs in /Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/SDKs or /opt/theos/sdks.
make: *** [before-all] Error 1

 解决

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

 

2、即使在 makefile 文件写,库依赖,但是还是make失败。

项目名_FRAMEWORKS = UIKit

解决:在 .xm或 .x 文件引入头文件

#import <UIKit/UIKit.h>

注:可能一些环境配置有问题,导致这个问题的原因没去找,因为后面接触了 MonkeyDev 。

 

3、make package install 下载后,无效果(插件没运行),查了网上一些资料,发现类似的,是下载到根目录了,需要移动到这个位置(可用爱思助手/iFile 手机越狱软件)。

/Library/MobileSubstrate/DynamicLibraries/

注:导致不能成功安装/运行的原因没去找,因为后面接触了 MonkeyDev 。

 


============================================== 参考自 ==============================================

旧:搭旧版本环境麻烦,要从手机拷贝文件,还要去下载ios头文件,但第一个demo比较详细

https://www.jianshu.com/p/b546e26bddb1

新:搭新版本环境 比较快上手

https://www.jianshu.com/p/a5435650e828

 

iOS逆向:Tweak 插件类 / 修改原有app功能方向(完结)(2020.11.12更)

上一篇:凭借这份面经,大专的我成功拿到腾讯Android岗offer


下一篇:vue-vant移动端项目