七、iOS逆向之《Logos语法》

概述

Logos语法其实是CydiaSubstruct框架提供的一组宏定义。便于开发者使用宏进行HOOK操作。语法简单,功能强大且稳定。
http://iphonedevwiki.net/index.php/Logos

Logos语法分为三大类:

  • Top level
  • Block level
  • Function level

Top level

这个TopLevel指令不放在BlockLevel中。
%config、%hookf、%ctor、%dtor

Block level

这一类型的指令会开辟一个代码块,以%end结束。
%group、%hook、% subclass 、 %end

Function level

这一块的指令就放在方法中。
%init、%class、 %c、 %orig、%log

常用语法

%HOOK

  • HOOK 某个类里面的某个方法


    HOOK方法
  • 为某个类添加新方法


    添加新方法

%group

用来将代码分组。开发中hook代码会很多,这样方便管理Logos代码。

构造函数%ctor(constructor)

%ctor(constructor)

构造函数,用于确定加载那个组。和%init结合用

%init

%init

用来初始化某个组。

%init

%log

能够输出日志!! 输出方法调用的详细信息

%log

%orig(original)

这个就是保持原有的方法实现,如果原来的方法有返回值,那么%orig 就有返回值的。

%orig(original)

%new

给某个类添加方法,在%hook 和 %end 中使用。

%new

%c

类似getClass函数,获得一个类对象。一般用于调用类方法。

%c

HOOK示例

下方示例是对微信的设置页面进行UI的修改。在设置界面末尾添加两个cell。


#import <UIKit/UIKit.h>

@interface MMTableViewInfo
- (long long)numberOfSectionsInTableView:(UITableView*)tableView;
@end

%hook MMTableViewInfo

- (long long)numberOfSectionsInTableView:(UITableView*)tableView{
    if ([tableView.nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]) {
        NSLog(@"设置页面");
        return %orig+1;
    }
    return %orig;

}

- (long long)tableView:(UITableView*)tableView numberOfRowsInSection:(long long)section{
    if ([tableView.nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]
        && section == [self numberOfSectionsInTableView:tableView]-1) {
        return 2;
    }
    return %orig;
}

- (double)tableView:(UITableView*)tableView heightForRowAtIndexPath:(id)indexPath {
    if ([tableView.nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]
        && [indexPath section] == [self numberOfSectionsInTableView:tableView]-1) {
        return 44;
    }
    return %orig;
}

- (id)tableView:(UITableView*)tableView cellForRowAtIndexPath:(id)indexPath {
    if ([tableView.nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]
        && [indexPath section] == [self numberOfSectionsInTableView:tableView]-1) {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
            cell.contentView.backgroundColor = UIColor.whiteColor;
            cell.backgroundColor = UIColor.whiteColor;
        }
        if ([indexPath row] == 0) {
            cell.textLabel.text = @"抢飞机";
            UISwitch * st = [[UISwitch alloc]init];
            cell.accessoryView = st;
        }else{
            cell.textLabel.text = @"抢飞机时间";
            UITextField * tf = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
            tf.borderStyle = UITextBorderStyleRoundedRect;
            tf.placeholder = @"请设置抢飞机时间";
            cell.accessoryView = tf;
        }
        return cell;
    }
    return %orig;
}


%end


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容