有没有办法让所有的类的列表从.dex文件?有的、没有办法、文件、列表

2023-09-04 23:52:50 作者:奔赴陷阱.

我有一个 .dex 文件,把它叫做 classes.dex

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

有没有办法来读中的内容 classes.dex ,并得到所有类别的列表在那里为完整的类名,包括他们的包, com.mypackage.mysubpackage.MyClass ,为〔实施例?

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?

我在想com.android.dx.dex.file.DexFile,但我似乎无法找到检索整个组类的方法。

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.

推荐答案

您可以使用的 dexlib2库作为一个独立的库(的提供行家),读取DEX文件,并得到类的列表。

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());
}

请注意,类名会的形式为Ljava /朗/字符串;,这是他们是如何存储在DEX文件(在Java类文件)。要转换,只是删除了第一个和最后一个字母,并替换/。

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 .

 
精彩推荐
图片推荐