Objective c 在UIApplication(CaptainHook)中调整openURL
如何在应用程序中加载钩子Objective c 在UIApplication(CaptainHook)中调整openURL,objective-c,ios5,hook,jailbreak,tweak,Objective C,Ios5,Hook,Jailbreak,Tweak,如何在应用程序中加载钩子 #import <CaptainHook/CaptainHook.h> #import <SpringBoard/SpringBoard.h> CHDeclareClass(SBAlertWindow); CHOptimizedMethod(1, self, void, SBAlertWindow, displayAlert, id, alert) { NSLog(@"load displayAlert!"); CHSuper(
#import <CaptainHook/CaptainHook.h>
#import <SpringBoard/SpringBoard.h>
CHDeclareClass(SBAlertWindow);
CHOptimizedMethod(1, self, void, SBAlertWindow, displayAlert, id, alert) {
NSLog(@"load displayAlert!");
CHSuper(1, SBAlertWindow, displayAlert, alert);
}
CHDeclareClass(UIApplication)
CHOptimizedMethod(1, self, void, UIApplication, openURL, NSURL *, url) {
NSString *linkToOpen = [[NSURL alloc] initWithString:[url absoluteString]];
NSLog(@"dont load link: %@", linkToOpen);
CHSuper(1, UIApplication, openURL, url);
}
CHConstructor {
CHLoadLateClass(SBAlertWindow);
CHHook(1, SBAlertWindow, displayAlert);
CHLoadLateClass(UIApplication);
CHHook(1, UIApplication, openURL);
}
#导入
#进口
CHDeclareClass(SBAlertWindow);
CHOptimizedMethod(1,self,void,SBAlertWindow,displayAlert,id,alert){
NSLog(@“加载显示警报!”);
CHSuper(1,SBAlertWindow,displayAlert,alert);
}
CHDECLARE类(UIApplication)
CHOptimizedMethod(1,self,void,UIApplication,openURL,NSURL*,url){
NSString*linkToOpen=[[NSURL alloc]initWithString:[url absoluteString]];
NSLog(@“不加载链接:%@”,链接打开);
CHSuper(1,UIApplication,openURL,url);
}
CHConstructor{
CHLoadLateClass(SBAlertWindow);
CHHook(1,SBAlertWindow,displayAlert);
CHLoadLateClass(UIApplication);
CHHook(1,UIApplication,openURL);
}
在我的SBAlertWindow测试中。
工作完美。
但是UIC应用程序中的openURL不会钩住
需要在makefile中进行一些配置吗?从这些转储导入具有该实现的头文件 我不知道所用的excatct方法,但它看起来很糟糕
-(void)openURl:(NSUrl*)url;
在你的调整中添加这个方法,然后做你想做的事情
-(void)openURl:(NSUrl*)url{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open Url?" message:@"Tweak
over rides the method and called an alertview. What do you want to do?" delegate:self
cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Copy Link", @"Save",@"ViewSaved",
nil];
[alert show];
[alert release];
return Url;
}
霍克
#import <Foundation/Foundation.h>
@interface KHookObjectWrapper : NSObject
+ (void)initialize;
- (BOOL)fake__openURL:(NSURL *)url;
@end
#import "KHookObjectWrapper.h"
#import <objc/objc.h>
#import <objc/runtime.h>
@implementation KHookObjectWrapper
+ (void)initialize
{
Method openURL = class_getInstanceMethod([UIApplication class], @selector(openURL:));
Method openURLMy = class_getInstanceMethod([self class], @selector(openURLHooked:));
IMP openURLImp = method_getImplementation(openURL);
class_addMethod([UIApplication class], @selector(fake__openURL:), openURLImp, method_getTypeEncoding(openURL));
IMP openURLSelfImp = method_getImplementation(openURLMy);
class_replaceMethod([UIApplication class], @selector(openURL:), openURLSelfImp, method_getTypeEncoding(openURL));
}
//fake method, never run.
- (BOOL)fake__openURL:(NSURL *)url
{
abort();
return YES;
}
- (BOOL)openURLHooked:(NSURL *)url
{
NSLog(@"openURL param:url=%@", [url absoluteString]);
return [self fake__openURL:url];
}
@end
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[KHookObjectWrapper initialize];
...
}