Skip to content
Search

Android:Decompile

lastmod 2025-02-13created 2016-10-195 edits

About Android decompilation (Decompile).

Tools

APK to JAR.
DEX2JAR - https://code.google.com/p/dex2jar/
Decompress APK.
APKTool - https://code.google.com/p/android-apktool/
JAR Decompiler .
JD-GUI - http://java.decompiler.free.fr/?q=jdgui
JAD - http://www.varaneckas.com/jad/

APK Decompile

A summary of how to decompile an Android apk file with APK tool, dex2jar, and jd-gui.

apk tool

  1. http://code.google.com/p/android-apktool/
  2. Download: the apktool-install- file for windows, apktool-file
  3. Extract both downloaded archives
  4. Create a folder named apktool in android-sdk/platform-tools/ on your computer
  5. Copy and paste aapt.exe, apktool.bat, apktool.jar (the files resulting from compressing the downloaded files, 3 in total) into the apktool folder.
  6. apk tool is ready

dex2jar

  1. http://code.google.com/p/dex2jar/
  2. Download: dex2jar-0.0.7.9-snopshot.zip -> extract
  3. Paste the extracted folder into android-sdk/platform-tools/ on your computer and shorten the folder name to dex2jar

Setting environment variables to use apk tool and dex2jar

  1. In the environment variable settings, edit Path among the system environment variables
  2. Add the path mycomputer/andorid-sdk/platform-tools
  3. Add the path /andorid-sdk/platform-tools/apktool on your computer
  4. Add the path /andorid-sdk/platform-tools/dex2jar on your computer
  5. After adding the 3 paths to the Path system variable, open cmd
  6. cmd: type adb! -> if a bunch of output scrolls by, it's working
  7. cmd: type apktool! -> if a bunch of output scrolls by, it's working
  8. cmd: type dex2jar! -> if a bunch of output scrolls by, it's working
  9. apk tool and dex2jar are ready to use!!!!

Preparing the jd-gui decompiler

  1. Download: http://java.decompiler.free.fr/?q=jdgui
  2. Reference: http://blog.naver.com/fromyongsik/40159603066

Extracting the apk file from an Android device or virtual device

  1. When using a virtual device running on VirtualBox
  2. Start the virtual device and check its IP in the wifi settings.
  3. Open a cmd window and
  4. adb connect (the IP you found)
  5. adb devices: shows the connected virtual devices.
  6. Run adb shell. In shell mode,
    shell@android:/ $ pm list package -f
    shows the list of apks installed on the virtual device.
    Find the path and name of the apk to extract in the list, and
  7. adb pull /data/app/com.HelloWorld.apk (path and name of the apk to extract)

Decompiling the extracted apk file with apktool

  1. apktool d extracted-apk-name output-directory (e.g. apktool d HelloWorld.apk out)
  2. The out folder will contain a res folder, a smali folder, androidmanifest.xml, and an apktool.yml file.
  3. You can see that *.smali files for the apk's java files have been created in the smali folder.
  4. That's it for preparing to reverse an Android apk. Now let's build an Android apk file and reverse it!
    1. Create an Android test project to reverse with Eclipse.
    2. Right-click the Android project -> android tools -> select export unsinged application package.... -> set the path for the apk file
    3. The Android apk file is created

WARNING

With apktool you can get the resource files and configuration files from an apk, but it is hard to view the Java source.

Viewing the source of an apk file with dex2jar and jd-gui

  1. Change the extension of the apk file whose Java files you want to see to zip.
  2. Extract it with a program such as ALZip.
  3. A res folder, androidManiFest.xml, classes.dex, and resources.arsc are created.
  4. The Java files can be read through classes.dex.
  5. Open cmd
  6. In cmd, go to the path of the classes.dex file
  7. In cmd, type dex2jar classes.dex
  8. Something runs and completes
  9. A classes_dex2jar.jar file is created in that path.
  10. Extracting the jar file lets you see the class files of the apk.
  11. Run the jd-gui program and open the classes_dex2jar.jar file.
  12. You can see the packages and Java source.

Decompiling java.class to java.java with jad

  1. Go to www.varaneckas.com/jad
  2. Download the jad.zip file for windows
  3. After extracting jad.zip, copy and paste the executable into the java/jdk/bin folder on your computer.
  4. Ready to decompile with jad
  5. In cmd, go to the path of the class file you want to decompile, then in the console type
    jad -p aaa.class > bbb.java
    This decompiles aaa.class and creates bbb.java in that path.

See also

Favorite site

References


  1. Android_how_to_use_decompile_tools.pdf ↩

author Zer0 sitemap