ios专题

iOS逆向之Logos语法(十二)

2018-05-15  本文已影响193人  Colin_狂奔的蚂蚁

Logos语法

http://iphonedevwiki.net/index.php/Logos

001-LogosDemo工程.png 001-LogosDemo Screen Shot.png
$class-dump -H 001-LogosDemo -o /Users/yaoqi/Desktop/LogosHeaders
class-dump 001-LogosDemo工程.png Monkey工程,重签名001-LogosDemo工程.png

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

002-loginHookDemo工程Framework文件夹.png 屏幕快照 2018-05-15 下午9.37.41.png
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:

Logos Hook Screen Shot.png

Monkey工程注入FLEX库

https://github.com/Flipboard/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

FLEX能查看App的文件、数据库、沙盒、界面层级。。。

Screen Shot 2018-05-15 at 下午10.53.49.png Screen Shot 2018-05-15 at 下午10.56.05.png

Logos练习

需求:在微信首页导航栏左边添加一个➕按钮,点击事件和右边按钮的点击效果一样。

屏幕快照 2018-05-15 下午11.22.50.png

3、Xcode界面调试,找到微信导航栏右边按钮的点击的showRightTopMenuBtn方法

Target <NewMainFrameRightTopMenuBtn: 0x104dd99d0>
Action showRightTopMenuBtn
屏幕快照 2018-05-15 下午11.34.13.png 屏幕快照 2018-05-15 下午11.36.50.png 屏幕快照 2018-05-15 下午11.53.03.png

5、写代码实现需求

#import <UIKit/UIKit.h>

@interface NewMainFrameViewController :UIViewController
@end

@interface NewMainFrameRightTopMenuBtn: UIView
- (void)showRightTopMenuBtn;
@end

@interface MMBarButtonItem: UIBarButtonItem
@property(nonatomic,weak)NewMainFrameRightTopMenuBtn *view;
@end

%hook NewMainFrameViewController

-(UINavigationItem *)navigationItem{
    //    NSLog(@"\n\n\n-------------navigationItem-----");
    //方法交换! 调用自己!
    return %orig;
}

- (void)viewDidAppear:(_Bool)arg1{
    %orig;
    UIButton * leftBtn = [UIButton buttonWithType:(UIButtonTypeContactAdd)];
    [leftBtn addTarget:self action:@selector(CL_leftClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self.navigationItem setLeftBarButtonItem: [[UIBarButtonItem alloc] initWithCustomView:leftBtn]];
}

- (void)viewDidLoad{
    %orig;
    //    NSLog(@"\n\n\n-----viewDidLoad-----------");
}

%new
-(void)CL_leftClick
{
    /**
     从内存中能查到调用该方法:[self.navigationItem.rightBarButtonItem.view showRightTopMenuBtn]
     self:代表NewMainFrameViewController控制器

     */
    MMBarButtonItem *btn = self.navigationItem.rightBarButtonItem;
    [btn.view showRightTopMenuBtn];
}

%end
Screen Shot 2018-05-16 at 上午12.00.58.png
上一篇 下一篇

猜你喜欢

热点阅读