使用Logos进行hook时不能直接识别中文类名。绕过这个限制

在使用Logos进行hook时,如果你遇到“Unknown type name”的错误,通常是因为Logos不能直接识别中文类名。为了绕过这个限制,你可以使用Objective-C运行时函数来获取类和方法,并进行动态hook。以下是一个示例,演示如何使用运行时函数来hook中文类名的方法。

#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>

// 定义hook函数
void hook_中文方法名(id self, SEL _cmd) {
    NSLog(@"Before calling 中文方法名");
    
    // 获取原方法
    Class class = object_getClass(self);
    SEL selector = NSSelectorFromString(@"中文方法名");
    Method method = class_getInstanceMethod(class, selector);
    void (*orig_func)(id, SEL) = (void (*)(id, SEL))method_getImplementation(method);
    
    // 调用原方法
    orig_func(self, _cmd);
    
    NSLog(@"After calling 中文方法名");
}

// 在应用启动时执行hook
%ctor {
    @autoreleasepool {
        // 获取目标类
        Class targetClass = objc_getClass("中文.ViewController");
        
        // 获取目标方法
        SEL targetSelector = NSSelectorFromString(@"中文方法名");
        Method targetMethod = class_getInstanceMethod(targetClass, targetSelector);
        
        // 替换方法实现
        if (targetMethod) {
            MSHookMessageEx(targetClass, targetSelector, (IMP)hook_中文方法名, NULL);
        }
        
        NSLog(@"Tweak loaded");
    }
}
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>

// 定义hook函数
void hook_中文方法名(id self, SEL _cmd, id arg) {
    NSLog(@"Before calling 中文方法名: with arg: %@", arg);
    
    // 获取原方法
    Class class = object_getClass(self);
    SEL selector = NSSelectorFromString(@"中文方法名:");
    Method method = class_getInstanceMethod(class, selector);
    void (*orig_func)(id, SEL, id) = (void (*)(id, SEL, id))method_getImplementation(method);
    
    // 调用原方法
    orig_func(self, _cmd, arg);
    
    NSLog(@"After calling 中文方法名: with arg: %@", arg);
}

// 在应用启动时执行hook
%ctor {
    @autoreleasepool {
        // 获取目标类
        Class targetClass = objc_getClass("中文_ViewController");
        
        // 获取目标方法
        SEL targetSelector = NSSelectorFromString(@"中文方法名:");
        Method targetMethod = class_getInstanceMethod(targetClass, targetSelector);
        
        // 替换方法实现
        if (targetMethod) {
            MSHookMessageEx(targetClass, targetSelector, (IMP)hook_中文方法名, NULL);
        }
        
        NSLog(@"Tweak loaded");
    }
}
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>

// 定义hook函数
void hook_中文方法名(id self, SEL _cmd, id param1, id param2) {
    NSLog(@"Before calling 中文方法名:param1:param2: with params: %@, %@", param1, param2);
    
    // 获取原方法
    Class class = object_getClass(self);
    SEL selector = NSSelectorFromString(@"中文方法名:param1:param2:");
    Method method = class_getInstanceMethod(class, selector);
    void (*orig_func)(id, SEL, id, id) = (void (*)(id, SEL, id, id))method_getImplementation(method);
    
    // 调用原方法
    orig_func(self, _cmd, param1, param2);
    
    NSLog(@"After calling 中文方法名:param1:param2: with params: %@, %@", param1, param2);
}

// 在应用启动时执行hook
%ctor {
    @autoreleasepool {
        // 获取目标类
        Class targetClass = objc_getClass("中文_ViewController");
        
        // 获取目标方法
        SEL targetSelector = NSSelectorFromString(@"中文方法名:param1:param2:");
        Method targetMethod = class_getInstanceMethod(targetClass, targetSelector);
        
        // 替换方法实现
        if (targetMethod) {
            MSHookMessageEx(targetClass, targetSelector, (IMP)hook_中文方法名, NULL);
        }
        
        NSLog(@"Tweak loaded");
    }
}
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <substrate.h>

// 定义原始函数指针
id (*orig_中文方法名)(id self, SEL _cmd, id param1, id param2, id param3);

// 定义hook函数
id hook_中文方法名(id self, SEL _cmd, id param1, id param2, id param3) {
    NSLog(@"Before calling 中文方法名:param1:param2: with params: %@, %@, %@", param1, param2, param3);
    
    // 调用原方法
    id returnValue = orig_中文方法名(self, _cmd, param1, param2, param3);
    
    NSLog(@"After calling 中文方法名:param1:param2: with params: %@, %@, %@, return value: %@", param1, param2, param3, returnValue);
    
    return returnValue;
}

// 在应用启动时执行hook
%ctor {
    @autoreleasepool {
        // 获取目标类
        Class targetClass = objc_getClass("中文方法名.ViewController");
        
        // 获取目标方法
        SEL targetSelector = NSSelectorFromString(@"中文方法名:param1:param2:");
        Method targetMethod = class_getInstanceMethod(targetClass, targetSelector);
        
        // 替换方法实现
        if (targetMethod) {
            MSHookMessageEx(targetClass, targetSelector, (IMP)hook_中文方法名, (IMP *)&orig_中文方法名);
        }
        
        NSLog(@"Tweak loaded");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ios and Android

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值