【求助】通过fishhook,hook'_NSDictionaryOfVariableBindings'函数编译不过


#1

code

static id ori__NSDictionaryOfVariableBindings(NSString *commaSeparatedKeysString, __nullable id firstValue, ...);

static id new__NSDictionaryOfVariableBindings(NSString *commaSeparatedKeysString, __nullable id firstValue, ...){
    va_list args;
    va_start(args, firstValue);
    
    va_end(args);
    return nil;
}
__attribute__((constructor)) static void _wsApplicationConstructorCallback() {
    rebind_symbols((struct rebinding[1]){{"__NSDictionaryOfVariableBindings", new__NSDictionaryOfVariableBindings, (void*)&ori__NSDictionaryOfVariableBindings}},1);
  
}

编译错误提示如下:

_ori__NSDictionaryOfVariableBindings
Undefined symbols for architecture arm64:
  "_ori__NSDictionaryOfVariableBindings", referenced from:
      l_constinit in WSLaunchDetector.o
ld: symbol(s) not found for architecture arm64

这种问题有哪位大佬了解么?
如果去掉rebind_symbols((struct rebinding[1]){{"__NSDictionaryOfVariableBindings", new__NSDictionaryOfVariableBindings, (void*)&ori__NSDictionaryOfVariableBindings}},1);这句,也就是不用fishhook就可以编译过。


#2

你要声明成函数指针啊大兄弟


#3

嗯嗯,是的,验证没问题,感谢。


#4

代码改成这样,可以编译过:

static NSDictionary * (*ori__NSDictionaryOfVariableBindings)(NSString *commaSeparatedKeysString, __nullable id firstValue, ...);

static NSDictionary * new__NSDictionaryOfVariableBindings(NSString *commaSeparatedKeysString, __nullable id firstValue, ...){
    va_list args;
    va_start(args, firstValue);
    
    va_end(args);
    return nil;
}

...

rebind_symbols((struct rebinding[1]){{"__NSDictionaryOfVariableBindings", new__NSDictionaryOfVariableBindings, (void*)&ori__NSDictionaryOfVariableBindings}},1);

但是还是hook不到这个函数
UIKIT_EXTERN NSDictionary *_NSDictionaryOfVariableBindings(NSString *commaSeparatedKeysString, __nullable id firstValue, ...) NS_AVAILABLE_IOS(6_0);

内部函数是这个

为什么会这样捏?


#5

你确定这个函数被直接调用了吗


#6

fishhook只能hook被直接调用的外部函数