1、概念
Logos
语法其实是 CydiaSubstruct
框架提供的一组宏定义。便于开发者使用宏进行 HOOK
操作。语法简单,功能强大且稳定。
2、详细介绍
2.1、文件后缀名
.x
结尾,表示该文件支持 logos
和 c++
语法,.xm
结尾,表示该文件支持 logos
和 c++
、OC
语法
2.2、logos语法
logos
语法分为三大类:
2.2.1、Block level
这一类型的指令会开辟一个代码块,以 %end
结束。
%group
、%hook
、% subclass
、 %end
、%new
1、%group
将代码分组,开发中hooks代码很多,这样方便代码管理。All ungrouped hooks are in the implicit "_ungrouped" group.
所有代码块都会有默认的组和构造方法
%group group1
%hook ClassName1
%end
%end
%group group2
%hook ClassName2
%end
%end
// 初始化group1和group2
%ctor{
%init(group1);%init(group2);
}
2、%new
添加新的方法
%hook ClassName1
%new
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"touches");
}
%end
添加一个类方法
@interface ViewController: UIViewController
+ (void) ClassMethod; // 声明该方法
@end
%hook ViewController
%new
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"touches");
[self.class ClassMethod];
}
%new
+ (void) ClassMethod {
NSLog(@"添加一个类方法");
}
%end
2.2.2、Top level
这个 TopLevel
指令不放在 BlockLevel
中。
%config
、%hookf
、%ctor
、%dtor
1、%ctor
构造函数,用于确定加载哪个组,和 %init
结合使用
2、%dtor
析构函数
3、%hookf
hook
一个 function
// Given the function prototype
FILE *fopen(const char *path, const char *mode);
// The hook is thus made
%hookf(FILE *, fopen, const char *path, const char *mode) {
NSLog(@"Hey, we're hooking fopen to deny relative paths!");
if (path[0] != '/') {
return NULL;
}
return %orig; // Call the original implementation of this function
}
2.2.3、Function level
这一块的指令就放在方法中。
%init
、%class
、 %c
、 %orig
、%log
1、%init
用来初始化某个组
2、%log
用于输出日志,输出方法调试的信息。
-[<ViewController: 0x103115fe0> loginBtnClicked:<UIButton: 0x10311f970; frame = (166 388; 67 31); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x281287fa0>>]
3、%orig
对原来的方法进行调用。
id result = %orig; // 有返回值 result 可以修改返回值
4、%c
拿到一个类名的 runtime
方法
%c(ViewController) // 获取ViewController class
网友评论