I have some great troubles overriding some functions in an external App that I use SIMBL to hook in to.
In this app, there is a class - let's call it "AppClass". In this class there is a function,
-(void)doSomething;
I got this from class-dumping the Binary. the whole interface is defined as:
@interface AppClass : NSObject
{
}
I'm trying to override this function with jr_swizzleMethod:withMethod:error:
With the lack of documentation, this is what I have come up with:
#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
That should be enough right? But I get this error on compile:
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
How do I solve this?
You're creating a plugin, which refers to symbols in a binary (the app you're trying to extend). Therefore, you need to tell the linker where to look for those symbols (In your case, that's _OBJC_CLASS_$_AppClass
, i.e. AppClass
that's defined in the binary.
).
This is done by passing the option -bundle_loader executable_name
to the linker. See the man page for ld.
来源:https://stackoverflow.com/questions/4152907/simbl-with-method-swizzling