Reverse engineering of Android Apps

You are using an application on your phone, which looks really nice and have really nice design. You want to know how the layouts are created and how the graphics looks like in original. So how you can get access to the .apk-file from the market and is it possible to decompile it?
1 answer

Reverse engineering of Android Apps with baksmali and dex2jar

First of all you must get the .apk-file.

- Therefore you have to connect your Android-Phone with your computer over USB.
- If not already installed, load the Android SDK from here https://developer.android.com/sdk/index.html
- Open a terminal and navigate to Android SDK/platform-tools
- Run following command ./adb pull /data/app/-.apk
(You can find the package-name of the application in the market-url. For Example by https://play.google.com/store/apps/details?id=com.rovio.angrybirds the packe-name is "com.rovio.angrybirds". The Number is mostly 1 or 2.)
- Now you have the apk-file in the same folder on your computer and you can decompile it. Therefore there are 2 things you can do, so make two copies of the apk-file.
1. To get the graphics and layouts you have to download a tool named apktool from here http://code.google.com/p/android-apktool/
When the tool and the apk-file are in the same folder you can decompile it from the terminal with the following command:
./apktool d [PACKAGE-NAME]-[Nr].apk
Now you get a new folder with the whole project. You can't read the java-code, but the graphics and layouts are origin. If you want to do some funny stuff, you can replace so graphics and build a new apk with the comman
./apktool b [FOLDER] FUN_[PACKAGE-NAME]-[Nr].apk
You can install this apk running ./adb install FUN_[PACKAGE-NAME]-[Nr].apk
2. To get the java-files as a jar, so you can get a closer look to the package-structure and classes you have to rename your apk-file to jar and unzip it.
Now you have a classes.dex-file, which you can compile to smali-files with the following tool:
https://code.google.com/p/smali/
So after the dex->smali compiling you get the whole project but with smali-files instead of class-files. But the smali-files are a bit understandable, so sometimes it is possible to change the right code-snippet to get what you want.
If you don't want to change anything, you can compile back smali->dex with the same baksmali-tool.
Now download the last tool: https://code.google.com/p/dex2jar/
With this one you can compile the classes.dex-file to a jar-file, which you can include as a normal java-lib into your Andrpod project.

And that's it!

Taggings: