SIMBL方法混乱 [英] SIMBL with Method Swizzling
问题描述
在使用SIMBL连接的外部应用程序中,我在覆盖某些功能方面遇到了很大的麻烦.
I have some great troubles overriding some functions in an external App that I use SIMBL to hook in to.
在此应用中,有一个类-我们将其称为"AppClass".此类中有一个函数,
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
{
}
我正在尝试使用jr_swizzleMethod:withMethod:error覆盖此功能:
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
我该如何解决?
推荐答案
您正在创建一个插件,该插件引用二进制文件(您要扩展的应用程序)中的符号.因此,您需要告诉链接器在哪里寻找这些符号(在您的情况下为_OBJC_CLASS_$_AppClass
,即在二进制文件中定义的AppClass
.
).
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.
).
这是通过将选项-bundle_loader executable_name
传递给链接器来完成的.请参见 ld的手册页.
This is done by passing the option -bundle_loader executable_name
to the linker. See the man page for ld.
这篇关于SIMBL方法混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!