在逆向开发中,我需要使用到Logos语法,便于我们逆向开发
Logos语法
- 1.新建Logos测试工程


- 2.找到Logos测试工程的可执行文件,并导出其中的头文件
$class-dump -H 001-LogosDemo -o /Users/yaoqi/Desktop/LogosHeaders

- 3.新建Monkey工程,将Logos测试工程重签名

此时Monkey工程已经将libsubstrate.dylib库和RevealServer.framework库注入进去了,有了libsubstrate.dylib库就能写Logos语法了。

- 4.在Monkey中的Logos文件夹的.xm文件写Logos语法

Logos语法 | 功能解释 | 事例 |
---|---|---|
%hook | 需要hook哪个类 | %hook Classname |
%end | 代码块结束标记 | |
%group | 分组 | %group Groupname |
%new | 添加新方法 | %new(signature) |
%ctor | 构造函数 | %ctor { … }" |
%dtor | 析构函数 | %dtor { … } |
%log | 输出打印 | %log; %log([(<type>)<expr>, …]); |
%orig | 保持原有方法 | %orig;%orig(arg1, …); |
_02_loginHookDemoDylib.xm
// See http://iphonedevwiki.net/index.php/Logos
#import <UIKit/UIKit.h>
@interface ViewController: UIViewController
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion NS_AVAILABLE_IOS(5_0);
+ (void)CL_classMethod;
@end
%hook ViewController
- (void)loginBtnClicked:(id)arg1 {
%log;
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Hook成功了!!!" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
[alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleCancel) handler:nil]];
[self presentViewController:alertVC animated:YES completion:nil];
}
%new
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
[self.class CL_classMethod];
}
%new
+ (void)CL_classMethod {
NSLog(@"这是一个类方法!!!");
}
%end
这里在ViewController中定义了一个方法presentViewController:animated:completion:,只是为了能编译通过,骗过Xcode编译器。
5、运行成功后,Monkey工程就能Hook到001-LogosDemo工程里面的loginBtnClicked:

Monkey工程注入FLEX库
- 1.在Monkey的Dylib动态库中注入FLEX库
在Monkey工程的根目录添加Podfile文件,Target为Monkey工程动态库的Target
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target '002-loginHookDemoDylib' do
use_frameworks!
pod 'FLEX'
end
- 2.界面展示


网友评论