Logos 官网: http://iphonedevwiki.net/index.php/Logos
iphonedevwiki.net/index.php/Logos
在 .xm 文件 进行编译(支持 C、C++、OC )
在 .mm 原文件
-
基本使用的语法
/*
%hook + 类 //开始
code...
%end //结束
//构造函数 constructor
//默认的 %ctor{ %init(_ungrouped)}
*/
//------------------分组:组1-------------------
%group group1
%hook ViewController
%end
%end
//------------------分组:组2-------------------
%group group2
%hook ViewController
%end
%end
//构造函数:constructor 初始化
%ctor{
%init(group1)%init(group2) // group2 覆盖 group1
}
%orig
// original: 保持原有方法的实现
// %ori(arg1, arg2, arg3, ...) 可以传参数
%new
// 给某个类添加动态方法
-
测试过程
1、创建Logos_MokeyApp
2、编辑logos
3、安装pod应用
# Uncomment the next line to define a global platform for your project
# platform :ios, '8.0'
target 'Logos_MokeyApp-LoginHookDylib' do
use_frameworks!
pod 'FLEX'
end
Logos-1.png
Logos-2.png
-
测试源码
#import <UIKit/UIKit.h>
@interface CustomViewController
@property (nonatomic, copy) NSString* newProperty;
+ (void)classMethod;
- (NSString*)getMyName;
- (void)newMethod:(NSString*) output;
@end
%hook CustomViewController
+ (void)classMethod
{
%log;
%orig;
}
%new
-(void)newMethod:(NSString*) output{
NSLog(@"This is a new method : %@", output);
}
%new
- (id)newProperty {
return objc_getAssociatedObject(self, @selector(newProperty));
}
%new
- (void)setNewProperty:(id)value {
objc_setAssociatedObject(self, @selector(newProperty), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSString*)getMyName
{
%log;
NSString* password = MSHookIvar<NSString*>(self,"_password");
NSLog(@"password:%@", password);
[%c(CustomViewController) classMethod];
[self newMethod:@"output"];
self.newProperty = @"newProperty";
NSLog(@"newProperty : %@", self.newProperty);
return %orig();
}
%end
网友评论