应用需求:开发一个插件,把喜马拉雅App播放页面的广告去掉
大致分析
1.通过Reveal调试,可以找到广告页面的View
类名
2.通过class-dump把app的头文件导出来,根据类名找到对应的文件
3.通过theos
编写App越狱插件,注释掉view的init方法
一.新建tweak项目
1.cd到一个存放项目代码的文件夹(比如桌面)
cd ~/Desktop
2.执行theos命令
nic.pl
终端输出
------------------------------
[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
3.选择iphone/tweak,在终端输入13(我电脑这里是13),越狱插件
13
依次填写项目信息
-
1.Project Name :项目名称(随便自己写)
-
2.Package Name : 项目ID(随便写,注意不支持下划线)
-
3.Author/Maintainer Name :(作者-直接敲回车默认就是Mac上的用户名)
-
4.[iphone/tweak] MobileSubstrate Bundle filter (找到对应app的bundle id)
以喜马拉雅为例
com.gemd.iting
需要修改的App的Bundle Identifier
可以通过Cycript查看App的Bundle Identifier 例如微信的(@"com.tencent.xin")
- 5.[iphone/tweak] List of applications to terminate upon installation :(直接敲回车就是默认做法)
二.编辑Makefile
配置用户的IP和端口环境变量
vim ~/.bash_profile
添加以下代码
export THEOS=~/theos
export PATH=$THEOS/bin:$PATH
export THEOS_DEVICE_IP=127.0.0.1
export THEOS_DEVICE_PORT=10010
注意:THEOS_DEVICE_IP=127.0.0.1是固定的,代表本机地址(本机服务器)与localhost略有差别,请百度
让.bash_profile配置的环境变量立即生效(或重新打开终端)
source ~/.bash_profile
三.编写代码
打开Tweak.xm文件(建议使用Sublime Text)
%hook XMAdAnimationView
- (id)initWithImageUrl:(id)arg1 title:(id)arg2 iconType:(long long)arg3
jumpType:(long long)arg4{
return nil;
}
%end
%hook XMSoundPatchImageView
- (id)initWithFrame:(struct CGRect)arg1{
return nil;
}
%end
四.编译
make
终端输出示例
> Making all for tweak ting_tweak…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
==> Linking tweak ting_tweak (armv7)…
==> Generating debug symbols for ting_tweak…
rm /Users/lidongxi/Documents/iOS/ting_tweak/.theos/obj/debug/armv7/Tweak.xm.mm
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (arm64)…
==> Linking tweak ting_tweak (arm64)…
==> Generating debug symbols for ting_tweak…
rm /Users/lidongxi/Documents/iOS/ting_tweak/.theos/obj/debug/arm64/Tweak.xm.mm
==> Merging tweak ting_tweak…
==> Signing ting_tweak…
如果终端输出
> Making all for tweak spring…
make[2]: Nothing to be done for `internal-library-compile'.
如果想要重新编译,需要先clean一下
make clean
五.打包
make package
终端输出
> Making all for tweak itingtweak…
make[2]: Nothing to be done for `internal-library-compile'.
> Making stage for tweak itingtweak…
dm.pl: building package `com.li.ting:iphoneos-arm' in `./packages/com.li.ting_0.0.1-5+debug_iphoneos-arm.deb'
六.开启越狱手机端口转发
sh usb.sh
七.安装
make install
终端输出
==> Installing…
(Reading database ... 4414 files and directories currently installed.)
Preparing to unpack /tmp/_theos_install.deb ...
Unpacking com.li.ting (0.0.1-5+debug) over (0.0.1-4+debug) ...
Setting up com.li.ting (0.0.1-5+debug) ...
install.exec "killall -9 SpringBoard"
安装后越狱手机会桌面会重启
重新打开喜马拉雅,通过Reveal调试UI界面发现那个广告view已经没有了

注意:make package可能会报错
修改deb.mk文件第5行的压缩方式为gzip
$ vim $THEOS/makefiles/package/deb.mk
_THEOS_PLATFORM_DPKG_DEB_COMPRESSION ?= gzip
网友评论