Extract Android apk from Market and Decompile it to Java Source

This post talks about process of extracting apk file of any app available in market and then decompiling it to Java source. This can be helpful for those who perform code review (for security vulnerabilities) on apps whose source code is not available. Once Java source code is obtained, we can either do manual code review or run any free/commercial automated code scanners.

Download .apk file from market

  1. Search in market for the app you want to decompile and install it on your phone.
  2. Install Astro File Manager from market (link). Open Astro > Tools > Application Manager/Backup and select the application to backup on to the SD card .
  3. Mount phone as USB drive and access '\backups\apps\' folder to find the apk of target app (lets call it targetapp.apk) . Copy it to your local drive.

Decomiling apk to Dex format

  1. Download Dex2Jar (link) (Android runs applications which are in Dalvik Executable (.dex) format).
  2. Run the command to convert apk to jar

dex2jar targetapp.apk file(./dex2jar targetapp.apk on terminal)

File ‘targetapp.apk.dex2jar.jar’ is created

Converting Apk (Dex) to Jar

Viewing/Decompiling the Jar files to Java

Method 1 : Use JavaDecompiler (JD)

  1. Open ‘targetapp.apk.dex2jar.jar’ with jd-gui (link)
  2. File > Save All Sources to sava the class files in jar to java files.

JD GUI Viewer

Method 2: JAD

  1. Extract contents of jar file on to a folder named src. Use and unarchival utility like 7zip
  2. Keep ‘src’ folder in the same directory where JAD and targetapp jar is present
  3. Open JAD in cmd and execute the following command
  4. jad -o -r -sjava -dsrc src/**/*.class (./jad on terminal)

Extract jar contents to src folder

Running jad command

Now src will contain decompiled Java files ready for manual code review.

Decompiled java files

Tools Used

  1. Sample app – RemoteDroid (Opensource – link)
  2. Astro File Manager (Android Market – link)
  3. Dex2Jar (link)
  4. jd-gui (link)
  5. JAD (link)
Dex2Jar Info
App Name Dex2Jar
License free
  • portable
  • code
App URL Download
More Info link