android 7.0获取soinfo

烂笔头

7.0开始不再允许获取soinfo对象,贴一下大概流程以及依据:
6.0:
dlopen -> dlopen_ext:返回soinfo* result = do_dlopen(filename, flags, extinfo);
->do_dlopen:soinfo* si = find_library(name, flags, extinfo);return si;

7.0:
dlopen -> dlopen_ext:返回void* result = do_dlopen(filename, flags, extinfo, caller_addr);
->do_dlopen:
soinfo* si = find_library(ns, translated_name, flags, extinfo, caller);
return si->to_handle();

to_handle() -> 判断版本号,调用get_handle()
get_handle() -> 返回handle_
handle_ -> 定义在struct soinfo结构体中,类型为 uintptr_t.


参考地址

获取方法

    LibraryReader *libraryReader = new LibraryReader("/system/bin/linker");
    void *soinfo_handles_map = reinterpret_cast(libraryReader->get_symbol_address(
            "__dl__ZL20g_soinfo_handles_map"));
    std::unordered_map *g_soinfo_handles_map = (std::unordered_map *) soinfo_handles_map;
    void *handle = dlopen("/system/lib/libc++.so", 0);
    auto it = g_soinfo_handles_map->find((uintptr_t) handle);

    void *soinfo = it->second;
    LogHex::DumpHexByPrintf(soinfo, 256);

内存打印

image.png

你可能感兴趣的:(android 7.0获取soinfo)