Hook NSString问题

请教下这个报错什么问题

不定参数可不能这么hook

1 个赞
+ (instancetype)stringWithFormat:(NSString *)format, ...;

https://developer.apple.com/documentation/foundation/nsstring/1497275-stringwithformat

id stringWithFormat(id self, SEL op,id obj1, ...);
id stringWithFormat(id self, SEL op,id obj1, ...){
    va_list args;
    va_start(args, obj1);
    //等价实现方法
    NSString *result = [[NSMutableString alloc] initWithFormat:obj1 arguments:args ];
    NSLog(@"NSString stringWithFormat ---%@",result?:@"");
    va_end(args);
    return result;
}

static __attribute__((constructor)) void _logosLocalInit112() {


        Method originalMethod = class_getClassMethod(NSClassFromString( @"NSString" ), NSSelectorFromString( @"stringWithFormat:" ));

        method_setImplementation(originalMethod, (IMP)stringWithFormat );

}
3 个赞