源代码:
private static List<String> allSOLists = new ArrayList<String>();/** * 获取全部已加载的SO库*/private void getAllSOLoaded(){allSOLists.clear();// 当前应用的进程IDint pid = Process.myPid();String path = "/proc/" + pid + "/maps";File file = new File(path);if(file.exists() && file.isFile()){readFileByLines(file.getAbsolutePath());} else {Log.e("DAVIS", "不存在[" + path + "]文件.");}StringBuilder sb = new StringBuilder();for(int i=0;i<allSOLists.size();i++){sb.append(allSOLists.get(i) + "\n");}Log.e("DAVIS", sb.toString());}/** * 获取当前应用已加载的SO库*/private void getCurrSOLoaded(){allSOLists.clear();// 当前应用的进程IDint pid = Process.myPid();String path = "/proc/" + pid + "/maps";File file = new File(path);if(file.exists() && file.isFile()){readFileByLines(file.getAbsolutePath());} else {Log.e("DAVIS", "不存在[" + path + "]文件.");}StringBuilder sb = new StringBuilder();for(int i=0;i<allSOLists.size();i++){if(allSOLists.get(i).startsWith("/data/app/")) {sb.append(allSOLists.get(i) + "\n");}}Log.e("DAVIS", sb.toString());}/*** 以行为单位读取文件,常用于读面向行的格式化文件*/public static void readFileByLines(String fileName) {File file = new File(fileName);BufferedReader reader = null;try {reader = new BufferedReader(new FileReader(file));String tempString = null;// 一次读入一行,直到读入null为文件结束while ((tempString = reader.readLine()) != null) {if(tempString.endsWith(".so")) {int index = tempString.indexOf("/");if(index != -1){String str = tempString.substring(index);// 所有so库(包括系统的,即包含/system/目录下的)allSOLists.add(str);}}}reader.close();} catch (Exception e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e1) {}}}}
输出日志
全部已加载的SO库:
/vendor/lib64/hw/gralloc.kirin710.so/vendor/lib64/hw/gralloc.kirin710.so/vendor/lib64/hw/gralloc.kirin710.so/system/lib64/vndk-sp-28/libion.so/system/lib64/vndk-sp-28/libion.so/system/lib64/vndk-sp-28/libion.so/vendor/lib64/libhiion.so/vendor/lib64/libhiion.so/vendor/lib64/libhiion.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so/system/lib64/libhwetrace_jni.so/system/lib64/libhwetrace_jni.so/system/lib64/libhwetrace_jni.so/system/lib64/vndk-sp-28/liblzma.so/system/lib64/vndk-sp-28/liblzma.so/system/lib64/vndk-sp-28/liblzma.so/vendor/lib64/egl/libGLES_mali.so/vendor/lib64/egl/libGLES_mali.so/vendor/lib64/egl/libGLES_mali.so/system/lib64/vndk-sp-28/libz.so/system/lib64/vndk-sp-28/libz.so/system/lib64/vndk-sp-28/libz.so/vendor/lib64/libc_secshared.so/vendor/lib64/libc_secshared.so/vendor/lib64/libc_secshared.so/system/lib64/vndk-sp-28/libutilscallstack.so/system/lib64/vndk-sp-28/libutilscallstack.so/system/lib64/vndk-sp-28/libutilscallstack.so/system/lib64/vndk-sp-28/libbacktrace.so/system/lib64/vndk-sp-28/libbacktrace.so/system/lib64/vndk-sp-28/libbacktrace.so/system/lib64/vndk-sp-28/libunwindstack.so/system/lib64/vndk-sp-28/libunwindstack.so/system/lib64/vndk-sp-28/libunwindstack.so/system/lib64/vndk-sp-28/libunwind.so/system/lib64/vndk-sp-28/libunwind.so/system/lib64/vndk-sp-28/libunwind.so/system/lib64/libwebviewchromium_loader.so/system/lib64/libwebviewchromium_loader.so/system/lib64/libwebviewchromium_loader.so/system/lib64/libcompiler_rt.so/system/lib64/libcompiler_rt.so/system/lib64/libcompiler_rt.so/system/lib64/vndk-sp-28/libutils.so/system/lib64/vndk-sp-28/libutils.so/system/lib64/vndk-sp-28/libutils.so/system/lib64/vndk-sp-28/libbase.so/system/lib64/vndk-sp-28/libbase.so/system/lib64/vndk-sp-28/libbase.so/system/lib64/vndk-sp-28/libcutils.so/system/lib64/vndk-sp-28/libcutils.so/system/lib64/vndk-sp-28/libcutils.so/system/lib64/vndk-sp-28/libhidlbase.so/system/lib64/vndk-sp-28/libhidlbase.so/system/lib64/vndk-sp-28/libhidlbase.so/system/lib64/vndk-sp-28/android.hardware.graphics.common@1.0.so/system/lib64/vndk-sp-28/android.hardware.graphics.common@1.0.so/system/lib64/vndk-sp-28/android.hardware.graphics.common@1.0.so/vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so/vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so/vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so/system/lib64/vndk-sp-28/libhidltransport.so/system/lib64/vndk-sp-28/libhidltransport.so/system/lib64/vndk-sp-28/libhidltransport.so/system/lib64/vndk-sp-28/android.hardware.graphics.mapper@2.0.so/system/lib64/vndk-sp-28/android.hardware.graphics.mapper@2.0.so/system/lib64/vndk-sp-28/android.hardware.graphics.mapper@2.0.so/system/lib64/vndk-sp-28/libhardware.so/system/lib64/vndk-sp-28/libhardware.so/system/lib64/vndk-sp-28/libhardware.so/system/lib64/vndk-sp-28/libc++.so/system/lib64/vndk-sp-28/libc++.so/system/lib64/vndk-sp-28/libc++.so/system/lib64/vndk-sp-28/libhwbinder.so/system/lib64/vndk-sp-28/libhwbinder.so/system/lib64/vndk-sp-28/libhwbinder.so/system/lib64/libiAwareSdk_jni.so/system/lib64/libiAwareSdk_jni.so/system/lib64/libiAwareSdk_jni.so/system/lib64/libjavacrypto.so/system/lib64/libjavacrypto.so/system/lib64/libjavacrypto.so/system/lib64/libsoundpool.so/system/lib64/libsoundpool.so/system/lib64/libsoundpool.so/system/lib64/libmedia_jni.huawei.so/system/lib64/libmedia_jni.huawei.so/system/lib64/libmedia_jni.huawei.so/system/lib64/libhwlog_jni.so/system/lib64/libhwlog_jni.so/system/lib64/libhwlog_jni.so/system/lib64/libhwaps.so/system/lib64/libhwaps.so/system/lib64/libhwaps.so
当前应用已加载的SO库:
/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libNativeCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so/data/app/com.tsb-eMBG4MWSQgAzpqckdwC7cQ==/lib/arm64/libCloudwiseCrash.so