首先我们需要配置Theos
,这里简单的说一下,毕竟简书上关于安装Theos
的文章非常的多。 ####一、Theos的配置与安装 1.安装dpkg 2.安装ldid 3.Theos安装 如果上面的安装成功之后,我们来写自己的第一个tweak
。 ####二、tweak的编写、编译、打包以及安装 ######1、创建工程 (1)打开终端输入:
nic.pl
复制代码
15
,按
Enter
键,此时
Theos
要求我们输入工程名:
Project Name (required): iostweak
复制代码
(3)输入一个工程名称,按Enter
键,此时Theos
要求我们输入deb
包的名字(类似于bundle identifier
):
Package Name [com.yourcompany.iostweak]: com.xin.iostweak
复制代码
(4)输入deb
包的名字,按Enter
键,Theos
要求我们输入tweak
作者的名字:
Author/Maintainer Name [zy]: zyxin
复制代码
(5)输入名字后,按Enter
键,Theos
要求我们输入MobileSubstrate Bundle Filter
,也就是tweak
作用对象的bundle identifier
,这里我们使用微信的bundle identifier
,待会可以看到效果:
[iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: com.tencent.xin
复制代码
(6)输入bundle filter
,Theos
要求我们指定tweak
安装完成后需要重启的应用,仍以bundle identifier
表示:
[iphone/tweak] List of applications to terminate upon installation (space-separated, '-' for none) [SpringBoard]: com.tencent.xin
复制代码
以上的步骤完成之后,一个名为iostweak
的文件夹就在当前目录下生成了,文件夹中就是刚创建的tweak
工程,你可以把这个文件夹挪到任何位置。 ######2.定制工程文件 (1)control
control
文件记录了deb
包管理系统所需的基本信息,会被打包进deb
包中。control
文件中得很多信息直接体现在Cydia
中,可以自行对比其内容。 (2)iostweak.plist
这个plist
文件的作用和App
中的Info.plist
类似,都记录一些配置信息,它描述了tweak
的作用范围。 (3)Makefile
Makefile
文件制定编译和链接所涉及的文件、框架、库等信息,将整个过程自动化。 (4)Tweak.xm
######3.编写Makefile
THEOS_DEVICE_IP = localhost -p 2223
ARCHS = arm64 armv7
TARGET = iPhone:latest:8.0
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = iostweak
iostweak_FILES = Tweak.xm
iostweak_FRAMEWORKS = UIKit
include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
install.exec "killall -9 com.tencent.xin"
复制代码
######4.编写Tweak.xm
%hook MicroMessengerAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"微信提示" message:@"第一个tweak成功了" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alertView show];
return %orig;
复制代码
######5.编译,打包 1> cd
到工程目录中
deMacBook-Pro:iostweak zy$
复制代码
2> 输入make
进行编译:
deMacBook-Pro:iostweak zy$ make
> Making all for tweak iostweak…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (arm64)…
==> Linking tweak iostweak (arm64)…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
==> Linking tweak iostweak (armv7)…
==> Merging tweak iostweak…
==> Signing iostweak…
deMacBook-Pro:iostweak zy$
复制代码
3> 输入make package
进行打包
deMacBook-Pro:iostweak zy$ make package
> Making all for tweak iostweak…
make[2]: Nothing to be done for `internal-library-compile'.
> Making stage for tweak iostweak…
dm.pl: building package `com.xin.iostweak:iphoneos-arm' in `./packages/com.xin.iostweak_0.0.1-1+debug_iphoneos-arm.deb'
deMacBook-Pro:iostweak zy$
复制代码
此时在文件packages
中会有一个.deb
文件。 ######6.安装 这里有点出处,可以用ssh
来安装,由于手机版本是10.1.1
,ssh
连不上手机,目前未找到原因,希望有人可以告诉我。所以这里借助pp
助手来安装。
Makefile
文件时,设备
IP
地址:
THEOS_DEVICE_IP = localhost -p 2223
复制代码
这里需要写你当前的手机IP
地址。 一切准备就绪,此时不安装,更待何时。 输入make package install
,期间会让你输入两次密码,均为默认密码:alpine
deMacBook-Pro:iostweak zy$ make package install
> Making all for tweak iostweak…
make[2]: Nothing to be done for `internal-library-compile'.
> Making stage for tweak iostweak…
dm.pl: building package `com.xin.iostweak:iphoneos-arm' in `./packages/com.xin.iostweak_0.0.1-3+debug_iphoneos-arm.deb'
==> Installing…
The authenticity of host '[localhost]:2223 ([127.0.0.1]:2223)' can't be established.
ECDSA key fingerprint is SHA256:cWorIL/1FtfI3ad4iTFfufN3K4bs71U+V0W+RQhK7lg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2223' (ECDSA) to the list of known hosts.
root@localhost's password:
Selecting previously unselected package com.xin.iostweak.
(Reading database ... 3284 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.xin.iostweak (0.0.1-3+debug) ...
Setting up com.xin.iostweak (0.0.1-3+debug) ...
install.exec "killall -9 com.tencent.xin"
root@localhost's password:
No matching processes were found
make: *** [after-install] Error 1
deMacBook-Pro:iostweak zy$
复制代码
报了一个错误,说找不到进程,这个错误是因为我误将 Makefile
中需要 kill
的进程名称填成了bundle identifier
,将它改成WeChat
就好了:killall -9 WeChat
。 运行微信:
Cydia
查看:这里的大多数信息就是我们得到的
control
,可以对比一下!
####三、问题总结 1.tweak
编译成功了,但是make package
时报错,错误信息如下:
/opt/theos/bin/dm.pl
把
dm.pl
文件替换成
dm.pl 密码:
jjtb
,不出意外,你会报这个错误
/usr/local/bin/fakeroot: line 179: /opt/theos/bin/dm.pl: Permission denied
make: *** [internal-package] Error 126
复制代码
这个其实是dm.pl
没有权限,所以我们赋予它权限就可以了,终端输入:
sudo chmod 777 /opt/theos/bin/dm.pl
复制代码
打包成功!
2.编译时出现如下错误
Makefile
写成如下:
TARGET = iPhone:10.1.2:8.0
解释一下 TARGET = iPhone:低于10.0版本的SDK:高于8.0版本的ios
复制代码
改成这样就没事了,哈哈
TARGET = iPhone:latest:8.0
复制代码
#####参考: http://bbs.iosre.com/t/make-make-package/1345/7 http://www.360doc.com/content/17/1208/23/50666456_711399816.shtml http://www.jianshu.com/p/ad4c009511ec http://www.jianshu.com/p/307243ea40e4 ####主要参考:【IOS应用逆向工程:分析与实战】