用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