Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

I was thinking about com.android.dx.dex.file.DexFile, but I cannot seem to find a method for retrieving an entire set of classes.

like image 257
ioreskovic Avatar asked Jul 05 '12 11:07

ioreskovic


People also ask

How do I read a .DEX file?

If you cannot open your DEX file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a DEX file directly in the browser: Just drag the file onto this browser window and drop it.

What is the significance of .DEX file?

A Dex file contains code which is ultimately executed by the Android Runtime. Every APK has a single classes. dex file, which references any classes or methods used within an app.

Is classes DEX file readable?

Both . class files and . dex files are not readable. However, one can create readable instruction sets by executing sequence of commands.

What is Classes dex file in android?

The classes. dex file is a Dalvik Executable file that all Android applications must have. This file contains the Java libraries that the application uses. When you deploy an application for Android, RAD Studio includes a classes. dex file that contains the RAD Studio built-in Java libraries.


2 Answers

Use the command line tool dexdump from the Android-SDK. It's in $ANDROID_HOME/build-tools/<some_version>/dexdump. It prints a lot more info than you probably want. I didn't find a way to make dexdump less verbose, but

dexdump classes.dex | grep 'Class descriptor' 

should work.

like image 76
3 revs, 3 users 75% Avatar answered Sep 23 '22 14:09

3 revs, 3 users 75%


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 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 .

like image 38
JesusFreke Avatar answered Sep 23 '22 14:09

JesusFreke