微信iOS消息拦截插件教程-第一个tweak编译过程
-安装好theos框架之后,下面用一个简单的例子进行说明编译过程
-新建一个代码目录
-进入terminal,cd到刚才的目录中
1、进入目录
2、执行/opt/theos/bin/nic.pl
3、选择模板11
4、输入你的插件名字 wechat_hook
5、输入你公司的名字 com.tencent.xin,名字随意
6、输入作者的名字,author 随意
7、输入你的插件需要Hook的目标App Bundle ID ,微信的是 com.tencent.xin
8、输入安装时需要结束进程的App Bundle ID,这里直接Enter跳过
执行完毕之后你将看到目录:
-进入terminal,cd 到 wechat_hook中
1、执行make指令之后你很可能看到错误
'''
Makefile:1: /makefiles/common.mk: No such file or directory
Makefile:6: /tweak.mk: No such file or directory
make: *** No rule to make target `/tweak.mk'. Stop.
'''
这个是因为路径不对,需要在终端中添加默认环境变量
-解决编译错误,在终端中输入,export THEOS=/opt/theos
-将Tweak.xm修改为下面的代码
'''
%hook ClassName
// Hooking a class method
- (id)sharedInstance {
return %orig;
}
// Hooking an instance method with an argument.
-
(void)messageName:(int)argument {
%log; // Write a message about this call, including its class, name and arguments, to the system log.%orig; // Call through to the original function with its original arguments.
%orig(nil); // Call through to the original function with a custom argument.// If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
}
// Hooking an instance method with no arguments.
-
(id)noArguments {
%log;
id awesome = %orig;
//[awesome doSomethingElse];
[awesome performSelector:@selector(doSomethingElse)];return awesome;
}
// Always make sure you clean up after yourself; Not doing so could have grave consequences!
%end
'''
-然后make
如果看到下面的结果表明编译成功了