2012年8月21日 星期二

Get Android source code from .apk

To get Android source code from .apk, you need following tools:

  1. dex2jar - the tool helps we decode .apk to .class files
  2. JD-gui or JDEclipse - the tool helps we read the .class files. JD-gui can help you save all .class to .java at one time.
  3. android-apktool - the tool helps we get res and other properties in the .apk.

The steps to get the source code of XXX.apk:

The environment I used is Fedora 16. android-apktool was installed under /usr/local/bin directory.

First, we are going to take the .java files.
     1.  Use dex2jar to get the .class files.
          # sh dex2jar.sh XXX.apk
     Then we will get a file named "XXX.apk.dex2jar.jar". 
     2. Open JD-gui and open "XXX.apk.dex2jar.jar" file. (File -> OpenFile -> indicate XXX.apk.dex2jar.jar ).
     3. Save all sources (File -> Save all sources -> to where you want to save the sources and make a name). Then you will get a zip file. Here we named it XXX.zip.

Now we have .java files in XXX.zip.
     
Second, we are going to get other files such as res directory and .xml files in XXX.apk.
     1.  Use android-apktool to get the files.
           # apktool d XXX.apk XXX_dir
     apktool will create XXX_dir. Then in XXX_dir, we have the files. 
     
Finally, we can unzip XXX.zip to XXX_dir/src. And everything is done.

References:

沒有留言:

張貼留言