Theos-tweak工程

1、查看《iOS逆向 开发工具》 Theos的使用方法做准备工作;
2、创建tweak工程,实现在屏幕上添加弹框(越狱手机);
3、Logos语法。
完成该工程,我们可以实现在任意地方添加我们想要的功能。任性,吼吼。

一、给屏幕添加弹框

项目目录:/Users/yanghaibo/Documents/iOS逆向/Theos/

1、创建tweak工程,进入工程目录执行命令:

/opt/theos/bin/nic.pl  

会出现列表:

NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/application_modern
  [3.] iphone/application_swift
  [4.] iphone/cydget
  [5.] iphone/flipswitch_switch
  [6.] iphone/framework
  [7.] iphone/ios7_notification_center_widget
  [8.] iphone/library
  [9.] iphone/notification_center_widget
  [10.] iphone/preference_bundle_modern
  [11.] iphone/tool
  [12.] iphone/tool_swift
  [13.] iphone/tweak
  [14.] iphone/xpc_service
Choose a Template (required):

2、选择13创建一个tweak工程;
3、输入tweak的工程名称 Project Name: first
4、输入deb包的名字,Package Name: com.yahibo.first
5、输入tweak作者的名称,Author: yahibo
6、输入作用对象的bundle identifier: com.apple.springboard
7、安装完成后需要重启应用,以进程名表示 命令:使用空格
项目创建完成如下:

1609369-5f62c7c94865d191.png
create.png

8、修改Tweak.xm文件

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application{
    %orig;
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"我来了,哈哈哈" delegate:nil cancelButtonTitle:@"不见" otherButtonTitles:@"好的", nil];
    [alert show];
}

%end

9、修改Makefile文件,指定设备IP,指定处理器架构,指定SDK版本,导入framework,多个framework 空格添加。

THEOS_DEVICE_IP = 192.168.0.105
ARCHS = armv7 arm64
TARGET = iphone:latest:8.0
    
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = first
first_FILES = Tweak.xm
first_FRAMEWORKS = UIKit

include $(THEOS_MAKE_PATH)/tweak.mk

after-install::
    install.exec "killall -9 SpringBoard"

10、配置完后终端进入工程文件执行安装命令:

make package install

执行如下:

1609369-7f32caf2fa4be2b4.png
install.png

手机端显示如下:

1609369-96e9c0c0dfa4a283.png
iphone.png

以上大功告成,完成了锁屏状态下加弹框。

扫描二维码关注公众号,回复: 6432781 查看本文章

11、工程被打包到:./packages/com.yahibo.first_0.0.1-23+debug_iphoneos-arm.deb中,可使用dpkg 查看deb包信息:

dpkg -I ./packages/com.yahibo.first_0.0.1-23+debug_iphoneos-arm.deb

12、在Cydia应用中搜索 syslogd to/var/log/syslog并安装;搜索Core Utilities并安装,安装后可以使用tail命令查看文件。
13、项目打包成一个.dylib动态库在越狱手机/Library/MobileSubstrate/DynamicLibraries/目录下。

修改内容需要清除包

make clean
rm -rf packages

重启SpringBoard 杀死进程会自动重启

killall -9 SpringBoard

二、常用的Logos语法简介

1、%hook 指定需要hook的类名,以%end结尾。

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application{
    %orig;//执行原始操作
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"我来了,哈哈哈" delegate:nil cancelButtonTitle:@"不见" otherButtonTitles:@"好的", nil];
    [alert show];
}

%end

示例代码为钩住SpringBoard类的applicationDidFinishLaunching函数,先执行原始操作,再显示弹框。

2、%log 用来打印log的,将信息输入到syslog中,格式%log([(<type><expr>,...)])。

%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application{
    %orig;//执行原始操作
    %log((NSString *)@"iOSRE",(NSString *)@"Debug");
}
%end

3、%orig 执行被hook函数的原始代码,类似于super.method功能,如果去掉,原始代码不会执行。还可以使用该函数更改原始函数的参数:

%hook SBLockScreenDateViewController
-(void)setCustomSubtitleText:(id)arg1 withColor:(id)arg2{
    %orig(@"hello I am hibo",arg2);
}
%end

4、%group 该指令用于%hook的分组,%group后边跟的是组名,%group也是必须以%end结尾,其中可以包含多个%hook。

5、%init 该指令用来初始化某个%group,一个group只有被初始化后才可生效,init必须在hook中进行执行。

6、%ctor tweak的构造器,用来初始化,如果不显式定义,Theos就会自动生成一个%ctor,并在其中调用%init(_ungrouped). 如:%ctor { %init(_ungrouped)}。

7、%new 该指令用来给现有的class添加一个新的函数。与Runtime中的class_addMethod相同。

8、%c 该指令用来获取一个类的名称,类似于objc_getClass。

从越狱手机中我们可以拿到苹果设备的桌面程序SpringBoard.app,砸壳后获取到SpringBoard对应的头文件。根据头文件我们可以大致猜测到类及类方法的作用,因此使用以上方法,我们也可以更改其他一些显示,修改桌面时间文本、颜色、电池状态、电量,当然这些可能没有实用价值,我们只是通过这种方式来进一步了解逆向。
苹果设备桌面头文件

转载于:https://www.jianshu.com/p/5705477a9f4b

猜你喜欢

转载自blog.csdn.net/weixin_34119545/article/details/91193443