Reverse Engineering Android Apk

If you ever want to reverse engineer ( i.e: See the source code ) any android application, here is the process.

If you have the android package kit (apk ) you can skip the bellow step.

Download APK File from Google Play

Go to android play store and get the application package name . You will find it in the url ( i.e : com.something.something ) . Let the package name is com.myapp.test

Go to bellow sites

http://apkleecher.com/

http://apps.evozi.com/apk-downloader/

Input the "com.myapp.test" in the text file highlighted in the sites.

You will get a download link for that apk.

Download Necessary Tools

You will need following tools ,

  1. apktool ( https://code.google.com/p/android-apktool/downloads/list )

  2. dex2jar ( https://code.google.com/p/dex2jar/ )

  3. jd-gui ( http://jd.benow.ca/ ) ( i.e : Web Decompiler on this site works better then downloaded version )

How to decompile

Open the terminal Enter the follwing commands ,

Get Resource Files
            apktool d test.apk  

it will decomplie the apk and you will get the resource files like, layouts, strings , configs etc..

Get Source Files

Extract dex2jar from downloaded zip archive ,

            dex2jar/dex2jar.sh test.apk 

It will give you a jar file with names like "test_dex2jar.jar" ( i.e : "test" is your app name )

  • Online Source View :

Now go to http://jd.benow.ca/ this site, scroll down to bottom , you will find a "Live Demo" section.

Drag the "test_dex2jar" file in the container with text "Drop Jar file or class and inner class files here".

Decomplies sources will be shown bellow it.

  • Desktop Source View:

Open the jar file with JD-GUI. It will show you all the sources.
Now go to file -> Save the sources. It will zip up the decompiles sources and save it to selected path. Unzip it, you will get the sources.

To Re-Compile After Changing some String Values
        apktool b /path/to/decomplied/src  newapp.apk

You need sign the apk to install it again,

zipalign -v 4 test.apk test_aligned.apk

keytool -genkey -v -keystore my-release-key.keystore -alias android -keyalg RSA -keysize 2048 -validity 20000

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore test.apk android

Now you can re-install the final apk .

Happy Reversing...