decompiling DEX into Java sourcecode

后端 未结 17 1437
情歌与酒
情歌与酒 2020-11-22 12:41

How can one decompile Android DEX (VM bytecode) files into corresponding Java sourcecode?

17条回答
  •  礼貌的吻别
    2020-11-22 13:12

    Since Dheeraj Bhaskar's answer is relatively old as many years past.

    Here is my latest (2019 year) answer:

    Main Logic

    from dex to java sourcecode, currently has two kind of solution:

    • One Step: directly convert dex to java sourcecode
    • Two Step: first convert dex to jar, second convert jar to java sourcecode

    One step solution: dex directly to java sourcecode

    Tools

    • jadx

    Process

    1. download jadx-0.9.0.zip, unzip it, in bin folder can see command line jadx or GUI version jadx-gui, double click to run GUI version: jadx-gui

    1. open dex file

    then can show java source code:

    1. File -> save as gradle project

    then got java sourcecode:


    Two Step solution

    Step1: dex to jar

    Tools

    • dex2jar

    Process

    download dex2jar zip, unzip got d2j-dex2jar.sh, then:

    • apk to jar: sh d2j-dex2jar.sh -f ~/path/to/apk_to_decompile.apk
    • dex to jar: sh d2j-dex2jar.sh -f ~/path/to/dex_to_decompile.dex

    example:

    ➜  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 to java sourcecode

    Tools

    • jd-gui: most popular, but many code will decompile error
    • CRF: popular, minor code will decompile error
    • Procyon: popular, no code decompile error
      • GUI tool based on Procyon
        • Luyten:
        • Bytecode Viewer
    • others
      • Krakatau
      • Fernflower
      • old one: AndroChef
      • etc.

    Process

    here demo Procyon convert jar to java source code:

    download procyon-decompiler-0.5.34.jar

    then using syntax:

    java -jar /path/to/procyon-decompiler-0.5.34.jar -jar your_to_decompile.jar -o outputFolderName

    example:

    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

    using editor VSCode to open exported source code, look like this:

    Conclusion

    Conversion correctness : Jadx > Procyon > CRF > JD-GUI

    Recommend use: (One step solution's) Jadx


    for more detailed explanation, please refer my online Chinese ebook: 安卓应用的安全和破解

提交回复
热议问题