用dlopen,dlsym加载动态链接库.so中函数


代码如下

static void *findSymbol(const char *path, const char *symbol) {
    void *handle = dlopen(path, RTLD_LAZY);
    if(!handle) {
        LOGE("handle %s is null", path);
        return NULL;
    }

    //Cydia::MSHookFunction(void *,void *,void **)
    void *target = dlsym(handle, symbol);
    if(!target) {
        LOGE("symbol %s is null", symbol);
    }
    return target;
}

void *target = findSymbol("libc.so", "__system_property_get");

dlopen打开失败:

dlopen第三方动态库时经常会发生打开失败的错误,可以适用dlerror()函数查看具体错误:

void *dlh;  
dlh = dlopen("libdes3-32.so", RTLD_NOW | RTLD_GLOBAL);  
if (dlh == NULL)  
{  
      printf("dlopen err:%s.\n",dlerror());  
}  

  

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM