Logos语法学习

栏目: IOS · 发布时间: 7年前

内容简介:它是在Theos开发中允许hook代码非常的简单明了,它能够替换、修改、新增方法或者类。这种等级必须以%end结尾,并且也不存在函数如果为了支持适配不同系统的代码,可以通过以下方式

它是在Theos开发中允许hook代码非常的简单明了,它能够替换、修改、新增方法或者类。

块等级

这种等级必须以%end结尾,并且也不存在函数

%group

%group Groupname
复制代码

如果为了支持适配不同系统的代码,可以通过以下方式

%group iOS8
    %hook IOS8_SPECIFIC_CLASS
	  // your code here
    %end // end hook
    %end // end group ios8

    %group iOS9
    %hook IOS9_SPECIFIC_CLASS
    	// your code here
    %end // end hook
    %end // end group ios9

    %ctor {
    	if (kCFCoreFoundationVersionNumber >   1200) {
    		%init(iOS9);
    	} else {
    		%init(iOS8);
    	}
    }
复制代码

%hook

所有的hook都有隐藏了一个“_ungrouped”的隐式分组;它用来修饰 类名

%hook Classname
复制代码

hook之间的代码是SBApplicationController具体的函数

%hook SBApplicationController
-(void)uninstallApplication:(SBApplication *)application {
	NSLog(@"Hey, we're hooking uninstallApplication:!");
	%orig; // Call the original implementation of this method
	return;
}
%end
复制代码

%new

给hook的类添加新方法;signature是OC类型的新方法名,必须在%hook块之间

%new  // 修饰新的方法
%new(signature)  // 修饰新的方法signature
复制代码
%hook ClassName
%new
- (id)someValue {
	return objc_getAssociatedObject(self, @selector(someValue));
}

%end
复制代码

%subclass

通过运行时创建的子类,ivars不支持;使用%new修饰新增的方法,如果需要访问新类,必须通过 %c 操作符获取,可以在%group块中

%subclass MyObject : NSObject

- (id)init {
	self = %orig;
	[self setSomeValue:@"value"];
	return self;
}

//the following two new methods act as `@property (nonatomic, retain) id someValue;`
%new
- (id)someValue {
	return objc_getAssociatedObject(self, @selector(someValue));
}

%new
- (void)setSomeValue:(id)value {
	objc_setAssociatedObject(self, @selector(someValue), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

%end

%ctor {
	MyObject *myObject = [[%c(MyObject) alloc] init];
	NSLog(@"myObject: %@", [myObject someValue]);
}
复制代码

%property

%property (nonatomic|assign|retain|copy|weak|strong|getter|setter) Type name;
复制代码

添加新的属性在类中,必须在 %hook 修饰或者 %subclass 修饰的内部。

%end

%end
复制代码

用来修饰 group/hook/subclass 的块结束

顶部等级

这部分的指令不再 group/hook/subclass 的块内部。

%config

%config(Key=Value);
复制代码
Logos语法学习

%hookf

%hookf(rtype, symbolName, args...) { … }
复制代码
// 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
}
复制代码
CFBooleanRef (*orig_MGGetBoolAnswer)(CFStringRef);
CFBooleanRef fixed_MGGetBoolAnswer(CFStringRef string)
{
	if (CFEqual(string, CFSTR("StarkCapability"))) {
		return kCFBooleanTrue;
	}
	return orig_MGGetBoolAnswer(string);
}

%hookf(CFBooleanRef, "_MGGetBoolAnswer", CFStringRef string)
{
	if (CFEqual(string, CFSTR("StarkCapability"))) {
		return kCFBooleanTrue;
	}
	return %orig;
}
复制代码

%ctor

%ctor { … }
复制代码

匿名构造方法

%dtor

%dtor { … }
复制代码

匿名销毁构造方法

函数等级

只在函数block中

%init

%init;
%init([<class>=<expr>, …]);
%init(Group[, [+|-]<class>=<expr>, …]);
复制代码

初始化分组或默认分组

%hook SomeClass
-(id)init {
    return %orig;
}
%end

%ctor {
    %init(SomeClass=objc_getClass("class with spaces in the name"));
}
复制代码

%c

%c([+|-]Class)
复制代码

等价于实例对象,或者类名

%orig

%orig
%orig(arg1, …)
复制代码

调用原始方法,不能够在%new里面,

%log

%log;
%log([(<type>)<expr>, …]);
复制代码

打印日志


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security Testing Cookbook

Web Security Testing Cookbook

Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99

Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器