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

后端 未结 5 610

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 class

5条回答
  •  难免孤独
    2021-01-30 17:13

    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 .

提交回复
热议问题