如何将Android DEX(虚拟机字节码)文件反编译成相应的Java源代码?
当前回答
下载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.
其他回答
下载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逆向工程是可能的 . 按照以下步骤从apk文件中获取.java文件。
步骤1。使用dex2jar
从。apk文件生成。jar文件 命令:dex2jar sampleApp.apk
步骤2。使用JD-GUI反编译.jar
它会反编译。class文件,也就是说,我们会从apk中得到模糊的。java文件。
在使用dex2jar/apktool时,有时会出现坏代码,最明显的是在循环中。为了避免这种情况,可以使用jadx,它可以将dalvik字节码反编译成java源代码,而不需要像dex2jar那样先创建.jar/.class文件(我认为apktool使用dex2jar)。它也是开源的,正在积极开发中。它甚至有一个GUI,专为GUI爱好者设计。试一试!
因为Dheeraj Bhaskar的答案在很多年前就已经过时了。
以下是我最新的答案(2019年):
主逻辑
从dex到Java源代码,目前有两种解决方案:
一步:直接转换dex到java源代码 两步:首先将dex转换为jar,然后将jar转换为java源代码
一步解决方案:dex直接到java源代码
工具
jadx
过程
下载jadx-0.9.0.zip,解压,在bin文件夹中可以看到命令行jadx或GUI版本jadx- GUI,双击运行GUI版本:jadx- GUI
打开dex文件
然后可以显示Java源代码:
文件->保存为gradle项目
然后得到Java源代码:
两步解决方案
步骤1:dex到jar
工具
dex2jar
过程
下载dex2jar zip,解压得到d2j-dex2jar.sh,然后:
Apk到jar: sh d2j-dex2jar.sh -f ~/path/to/apk_to_decompile.apk .sh Dex to jar: sh d2j-dex2jar.sh -f ~/path/to/dex_to_decompile.dex
例子:
➜ v3.4.8 /Users/crifan/dev/dev_tool/android/reverse_engineering/dex-tools/dex-tools-2.1-SNAPSHOT/d2j-dex2jar.sh -f com.huili.readingclub8825612.dex
dex2jar com.huili.readingclub8825612.dex -> ./com.huili.readingclub8825612-dex2jar.jar
➜ v3.4.8 ll
-rw------- 1 crifan staff 9.5M 3 21 10:00 com.huili.readingclub8825612-dex2jar.jar
-rw------- 1 crifan staff 8.4M 3 19 14:04 com.huili.readingclub8825612.dex
Step2: jar到java源代码
工具
Jd-gui:最流行的,但许多代码会反编译错误 CRF:流行,次要代码会反编译错误 Procyon:流行,没有代码反编译错误 基于Procyon的GUI工具 Luyten: 字节码查看器 其他人 喀拉喀托火山 Fernflower 旧的:AndroChef 等。
过程
这里演示Procyon转换jar到java源代码:
下载procyon-decompiler-0.5.34.jar
然后使用语法:
java -jar /path/to/procyon-decompiler-0.5.34.jar -jar your_to_decompile.jar -o outputFolderName .jar
例子:
java -jar /Users/crifan/dev/dev_tool/android/reverse_engineering/Procyon/ Procyon -decompiler-0.5.34.jar -jar com.huili.readingclub8825612-dex2jar.jar -o com.huili.readingclub8825612
使用编辑器VSCode打开导出的源代码,如下所示:
结论
转换正确性:Jadx > Procyon > CRF > JD-GUI
推荐使用:(一步解决方案)Jadx
for more detailed explanation, please refer my online Chinese ebook: Security and Cracking of Android Apps
这可以通过以下五个步骤来完成:
这个gem自动为您完成这些工作,甚至安装所需的工具
将apk文件转换为zip 解压缩文件 从中提取classes.dex 使用dex to jar将classes.dex转换为jar文件 使用jadx GUI打开jar文件作为Java源代码
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 碎片中的onCreateOptionsMenu
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?