美文网首页iOS程序猿
symdl :一个可以替代dlsym的小工具

symdl :一个可以替代dlsym的小工具

作者: 知水为命 | 来源:发表于2019-05-30 16:34 被阅读121次

  前面已经写了几篇文章介绍MangoFix了,一个语法和Objective-C非常相似的SDL,用来对iOS App进行热修复。但是MangoFix1.x版本中对于需要用到的C函数要进行预埋,而哪些C函数需要进行预埋,这其实是不可预测的。所以MangoFix在2.0中会添加 C函数声明即用功能,这就需要用到dlsym函数,但是使用了这个函数后在App Store是审核不过的,所以最近写了一个小工具,功能和dlsym一样,即通过动态链接的C函数名字符串,获取函数指针。这个小工具就是:symdl。 GitHub地址:https://github.com/YPLiang19/symdl

\color{red}{注意:是非常不建议利用symdl动态加载一些Apple 的私有函数!!!!}

下面就是对symdl的介绍:

symdl

symdl is a simple little tool, its function is very similar to dlsym, with symdl, you can pass in the dynamic linked C function name string, get the function pointer, so as to achieve the dynamic call of C function.

Example

 #import <symdl/symdl.h>
#import <dlfcn.h>

int main(){
    typedef  void * (*MyFunc)(const char *__path, int __mode);
    
    const char *func_name = "dlopen";
    MyFunc dlopen_ptr = symdl(func_name);
    if (dlopen_ptr) {
        dlopen_ptr("your path",RTLD_LAZY);
    }
}

Installation

CocoaPods

  1. Add pod 'symdl' to your Podfile.
  2. Run pod install or pod update.
  3. Import <symdl/symdl.h>

相关文章

网友评论

    本文标题:symdl :一个可以替代dlsym的小工具

    本文链接:https://www.haomeiwen.com/subject/tkuvtctx.html