views:

119

answers:

0

I am trying to hooking message sending for iOS 3.2, I implement my own hook on a working ExampleHook program I find on the web. But my hook apparently caused segmentation fault everytime it hooks and I don't know why. I want to hook to

[NSURL initWithString:(NSString *)URLString  relativeToURL:(NSURL *)baseURL;

and here is my related implementation

static id __$GFWInterceptor_NSURL_initWithString2(NSURL<GFWInterceptor> *_NSURL, NSString *URLString, NSURL* baseURL){
NSLog(@"We have intercepted this url: %@",URLString);
[_NSURL __HelloNSURL_initWithString:URLString relativeToURL:baseURL];

establish hook

Class _$NSURL = objc_getClass("NSURL");
MSHookMessage(_$NSURL, @selector(initWithString:relativeToURL:), (IMP) &__$GFWInterceptor_NSURL_initWithString2, "__HelloNSURL_");

original method declaration

- (void)__HelloNSURL_initWithString:(NSString *)URLString  relativeToURL:(NSURL *)baseURL;

and here is my gdb backtrace

Reason: KERN_INVALID_ADDRESS at address: 0x74696e71
0x335625f8 in objc_msgSend ()
(gdb) bt
0  0x335625f8 in objc_msgSend ()
1  0x32c05b1a in CFStringGetLength ()
2  0x32c108a8 in _CFStringIsLegalURLString ()
3  0x32b1c32a in -[NSURL initWithString:relativeToURL:] ()
4  0x000877c0 in __$GFWInterceptor_NSURL_initWithString2 ()
5  0x32b1c220 in +[NSURL URLWithString:relativeToURL:] ()
6  0x32b1c1f4 in +[NSURL URLWithString:] ()
7  0x3061c614 in createUniqueWebDataURL ()
8  0x3061c212 in +[WebFrame(WebInternal)             

and apparently it hooks, but there is some memory issue there and I can't find anything to blame now