Lopina Lopina - 7 months ago 49
Java Question

Is there a way to get a list of all classes from a .dex file?

I have a

file, call it

Is there a way to "read" the contents of that
and get a list of all classes in there as full class names, including their package,
, for exmaple?

I was thinking about
, but I cannot seem to find a method for retrieving an entire set of classes.


You can use the dexlib2 library as a standalone library (available in maven), to read the dex file and get a list of classes.

DexFile dexFile = DexFileFactory.loadDexFile("classes.dex", 19 /*api level*/);
for (ClassDef classDef: dexFile.getClasses()) {

Note that the class names will be of the form "Ljava/lang/String;", which is how they are stored in the dex file (and in a java class file). To convert, just remove the first and last letter, and replace / with .