代碼如下
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()); }