mac 工具集(2)之Theos以及第一次写tweak和遇到的问题总结

首先我们需要配置Theos,这里简单的说一下,毕竟简书上关于安装Theos的文章非常的多。 ####一、Theos的配置与安装 1.安装dpkg 2.安装ldid 3.Theos安装 如果上面的安装成功之后,我们来写自己的第一个tweak。 ####二、tweak的编写、编译、打包以及安装 ######1、创建工程 (1)打开终端输入:

nic.pl
复制代码

(2)输入 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.1ssh连不上手机,目前未找到原因,希望有人可以告诉我。所以这里借助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.pldm.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应用逆向工程:分析与实战】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值