// hook
Class inputClzss = NSClassFromString(@"__NSCFInputStream");
[inputClzss aspect_hookSelector:@selector(read:maxLength:) withOptions:(AspectPositionAfter) usingBlock:^(id<AspectInfo> aspectInfo, uint8_t *buffer, NSUInteger maxLength) {
NSInputStream *instance = (NSInputStream *)[aspectInfo instance];
NSString *hostName = [instance propertyForKey:(NSString *)kCFStreamPropertySocketRemoteHostName];
NSString *portNum = [instance propertyForKey:(NSString *)kCFStreamPropertySocketRemotePortNumber];
NSLog(@"===== ip: %@:%@ input: %s maxLength: %lu", hostName, portNum, buffer, (unsigned long)maxLength);
;
} error:NULL];
Class outputClzss = NSClassFromString(@"__NSCFOutputStream");
[outputClzss aspect_hookSelector:@selector(write:maxLength:) withOptions:(AspectPositionAfter) usingBlock:^(id<AspectInfo> aspectInfo, const uint8_t *buffer, NSUInteger maxLength) {
NSOutputStream *instance = (NSOutputStream *)[aspectInfo instance];
NSString *hostName = [instance propertyForKey:(NSString *)kCFStreamPropertySocketRemoteHostName];
NSString *portNum = [instance propertyForKey:(NSString *)kCFStreamPropertySocketRemotePortNumber];
NSLog(@"===== ip: %@:%@ output: %s maxLength %lu", hostName, portNum, buffer, (unsigned long)maxLength);
;
} error:NULL];
网友评论