安装签名工具ldid
- 先确保安装了brew
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 利用
brew
安装ldid
$ brew install ldid
修改环境变量
- 编辑用户的配置文件
$ vim ~/.bash_profile
- 在
.bash_profile
文件后面加入以下2行
export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
- 让
.bash_profile
配置的环境变量立即生效(或者重新打开终端)
$ source ~/.bash_profile
下载theos
- 建议在
$THEOS
目录下载代码(也就是刚才配置的~/theos
)
$ git clone --recursive https://github.com/theos/theos.git $THEOS
新建tweak项目
- cd到一个存放项目代码的文件夹(比如桌面)
$ cd ~/Desktop
$ nic.pl
- 选择
[11.] iphone/tweak
- 填写项目信息
- Project Name (项目名称)
- Package Name(项目ID,可随便写)
- Author/Maintainer Name
- 作者
- 直接回车就行,默认Mac上的用户名
- [iphone/tweak] MobileSubstrate Bundle filter
- 需要修改的APP的Bundle identifier
- 可以通过
Cycript
查看APP的Bundle identifier
- [iphone/tweak] List of applications to terminate upon installation
- 直接回车就行
编辑Makefile
- 在前面加入环境变量,写清楚通过哪个IP和端口访问手机
- THEOS_DEVICE_IP
- THEOS_DEVICE_PORT
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=10010
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = tingtweak2
tingtweak2_FILES = Tweak.xm
include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
install.exec "killall -9 SpringBoard"
如果不希望每个项目的Makefile都编写IP和端口环境变量,也可以添加到用户的配置文件中,编辑完毕后$ source ~/.bash_profile
(或者重启终端)
$ vim ~/.bash_profile
export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=10010
$ source ~/.bash_profile
编写代码
- 打开
Tweak.xm
文件
%hook XMSoundPatchImageView
- (id)initWithFrame:(struct CGRect)arg1{
return nil;
}
%end
%hook XMAdAnimationViewTwo
- (id)initWithFrame:(struct CGRect)arg1{
return nil;
}
%end
编译-打包-安装
- 编译
make
- 打包成
deb
make package
- 安装
make install
可能遇到的问题
make package
的错误
$ make package
Can't locate IO/Compress/Lzma.pm in @INC (you may need to install the
IO::Compress::Lzma module) (@INC contains: /Library/Perl/5.18/darwin-
thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-
thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2
/System/Library/Perl/5.18/darwin-thread-multi-2level
/System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-
multi-2level /System/Library/Perl/Extras/5.18 .) at
/Users/mj/theos/bin/dm.pl line 12.
BEGIN failed--compilation aborted at /Users/mj/theos/bin/dm.pl line 12.
make: *** [internal-package] Error 2
- 是因为打包压缩方式有问题,改成
gzip
压缩就行了- 修改
dm.pl
文件,用#
号注释掉下面两句
- 修改
$ vim $THEOS/vendor/dm.pl/dm.pl
#use IO::Compress::Lzma;
#use IO::Compress::Xz;
- 修改
deb.mk
文件第6行的压缩方式为gzip
$ vim $THEOS/makefiles/package/deb.mk
_THEOS_PLATFORM_DPKG_DEB_COMPRESSION ?= gzip
make的错误
$ make
Error: You do not have an SDK in
/Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/S
DKs
- 是因为多个Xcode导致路径(可能安装了多个xcode),需要指定以下xcode
$ sudo xcode-select --switch
/Applications/Xcode.app/Contents/Developer/
- 之前编译过,有会有以下提示
$ make
> Making all for tweak xxx...
make[2]: Nothing to be done for `internal-library-compile'.
这是因为缓存导致的,但是不影响操作,如需出现原来的打印,可以clean
一下
$ make clean
$ make