有没有办法让所有的类的列表从.dex文件? [英] Is there a way to get a list of all classes from a .dex file?

查看:245
本文介绍了有没有办法让所有的类的列表从.dex文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .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?

我在想<一href="http://www.jarvana.com/jarvana/view/com/google/android/tools/dx/1.7/dx-1.7-javadoc.jar!/com/android/dx/dex/file/DexFile.html"><$c$c>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 .

这篇关于有没有办法让所有的类的列表从.dex文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆