编程知识点

IOS插件开发

2016-09-12  本文已影响330人  灰斗儿

theos 是IOS插件开发的一个比较常用的管理工具

theos环境配置

  1. 配置环境变量
localhost:~ wany$ export THEOS=/opt/theos
  1. 使用git安装最新版 theos
# 如果之前已经安装过 theos,请先删除,然后下载最新版
rm -rf $THEOS
sudo git clone --recursive https://github.com/theos/theos.git $THEOS
  1. 下载ldid - 用于模拟证书
    ldid是用于对 iOS 可执行文具进行签名的工具,可以在越狱 iOS 中替换 Xcode 自带的签名工具。
curl -s http://joedj.net/ldid > ~/Desktop/ldid
chmod +x ~/Desktop/ldid 
sudo mv ~/Desktop/ldid $THEOS/bin/ldid
  1. 安装dpkg
    deb 是越狱开发安装包的标准格式,而 dpkg-deb 是操作 deb 文件的工具,有了这个工具,Theos 才能将工程正确地打包成 deb 包。
curl -s https://raw.githubusercontent.com/DHowett/dm.pl/master/dm.pl > ~/Desktop/dpkg-deb
chmod +x ~/Desktop/dpkg-deb 
sudo mv ~/Desktop/ldid $THEOS/bin/dpkg-deb

开始第一个插件开发

开发插件涉及到logos语法

%hook
指定需要hook的类,必须以%end结尾。

%log
将函数信息写入syslog 进行打印信息,可以理解为nslog

%orig
当在一个方法内部的时候,%orig会调用原来的方法(original method)。你甚至可以给原来的method传递参数,例如:%orig(arg1,arg2)。如果你不调用%orig,原来的方法就绝对不会被调用。所以,如果你hook了某个方法,但是没有调用%orig。那么你的app 或者 iphone就将出现异常。类型下面的如此熟悉的代码

- (void)viewdidload (hook 的方法)
{
   [super viewdidload];   ( %orig )
}

创建第一个工程
localhost:~ wany$ sudo /opt/theos/bin/nic.pl
Password:
NIC 2.0 - New Instance Creator
------------------------------
  [1.] iphone/activator_event
  [2.] iphone/application_modern
  [3.] iphone/cydget
  [4.] iphone/flipswitch_switch
  [5.] iphone/framework
  [6.] iphone/ios7_notification_center_widget
  [7.] iphone/library
  [8.] iphone/notification_center_widget
  [9.] iphone/preference_bundle_modern
  [10.] iphone/tool
  [11.] iphone/tweak
  [12.] iphone/xpc_service
Choose a Template (required): 5   
Project Name (required): firsttweak
Package Name [com.yourcompany.firsttweak]: com.xxx.firsttweak
Author/Maintainer Name [System Administrator]: wany
Instantiating iphone/framework in firsttweak/...
Done.
localhost:~ xwmedia01$ cd firsttweak
localhost:firsttweak xwmedia01$ ls
Makefile    Tweak.xm    control     firstteak.plist

Makefile:包含必要的编译命令
Tweak.xm: hook 的相关代码
control: 包含applicaton/tweak的信息,当你从Cydia安装时,你可以看到这些信息,包括名字,作者,版本,等等。
Resources:包含info.plist文件等
firstteak.plist:注入目标app 的bundle id

  1. 编辑Tweak.xm 修改注入代码
%hook WeChat

-(void)applicationDidFinishLaunching:(id)application {
%orig;

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" 
message:@"Hello " 
delegate:nil 
cancelButtonTitle:@"security.ios-wiki.com" otherButtonTitles:nil];

[alert show];
[alert release];

}

%end
  1. 修改Makefile,插入以下代码到文件起始位置
THEOS_DEVICE_IP = 192.168.00.00
THEOS_DEVICE_PORT = 22
ARCHS = armv7 arm64
  1. 安装到iPhone
localhost:firstteak wany$ make package install

期间会要求输入两次密码,之后安装完成

  1. 如果想要卸载,前往Cydia 已安装插件中进行卸载
上一篇下一篇

猜你喜欢

热点阅读