如何将Android DEX(虚拟机字节码)文件反编译成相应的Java源代码?
当前回答
最近Debian有Python包androguard:
Description-en: full Python tool to play with Android files
Androguard is a full Python tool to play with Android files.
* DEX, ODEX
* APK
* Android's binary xml
* Android resources
* Disassemble DEX/ODEX bytecodes
* Decompiler for DEX/ODEX files
安装相应的软件包:
sudo apt-get install androguard python-networkx
反编译DEX文件:
$ androdd -i classes.dex -o ./dir-for-output
从Apk +反编译中提取classes.dex:
$ androdd -i app.apk -o ./dir-for-output
Apk文件就是Java的JAR文件,你可以通过以下方法从JAR文件中提取文件:
$ unzip app.apk -d ./dir-for-output
其他回答
如果您不打算下载dex2jar,那么只需使用apk_grabber python脚本将任何apk反编译到jar文件中。然后使用jd-gui读取它们。
由于没有人提到这一点,还有一个工具:DED主页
安装指南和一些说明:安装。
它被用于一个非常有趣的关于顶级市场应用程序安全性的研究(不是真的相关,如果你好奇的话):Android应用程序安全性调查
需要澄清的是,根据你想要实现的目标,你可以采取两种主要的方法:
将Dalvik字节码(dex)反编译为可读的Java源代码。正如fred提到的,使用dex2jar和jd-gui可以很容易地做到这一点。得到的源代码对于阅读和理解应用程序的功能是有用的,但可能不会产生100%可用的代码。换句话说,您可以读取源代码,但不能真正地修改和重新打包它。请注意,如果源代码使用proguard进行了混淆,那么最终的源代码将更加难以理清。
The other major alternative is to disassemble the bytecode to smali, an assembly language designed for precisely this purpose. I've found that the easiest way to do this is with apktool. Once you've got apktool installed, you can just point it at an apk file, and you'll get back a smali file for each class contained in the application. You can read and modify the smali or even replace classes entirely by generating smali from new Java source (to do this, you could compile your .java source to .class files with javac, then convert your .class files to .dex files with Android's dx compiler, and then use baksmali (smali disassembler) to convert the .dex to .smali files, as described in this question. There might be a shortcut here). Once you're done, you can easily package the apk back up with apktool again. Note that apktool does not sign the resulting apk, so you'll need to take care of that just like any other Android application.
如果你走的是一条小路线,你可能想尝试APK Studio,它是一个IDE,可以自动执行上面的一些步骤,帮助你反编译和重新编译APK,并将其安装到设备上。
简而言之,你的选择是要么反编译成Java,后者可读性更强,但可能不可逆;要么反汇编成smalli,后者更难阅读,但更灵活地进行更改和重新打包修改后的应用。你选择哪种方法取决于你想要实现的目标。
最后,大胆的建议也是值得注意的。这是一个重新定位的工具,可以将.dex和.apk文件转换为java .class文件,这样就可以使用典型的java静态分析工具来分析它们。
很容易
获取这些工具:
Dex2jar将dex文件转换为jar文件 以查看jar中的Java文件
源代码可读性很强,因为dex2jar做了一些优化。
过程:
下面是如何反编译的过程:
步骤1:
将test_apk-debug.apk中的classes.dex转换为test_apk-debug_dex2jar.jar
d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk
d2j-dex2jar.sh -f -o output_jar.jar dex_to_decompile.dex
注1:在Windows机器中,所有的.sh脚本都被.bat脚本取代
注2:在linux/mac上不要忘记sh或bash。完整的命令应该是:
sh d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk
注意3:另外,请记住向dex2jar-X添加执行权限。例如sudo chmod -R + X dex2jar-2.0
dex2jar文档
步骤2:
在JD-GUI中打开罐子
下载APK文件后,您需要执行以下步骤以获得可编辑的java代码/文档。
Convert your apk file to zip (while start your download don't go with "save" option , just go with "save as" and mention your extension as .zip) by doing like this you may avoid APKTOOL... Extract the zip file , there you can find somefilename.dex. so now we need to convert dex -> .class To do that, you need "dex2jar"(you can download it from http://code.google.com/p/dex2jar/ , after extracted, in command prompt you have to mention like, [D:\dex2jar-0.09>dex2jar somefilename.dex] (Keep in mind that your somefilename.dex must be inside the same folder where you have keep your dex2jar.) Download jad from http://www.viralpatel.net/blogs/download/jad/jad.zip and extract it. Once extracted you can see two files like "jad.exe" and "Readme.txt" (sometimes "jad.txt" may there instead of "jad.exe", so just rename its extension as.exe to run) Finally, in command prompt you have to mention like [D:\jad>jad -sjava yourfilename.class] it will parse your class file into editable java document.
推荐文章
- Android Studio, logcat在应用程序关闭后清理
- Intellij IDEA Java类在保存时不能自动编译
- 何时使用Mockito.verify()?
- 在maven中安装mvn到底做什么
- 在android中从上下文获取活动
- 不可变与不可修改的集合
- 如何在JSON中使用杰克逊更改字段名
- GSON -日期格式
- 如何从线程捕获异常
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 如何在Java中打印二叉树图?
- 按钮背景是透明的
- String.format()在Java中格式化双重格式
- 在Mac OS X上哪里安装Android SDK ?