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

I have a .dex file, name it classes.dex .

Is there a way to β€œread” the contents of this classes.dex and get a list of all the classes in it as the full names of the classes, including their package, com.mypackage.mysubpackage.MyClass , for exmaple?

I was thinking about com.android.dx.dex.file.DexFile , but I cannot find a way to retrieve the entire set of classes.

+42
java android class dex dx
Jul 05 '12 at 11:28
source share
4 answers

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()) { System.out.println(classDef.getType()); } 

Note that the class names will be of the form "Ljava / lang / String;", which is stored in the dex file (and in the java class file). To convert, simply delete the first and last letter and replace / s.

+11
Jul 05 2018-12-18T00:
source share
β€” -

Use the dexdump command line dexdump from the Android SDK. This is at $ANDROID_HOME/build-tools/<some_version>/dexdump . It prints a lot more information than you probably want. I did not find a way to make dexdump less verbose, but

 dexdump classes.dex | grep 'Class descriptor' 

must work.

+90
Aug 25 '13 at 11:32
source share

You can use the dex2jar utility, which converts .dex to .jar.

http://code.google.com/p/dex2jar/

Then you can extract this .jar file.

You can also use this infrastructure.

Dedexer

+11
Jul 05 2018-12-12T00:
source share

baksmali has functionality for this, starting with baksmali v2.2.

baksmali list classes my.dex print a list of all classes in this dex file.

+1
Sep 11 '17 at 18:22
source share



All Articles