我在使用 SIMBL 连接的外部应用程序中覆盖某些功能时遇到了一些很大的麻烦。
在这个应用程序中,有一个类 - 我们称之为“AppClass”。在这个类中有一个函数,
-(void)doSomething;
我从类转储二进制文件中得到了这个。整个接口定义为:
@interface AppClass : NSObject
{
}
我试图用 jr_swizzleMethod:withMethod:error 覆盖这个函数:
由于缺乏文档,这就是我想出的:
#import "JRSwizzle.h"
#import "AppClass.h"
@interface AppClass (MyPlugin)
- (void)myPlugin_doSomething;
@end
@implementation AppClass (MyPlugin)
- (void)myPlugin_doSomething {
NSLog(@"lol?");
}
@end
@implementation MyPlugin
+ (void) load {
Mylugin* plugin = [MyPlugin sharedInstance];
NSError *err = nil;
BOOL result = [NSClassFromString(@"AppClass") jr_swizzleMethod:@selector(doSomething) withMethod:@selector(myPlugin_doSomething) error:&err];
if(!result)
NSLog(@"<Plugin> Could not install events filter (error: %@)", err);
NSLog(@"Plugin installed");
}
+ (MyPlugin *)sharedInstance {
static MyPlugin* plugin = nil;
if(plugin == nil)
plugin = [[MyPlugin alloc] init];
return plugin;
}
@end
应该够了吧?但我在编译时收到此错误:
Undefined symbols:
"_OBJC_CLASS_$_AppClass", referenced from:
l_OBJC_$_CATEGORY_AppClass_$_MyPlugin in MyPlugin.o
objc-class-ref-to-AppClass in MyPlugin.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
我该如何解决这个问题?