Guide to decompiling Android App to source code

From Yggenyk
Jump to: navigation, search

Howto: Extract APK into readable Java source code and XML files

Setup

  1. Install Apk Manager Plus on your Android device.
  2. Download APK-Multi-Tool and extract the files into a folder on your harddisk. There must be no spaces in the directory path.
  3. Install 'Java SE Development Kit 7'.
    1. Edit the environtment variable 'JAVA_HOME' to point to 'C:\Program Files\Java\jdk1.7.0_51' or wherever you installed the Java Development Kit.
  4. Run Setup.bat
    1. Select step 2. 'Installing Framework-Res'.
      1. Connect your phone to the PC via USB.
      2. 9. Pull Dependencies from Phone
      3. 10. Return to Main Menu
    2. Select step 3. 'Setup Directories'.
  5. Download dex2jar and extract it to wherever you want it installed.
  6. Download JD-GUI and extract it to wherever you want it installed.

Note: If step 2. 'Installing Framework-Res' fails it mighe be caused by a bug in APK-Multi-Tool\other\apkinstall.bat. To fix it replace:

(Y) with [Y]
(N) with (N)
(y) with [y]
(y) with (y)
and (%INPUT%) with [%INPUT%]

Decompile .APK file

  1. Start 'Apk Manager Plus' on your Android device and export an App to the SD card
  2. Copy the <app>.apk to APK-Multi-Tool\place-apk-here-for-modding
  3. Run Script.bat
    1. Select 9. Decompile apk
    2. Decompiled apk is now in APK-Multi-Tool\projects (as smali files)
  4. Run C:\<path to dex2jar>\d2j-dex2jar <app>.apk
    1. <app> is now in <app>_dex2jar.jar
  5. Run C:\<path to jd-gui<\jd-gui.exe
    1. Select File-Save All Sources to save sourcecode

Tools

Apk Manager Plus

Apk Manager Plus.jpg

Apk Manager Plus can backup .apk files from apps installed on your phone or tablet to the SD card.
Afterwards you can use the USB cable to transfer them to a PC.

APK-Multi-Tool

APK-Multi-Tool contains
APK.png
android-apktool 
A tool for reengineering 3rd party, closed, binary Android apps. It can decode resources to nearly original form and rebuild them after making some modifications.
smali / backsmali 
assembler/disassembler for Android's dex format
and a lot of other tools, and has build a menu system around all the tools.

To download APK-Multi-Tool Tool (includes android-apktool):

or clone Git repository from here:

dex2jar

Use dex2jar to translate .dex to .jar file then use JD-GUI to open the .jar file and view the .class files in the project.

usage: C:\path\d2j-dex2jar [options] <file0> [file1 ... fileN]

JD-GUI

JD-GUI.png

JD-GUI is a standalone graphical utility that displays Java source codes of “.class” files. You can browse the reconstructed source code with the JD-GUI for instant access to methods and fields.

Other interesting links

id=siteTree