android不通过proc获取应用的so的addr
时间: 2023-12-06 15:39:31 浏览: 127
在 Android 中,可以通过 `dladdr()` 函数获取一个共享库(包括应用程序的 so 文件)中某个符号的地址,从而获取应用的 so 的地址。
以下是一个示例代码:
```c++
#include <dlfcn.h>
#include <cstdio>
void* GetSoAddr(const char* soPath) {
void* handle = dlopen(soPath, RTLD_NOW);
if (handle == nullptr) {
fprintf(stderr, "Failed to open %s: %s\n", soPath, dlerror());
return nullptr;
}
void* addr = dlsym(handle, "JNI_OnLoad");
if (addr == nullptr) {
fprintf(stderr, "Failed to get symbol address: %s\n", dlerror());
}
dlclose(handle);
return addr;
}
int main(int argc, char* argv[]) {
const char* soPath = "/data/app/com.example.app/lib/arm64/libnative-lib.so";
void* soAddr = GetSoAddr(soPath);
if (soAddr != nullptr) {
printf("The address of %s is %p\n", soPath, soAddr);
}
return 0;
}
```
该示例代码中,通过 `dlopen()` 函数打开应用的 so 文件,然后通过 `dlsym()` 函数获取其中的 `JNI_OnLoad` 符号的地址。最后通过 `dlclose()` 函数关闭 so 文件的句柄。注意,在 Android 中,应用程序的 so 文件通常位于 `/data/app/<package_name>/lib/<cpu_arch>/` 目录下,因此需要根据实际情况自行修改 `soPath` 变量。
阅读全文
相关推荐












