Skip to content

Instantly share code, notes, and snippets.

@draveness
Last active September 1, 2016 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draveness/0cb112723fa1678976fb2907db5b47b2 to your computer and use it in GitHub Desktop.
Save draveness/0cb112723fa1678976fb2907db5b47b2 to your computer and use it in GitHub Desktop.
Using fishhook to change socket layer function and failed because of recursive call
#import "ViewController.h"
#import <fishhook.h>
@interface ViewController () <NSURLSessionDataDelegate>
@end
@implementation ViewController
int (*origianl_connect)(int, const struct sockaddr *, socklen_t);
int new_connect(int socket, const struct sockaddr * address, socklen_t address_len) {
return origianl_connect(socket, address, address_len);
}
+ (void)load {
rebind_symbols((struct rebinding[1]) {
{"connect", (void *)new_connect, (void **)&origianl_connect },
}, 1);
}
- (void)viewDidLoad {
[super viewDidLoad];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:nil];
[[session dataTaskWithURL:[NSURL URLWithString:@"https://baidu.com"]] resume];
}
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler {
NSLog(@"%@", response);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment