Tools Needed
Check apktool version
❯ apktool --version
Install dex2jar on Mac
❯ brew install dex2jar
Step 1: Decompiling APK file with Apktool
❯ apktool d xxx.apk
From apktool, you can view some source code files of the apk. By using this method, you can only view smali source code.
Step 2: Decompiling dex to jar with dex2jar
Change the file extension of the apk to zip.
Extract the zip file to get the file with dex extension, then use dex2jar to convert the dex file to jar file.
❯ d2j-dex2jar classes.dex
Alternatively, you can directly download dex2jar, and then execute
sh d2j-dex2jar.sh classes.dex
If the compilation fails and displays a version issue, you need to modify the version in the dex file header.
The magic field in the dex file header is an 8-byte fixed character array that represents the type and version of the dex file. The following are the contents of the magic field in the dex file header for different versions:
• Android 1.0 and 1.1: dex 035
• Android 1.5: dex 035
• Android 1.6: dex 036
• Android 2.0 to 2.3.7: dex 035
• Android 3.0 to 3.2.6: dex 036
• Android 4.0 to 4.0.4: dex 035
• Android 4.1 to 4.4.4: dex 036
• Android 5.0 to 6.0.1: dex 037
• Android 7.0 to 7.1.2: dex 038
• Android 8.0 and above: dex 039
After obtaining the jar file, you can use jd-gui to view the jar code.
Step 3: Viewing jar code with JD-GUI