Android tricks: How to decompile an APK File

Source: Internet
Author: User
Tags java decompiler

While learning how to program, it is inevitable to turn to reverse engineering, to learn the way that how others solve problem. there is no exception when learning development on Android platform. here we talk about three main
Methods to decompile an APK file.

Android-apktool
Where to get:

1.
Official Website

How to use:

Dowload the apktool.bz2 and decompress it with Bzip2 (might be other format, never mind)

#bzip2 -d apktool.bz2

Then you will get two files:
Apktool, which is a shell script and apktool. jar the core. We use scriptapktool rather than the jar. Here is to decompile an APK file to some directory:

./Apktool d [ecode] [Options] <file.apk> [<out dir>]

It will create a directory in <out dir> with the same name to APK file. inside the directory, You can see almost as the same hierarchies as the source hierarchies when developing. here is an example:

#./apktool d EffectiveAndroid.apk
#ls EffectiveAndroid
AndroidManifest.xml apktool.yml  res   smali

In the decoded directory, there is an androidmanifest. XML, Res which is the same to/RES in development source and smali is equavilent to/src in development source, cannot t these are *. smali Codes instead *. java codes.
The *. xml files are text format and the same to ones when compiling. The codes are in a different coding --- smali which is also easy to read and modify.

This tool also supports re-compile the decompiled sources

Into an apk file, which enables us to modify the apk files. For more info, please refer the help info.

This is the most convenient way from my standpoint. It decodes both the resources file and source codes for us in just one step. All other two ways need more than one.

Dex2jar + JD + axmlprinter2
Where to get:

1. official website:
Dex2jar jd AXMLPrinter2

2. CSDN resources
Dex2jar jd AXMLPrinter2

How to use:

1. Unzip the tool after downloading it, u can seedex2jar. bat anddex2jar. sh, which are scripts. That are the tool we gonna use. Unziping AXMLPrinter2.zip, there
Areaxmlprinter2and
Axmlprinter2.jar, and same here, we use script axmlprinter2

2. Rename *. APK file to *. zip, and unzip it;

3. After unziping, you will get a directory whose name is the same to APK file, in which you can see four things: androidmanifest. XML,/RES, classes. DEX and/assets

4. Use dex2jar. Bat ordex2jar. Sh to decompile the classes. Dex File

#./dex2jar.sh classes.dex

5. Use JD (Java decompiler) to decompile the *. jar into Java source codes. It might be not correct and the same to original sources, but absolutely readable and referenceable.

#./jd-gui classes.jar

6. use axmlprinter2 to decompile *. XML resources. the XML resources after unziping the APK file are in binary format, which is unreadable for human. and dex2jar can decode *. dex only. so use axmlprinter2 to turn binary XML
To text format.

The advantage of this tool is that you can see Java sources. the disadvantage is that this tool can only decompile an APK file, but cannot re-compile, which means you cannot modify the APK in this way. it is only for you to reference
Or learning.

Baksmali/smali + axmlprinter2
Where to get:

1. Official Websites: baksmali/smali axmlprinter2

How to use:

1. After downloading tools, unzip it, you will getbaksmali. jar, smali. jar, baksmaliandsmali, we
Use baksmaliandsmali
Which are shell scripts. unziping axmlprinter2.zip, there are axmlprinter2 and axmlprinter2.jar, and same here, we use script axmlprinter2

2. Rename *. APK file to *. zip, and unzip it

3. After unziping, you will get a directory whose name is the same to APK file, in which you can see four things: androidmanifest. XML,/RES, classes. DEX and/assets

4. Use baksmali
To decode classes. dex to smali codes. after decoding, in the output folder, there are the same hierarchies to the source folder/src in development, doesn't the code is *. smali instead *. java

./Baksmali <dex-file>-o <out dir>

5. The resources XMLs are in binary format, use AXMLPrinter2 to decode it to text format.

This tool also supports re-compile.
Smali scripts you can re-compile the *. smali into a DEX file:

./Smali *. smali | <Dir containing *. smali> <Out-dex>

Comparing the three methods, I prefer apktool most. it is powerful and easy to use. the only drawback of this tool is that it can only decodes into smali codes. but smali codes are also readable, referenceable and modifiable.

Finally, there are powerful tools indeed. But we shoshould use them in a valid ue way such reference, learning or localization.

Have fun in Android app reverse engineering trip.

This article discusses how to de-compile and modify an APK in great detail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.