Hook InputStream 和 OutputStream备

2020-04-07  本文已影响0人  madaoCN
// 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];
上一篇 下一篇

猜你喜欢

热点阅读