HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to decompile DEX into Java source code?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
sourcehowjavacodedexdecompileinto

Problem

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

Solution

It's easy

Get these tools:

-
dex2jar to translate dex files to jar files

-
jd-gui to view the java files in the jar

The source code is quite readable as dex2jar makes some optimizations.
Procedure:

And here's the procedure on how to decompile:
Step 1:

Convert classes.dex in test_apk-debug.apk to 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


Note 1: In the Windows machines all the .sh scripts are replaced by .bat scripts

Note 2: On linux/mac don't forget about sh or bash. The full command should be:

sh d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk


Note 3: Also, remember to add execute permission to dex2jar-X.X directory e.g. sudo chmod -R +x dex2jar-2.0

dex2jar documentation
Step 2:

Open the jar in JD-GUI

Code Snippets

d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk
d2j-dex2jar.sh -f -o output_jar.jar dex_to_decompile.dex
sh d2j-dex2jar.sh -f -o output_jar.jar apk_to_decompile.apk

Context

Stack Overflow Q#1249973, score: 988

Revisions (0)

No revisions yet.