Skip to content

Instantly share code, notes, and snippets.

@kmark
Last active January 14, 2024 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmark/17f9a211bdca9f5a50ed to your computer and use it in GitHub Desktop.
Save kmark/17f9a211bdca9f5a50ed to your computer and use it in GitHub Desktop.
Explores the current Android classpath
try {
PathClassLoader pcl = (PathClassLoader) Thread.currentThread().getContextClassLoader();
Field f = Class.forName("dalvik.system.BaseDexClassLoader").getDeclaredField("pathList");
f.setAccessible(true);
Object dpl = f.get(pcl);
Class cls = Class.forName("dalvik.system.DexPathList");
Field f2 = cls.getDeclaredField("dexElements");
f2.setAccessible(true);
Object[] elements = (Object[])f2.get(dpl);
for(Object e : elements) {
cls = Class.forName("dalvik.system.DexPathList$Element");
Field f3 = cls.getDeclaredField("dexFile");
f3.setAccessible(true);
DexFile df = (DexFile)f3.get(e);
Enumeration<String> entries = df.entries();
while(entries.hasMoreElements()) {
String entry = entries.nextElement();
Log.e("OH NOEZ", "Entry: " + entry);
}
}
} catch (Exception ex) {
Log.wtf("WTF", ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment