怎么hook 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?:@"");if (result.length == 32) {NSLog(@"params:%@",obj1);NSLog(@"shield found!%@",result);NSLog(@"%@",[NSThread callStackSymbols]);}va_end(args);return result;
}static __attribute__((constructor)) void _logosLocalInit112() {Method originalMethod = class_getClassMethod(NSClassFromString( @"NSString" ), NSSelectorFromString( @"stringWithFormat:" ));method_setImplementation(originalMethod, (IMP)stringWithFormat );}
替换NSString字符串
id stringWithFormat(id self, SEL op,id obj1, ...);
id stringWithFormat(id self, SEL op,id obj1, ...){va_list args;va_start(args, obj1);//等价实现方法
// NSLog(@"NSString args ---%@",args);NSLog(@"NSString obj1 ---%@",obj1);NSString*URLString = obj1;if (URLString && [URLString rangeOfString:@"xxxx剩余"].location != NSNotFound) {
// xxxx剩余
// %@obj1 = @"xxxx%@";}NSString *result = [[NSMutableString alloc] initWithFormat:obj1 arguments:args ];NSLog(@"NSString stringWithFormat ---%@",result?:@"");if (result.length == 32) {NSLog(@"params:%@",obj1);NSLog(@"shield found!%@",result);NSLog(@"%@",[NSThread callStackSymbols]);}va_end(args);return result;
}__attribute__((constructor)) static void entry(){NSLog(@"[AntiAntiDebug Init]");Method originalMethod = class_getClassMethod(NSClassFromString( @"NSString" ), NSSelectorFromString( @"stringWithFormat:" ));method_setImplementation(originalMethod, (IMP)stringWithFormat );
}