Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 带方法Swizzling的SIMBL_Macos_Simbl_Swizzling - Fatal编程技术网

Macos 带方法Swizzling的SIMBL

Macos 带方法Swizzling的SIMBL,macos,simbl,swizzling,Macos,Simbl,Swizzling,我在重写使用SIMBL连接的外部应用程序中的某些函数时遇到了一些大麻烦 在这个应用程序中,有一个类——我们称它为“AppClass”。在这个类中有一个函数 -(void)doSomething; 我是从课堂上扔掉二进制文件得到的。整个接口定义为: @interface AppClass : NSObject { } 我试图用jr_swizzleMethod:withMethod:error覆盖此函数: 由于缺乏文档,我得出以下结论: #import "JRSwizzle.h"

我在重写使用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

如何解决这个问题?

您正在创建一个插件,它引用二进制文件中的符号(您试图扩展的应用程序)。因此,您需要告诉链接器在哪里查找这些符号(在您的例子中,这是
\u OBJC\u CLASS\u$\u AppClass
,即在二进制文件中定义的
AppClass
)。 )


这是通过将选项
-bundle\u loader executable\u name
传递给链接器来完成的。请参阅。

谢谢您的回复。我尝试将其添加到其他\u LDFLAGS-bundle\u loader/Path/to/Binary中,但出现了相同的错误。把这个ld放在XCode中是不是错了?事实上,错误是当二进制链接为x86I时,库被编译为x86_64。我现在还有一些其他问题。我正在尝试重写一个类方法,但jr_Swizzle方法返回:Error Domain=nscocaerorDomain Code=-1 UserInfo=0x13911f90“+[NSObject(JRSwizzle)jr_Swizzle方法:withMethod:Error::原始方法notifyWithTitle:description:notificationName:iconData:priority:isSticky:clickContext:找不到类GrowlApplication Bridge”。定义就在这里,只是它是一个类方法:+(void)notifyWithTitle:……类方法是元类的实例方法。您应该将
NSClassFromString(@“SomeClass”)
替换为
objc\u getMetaClass(“SomeClass”)
。您需要包括
。要了解更多信息,请阅读。
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