Skip to content

Instantly share code, notes, and snippets.

@MCMrARM
Created November 13, 2018 17:45
Show Gist options
  • Save MCMrARM/33a178daf05b6107ca08adb79ea643ac to your computer and use it in GitHub Desktop.
Save MCMrARM/33a178daf05b6107ca08adb79ea643ac to your computer and use it in GitHub Desktop.
public static void extractInfo(ClassLoader loader) throws Exception {
BaseDexClassLoader dexLoader = (BaseDexClassLoader) loader;
Field pathListField = BaseDexClassLoader.class.getDeclaredField("pathList");
pathListField.setAccessible(true);
Object pathList = pathListField.get(dexLoader);
Field dexElementsField = pathList.getClass().getDeclaredField("dexElements");
dexElementsField.setAccessible(true);
Object[] dexElements = (Object[]) dexElementsField.get(pathList);
Field elementFileField = null;
for (Object dexElement : dexElements) {
if (elementFileField == null) {
try {
elementFileField = dexElement.getClass().getDeclaredField("path");
} catch (NoSuchFieldException exception) {
elementFileField = dexElement.getClass().getDeclaredField("file");
}
}
elementFileField.setAccessible(true);
Log.i("ClassLoaderHelper", "Path list entry: " + elementFileField.get(dexElement));
}
Field nativeLibDirsField = pathList.getClass().getDeclaredField("nativeLibraryDirectories");
nativeLibDirsField.setAccessible(true);
List<File> nativeLibDirs = (List<File>) nativeLibDirsField.get(pathList);
for (File dir : nativeLibDirs) {
Log.i("ClassLoaderHelper", "Native path list entry: " + dir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment