美文网首页
Hook InputStream 和 OutputStream备

Hook InputStream 和 OutputStream备

作者: madaoCN | 来源:发表于2020-04-07 14:07 被阅读0次
  • __NSCFInputStream
// 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];
  • __NSCFOutputStream
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];

相关文章

网友评论

      本文标题:Hook InputStream 和 OutputStream备

      本文链接:https://www.haomeiwen.com/subject/qqrkphtx.html