Last active
September 1, 2016 02:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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