如何检测其本地共享库是由Android应用程序加载 [英] How to detect which native shared libraries are loaded by Android application
问题描述
我的应用程序使用本机共享库(。所以),我通过调用加载的System.loadLibrary(XXX)
。它加载很好,我可以调用本地方法。
My application uses native shared library (.so), I am loading it by calling System.loadLibrary("xxx")
. It loads fine and I can call the native methods.
我不知道是否有任何可能性,以检测哪些共享库的应用程序使用。我试图通过PackageManager列出加载的库:
I wonder if there is any possibility to detect which shared libraries application uses. I tried to list loaded libraries by PackageManager:
PackageManager pm = getPackageManager();
String applicationPackage = this.getApplicationInfo().packageName;
ApplicationInfo ai = pm.getApplicationInfo(applicationPackage, PackageManager.GET_SHARED_LIBRARY_FILES);
String[] soFiles = ai.sharedLibraryFiles;
但它返回一个空列表。它的工作原理只有在我的应用程序使用了一些的.jar库,比如我用指定com.google.android.maps使用库
在清单中的应用程序标签。
but it returns an empty list. It works only if my application uses some .jar libraries like com.google.android.maps which I specify by uses-library
in the application tag of the manifest.
我如何列出的.so库?
How can I list .so libraries?
推荐答案
解决方法很简单,非常感谢@执政官 - 机器人
The solution is simple, many thanks to @ praetorian-droid
try {
Set<String> libs = new HashSet<String>();
String mapsFile = "/proc/" + android.os.Process.myPid() + "/maps";
BufferedReader reader = new BufferedReader(new FileReader(mapsFile));
String line;
while ((line = reader.readLine()) != null) {
if (line.endsWith(".so")) {
int n = line.lastIndexOf(" ");
libs.add(line.substring(n + 1));
}
}
Log.d("Ldd", libs.size() + " libraries:");
for (String lib : libs) {
Log.d("Ldd", lib);
}
} catch (FileNotFoundException e) {
// Do some error handling...
} catch (IOException e) {
// Do some error handling...
}
这篇关于如何检测其本地共享库是由Android应用程序加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!