简体   繁体   English

有没有办法从 a.dex 文件中获取所有类的列表?

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

I have a .dex file, call it classes.dex .我有一个.dex文件,称之为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?有没有办法“读取” classes.dex的内容并获取其中所有类的列表作为完整的类名,包括它们的包com.mypackage.mysubpackage.MyClass ,例如?

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.我在考虑com.android.dx.dex.file.DexFile ,但我似乎找不到检索整组类的方法。

Use the command line tool dexdump from the Android-SDK.使用 Android-SDK 中的命令行工具dexdump It's in $ANDROID_HOME/build-tools/<some_version>/dexdump .它在$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不那么冗长的方法,但是

dexdump classes.dex | grep 'Class descriptor'

should work.应该管用。

You can use the dexlib2 library as a standalone library ( available in maven ), to read the dex file and get a list of classes.您可以将dexlib2 库用作独立库( 在 maven 中可用),以读取 dex 文件并获取类列表。

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).请注意,类名的格式为“Ljava/lang/String;”,这是它们在 dex 文件(和 java 类文件)中的存储方式。 To convert, just remove the first and last letter, and replace / with.要转换,只需删除第一个和最后一个字母,并将 / 替换为。

You can use dex2jar utility that will convert .dex to .jar.您可以使用dex2jar实用程序将.dex转换为.jar.

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

Then you can extract that .jar file.然后您可以提取该.jar文件。

Also, you can use this framework另外,您可以使用此框架

Dedexer去索引器

baksmali has functionality to do this starting in baksmali v2.2.从 baksmali v2.2 开始,baksmali 具有执行此操作的功能。

baksmali list classes my.dex will print a list of all classes in the given dex file. baksmali list classes my.dex将打印给定 dex 文件中所有类的列表。

Reference: It is downloadable from here: https://github.com/JesusFreke/smali .参考:可从此处下载: https ://github.com/JesusFreke/smali。

dxshow mydexfile.dex dxshow mydex文件.dex

dxshow: dxshow:

strings -a $1 |字符串 -a $1 | grep "^L.*/" | grep "^L.*/" | grep -v "Ljava" | grep -v “Ljava” | grep -v "Landroid" | grep -v “机器人” | sed "s/^L\(.*\);/\1/" | sed "s/^L\(.*\);/\1/" | sed "s:/:.:g" sed "s:/:.:g"

ezpz hack... didn't wanna spend a lifetime java coding ezpz hack...不想花一生的时间编写 Java 代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM