Android APK decompilation

I have been learning and developing Android applications for a while, and today I wrote a blog to summarize the decompilation of Android apk files. We know that after Android application development is completed, we will eventually package the application into an apk file, and then let users download and install it through a mobile phone or tablet. Under normal circumstances, after an Android application is packaged into an apk, you can no longer see the resource files and codes used to develop the application. However, we have provided some tools on the Internet, and we can still decompile the apk. After the apk is decompiled, we can see the resource files (pictures), layouts, styles, and related implementation codes used to develop this application. Decompilation is also a more practical skill in Android development. When we are interested in applications developed by others, we can decompile the apk packaged by others through this technical means, and then we can see our feelings. Interested content, (Note: Decompilation is not for developers to crack and reinstall an application, the main purpose is to promote developers to learn, learn from good code, and improve self-development level.) Let's talk about it below How to decompile an apk.

1. Prepare the necessary tools

  If you want to do a good job, you must first sharpen your tools. First of all, we need to download the relevant tools needed to decompile apk.

1.1. Use tools

  1. apktool (resource file acquisition) 
  2. dex2jar (source source file acquisition)
  3. jd-gui (source view)

1.2, tool introduction

  apktool  

         Function: Resource file acquisition, you can extract image files and layout files for use and viewing

  dex2jar

         Function: Decompile apk into java source code (classes.dex is converted into jar file)

  jd-gui

         Function: View the jar file converted from classes.dex in the APK, that is, the source file

1.3 Tool download

  apktool download address: https://bitbucket.org/iBotPeaches/apktool/downloads

  

  After downloading, you will get a jar file as shown below

  

  dex2jar download address: http://sourceforge.net/projects/dex2jar/files/

  

  

  After the download is complete, you will get a compressed package as shown in the figure below

  

  jd-gui download address: http://jd.benow.ca/

  

  After the download is complete, you will get a compressed package as shown below:

  

  At this point, the three related tools that need to be used have been downloaded. Here is the download of jd-gui. When I click to download from the official website, the problem shown in the following figure often occurs.

  

  But you can download it after a few more tries, so if you encounter this problem, you may try it a few more times, or download jd-gui from other places. jd-gui is a must-have tool for Java development. It is very convenient to use it to decompile the class into java source code. You can generally download it by searching on the Internet, but the version is not necessarily the latest.

2. Apk decompilation process

  In order to facilitate decompilation, we put the three downloaded tools above into one folder, for example:

  

  Then extract [dex2jar-2.0.zip] and [jd-gui-windows-1.3.0.zip] to the current folder respectively, as shown in the following figure:

  

2.1. Use apktool to decompile apk to get pictures, XML configuration, language resources and other files

  Enter the CMD command line, as follows:

  

  Switch to the directory where the above three tools are located, such as: E:\AndroidDevelopTool\Android Decompilation Toolkit

  

  The next thing we have to do is to run the apktool_2.0.1.jar jar file to decompile the apk file. In java, the command to run the executable jar package is:

java -jar jar包名.jar

  Use the following command to run apktool_2.0.1.jar to decompile MMTS-release-1.0.2.apk

java -jar apktool_2.0.1.jar d -f E:\AndroidDevelopTool\Android Decompile Toolkit\Test apk\MMTS-release-1.0.2.apk -o MMTS

  This command is to start the apktool_2.0.1.jar which will be located in the [E:\AndroidDevelopTool\Android Decompilation Toolkit\Test apk\] directory to decompile the apk "MMTS-release-1.0.2.apk", and then decompile the The generated files are stored in a [MMTS] folder under the current directory (the directory where apktool_2.0.1.jar is located, that is, the "E:\AndroidDevelopTool\Android Decompilation Toolkit" directory). The name of this folder can be arbitrarily chosen, you can call it whatever you like.

  Perform a decompile operation:

  

  After the decompilation is successful, an MMTS folder will be generated in the current directory (E:\AndroidDevelopTool\Android Decompilation Toolkit), and there will be files generated after decompilation in MMTS, as shown in the following figure:

  

  Open the MMTS folder, and you can see the generated files after decompilation, as shown in the following figure:

  

  Among the generated files and folders, what we care about is the [res] folder and the AndroidManifest.xml file, open the res folder, and there are things we want to see inside, as shown in the following figure:

  

  

  

  

  Use a text editor to open the xml file you want to see, and you can see it all anyway. The above is the process of using apktool to decompile an apk to obtain files such as pictures, XML configuration, language resources, etc.

2.2. Use dex2jar to decompile apk to get Java source code

  Change the suffix name of the APK to be decompiled to .rar or .zip, and decompress it to get the classes.dex file (which is the java file compiled and packaged by the dx tool), as shown in the following figure:

  

  Put the obtained classes.dex in the folder [dex2jar-2.0] of the previously unzipped tool, as shown in the following figure:

  

  Navigate to the directory where dex2jar.bat is located on the command line, enter " d2j-dex2jar classes.dex ", the effect is as follows:

  

  After the command is executed, you can see the generated Jar file in the current directory, as shown in the following figure:

  

  After decompiling classes.dex to get the classes-dex2jar.jar file, you can use the [jd-gui] tool to decompile the class file into java source code

  

  Use jd-gui to open classes-dex2jar.jar to see the source code, as shown below:

  

  Although JD-GUI can decompile classes into java source code, for some obfuscated classes, the effect of decompilation is not so ideal . The method names will be named in the style of a,b,c....):

  

  The above steps are sorted out step by step after I personally practiced, and there should be no major problems in comparison.

Three, Apk decompilation attention problems

3.1. The apktool version is too old and the decompilation fails

  I have used some old versions of the apktool tool before, and found that the decompilation is always unsuccessful, and the following error occurs when the decompilation is performed:

  Exception in thread “main” brut.androlib.AndrolibException: Could not decode arsc file

  

  This problem is caused by the low version of apktool, and the solution to this problem is to use the latest version of apktool. The download address of the latest version is: https://bitbucket.org/iBotPeaches/apktool/downloads

3.2. "Input file was not found or was not readable" when apktool executes the decompile command

  This problem is because when apktool is upgraded to 2.0 or above, the usage has been replaced, the format is: apktool d [-s] -f <apkPath> -o <folderPath>

  Well, that's all for decompiling apk.
  Finally, I will share with you the three related tools that I have downloaded. The download address is: http://pan.baidu.com/s/1jGKSQyU

I have been learning and developing Android applications for a while, and today I wrote a blog to summarize the decompilation of Android apk files. We know that after the Android application development is completed, we will eventually package the application into an apk file, and then let users download and install it through a mobile phone or tablet. Under normal circumstances, after an Android application is packaged into an apk, you can no longer see the resource files and codes used to develop the application. However, we have provided some tools on the Internet, and we can still decompile the apk. After the apk is decompiled, we can see the resource files (pictures), layouts, styles, and related implementation codes used to develop this application. Decompilation is also a more practical skill in Android development. When we are interested in applications developed by others, we can decompile the apk packaged by others through this technical means, and then we can see our feelings. Interested content, (Note: Decompilation is not for developers to crack and reinstall an application, the main purpose is to promote developers to learn, learn from good code, and improve self-development level.) Let's talk about it below How to decompile an apk.

1. Prepare the necessary tools

  If you want to do a good job, you must first sharpen your tools. First of all, we need to download the relevant tools needed to decompile apk.

1.1. Use tools

  1. apktool (resource file acquisition) 
  2. dex2jar (source source file acquisition)
  3. jd-gui (source view)

1.2, tool introduction

  apktool  

         Function: Resource file acquisition, you can extract image files and layout files for use and viewing

  dex2jar

         Function: Decompile apk into java source code (classes.dex is converted into jar file)

  jd-gui

         Function: View the jar file converted from classes.dex in the APK, that is, the source file

1.3 Tool download

  apktool download address: https://bitbucket.org/iBotPeaches/apktool/downloads

  

  After downloading, you will get a jar file as shown below

  

  dex2jar download address: http://sourceforge.net/projects/dex2jar/files/

  

  

  After the download is complete, you will get a compressed package as shown in the figure below

  

  jd-gui download address: http://jd.benow.ca/

  

  After the download is complete, you will get a compressed package as shown below:

  

  At this point, the three related tools that need to be used have been downloaded. Here is the download of jd-gui. When I click to download from the official website, the problem shown in the following figure often occurs.

  

  But you can download it after a few more tries, so if you encounter this problem, you may try it a few more times, or download jd-gui from other places. jd-gui is a must-have tool for Java development. It is very convenient to use it to decompile the class into java source code. You can generally download it by searching on the Internet, but the version is not necessarily the latest.

2. Apk decompilation process

  In order to facilitate decompilation, we put the three downloaded tools above into one folder, for example:

  

  Then extract [dex2jar-2.0.zip] and [jd-gui-windows-1.3.0.zip] to the current folder respectively, as shown in the following figure:

  

2.1. Use apktool to decompile apk to get pictures, XML configuration, language resources and other files

  Enter the CMD command line, as follows:

  

  Switch to the directory where the above three tools are located, such as: E:\AndroidDevelopTool\Android Decompilation Toolkit

  

  The next thing we have to do is to run the apktool_2.0.1.jar jar file to decompile the apk file. In java, the command to run the executable jar package is:

java -jar jar包名.jar

  Use the following command to run apktool_2.0.1.jar to decompile MMTS-release-1.0.2.apk

java -jar apktool_2.0.1.jar d -f E:\AndroidDevelopTool\Android Decompile Toolkit\Test apk\MMTS-release-1.0.2.apk -o MMTS

  This command is to start the apktool_2.0.1.jar which will be located in the [E:\AndroidDevelopTool\Android Decompilation Toolkit\Test apk\] directory to decompile the apk "MMTS-release-1.0.2.apk", and then decompile the The generated files are stored in a [MMTS] folder under the current directory (the directory where apktool_2.0.1.jar is located, that is, the "E:\AndroidDevelopTool\Android Decompilation Toolkit" directory). The name of this folder can be arbitrarily chosen, you can call it whatever you like.

  Perform a decompile operation:

  

  After the decompilation is successful, an MMTS folder will be generated in the current directory (E:\AndroidDevelopTool\Android Decompilation Toolkit), and there will be files generated after decompilation in MMTS, as shown in the following figure:

  

  Open the MMTS folder, and you can see the generated files after decompilation, as shown in the following figure:

  

  Among the generated files and folders, what we care about is the [res] folder and the AndroidManifest.xml file, open the res folder, and there are things we want to see inside, as shown in the following figure:

  

  

  

  

  Use a text editor to open the xml file you want to see, and you can see it all anyway. The above is the process of using apktool to decompile an apk to obtain files such as pictures, XML configuration, language resources, etc.

2.2. Use dex2jar to decompile apk to get Java source code

  Change the suffix name of the APK to be decompiled to .rar or .zip, and decompress it to get the classes.dex file (which is the java file compiled and packaged by the dx tool), as shown in the following figure:

  

  Put the obtained classes.dex in the folder [dex2jar-2.0] of the previously unzipped tool, as shown in the following figure:

  

  Navigate to the directory where dex2jar.bat is located on the command line, enter " d2j-dex2jar classes.dex ", the effect is as follows:

  

  After the command is executed, you can see the generated Jar file in the current directory, as shown in the following figure:

  

  After decompiling classes.dex to get the classes-dex2jar.jar file, you can use the [jd-gui] tool to decompile the class file into java source code

  

  Use jd-gui to open classes-dex2jar.jar to see the source code, as shown below:

  

  Although JD-GUI can decompile classes into java source code, for some obfuscated classes, the effect of decompilation is not so ideal . The method names will be named in the style of a,b,c....):

  

  The above steps are sorted out step by step after I personally practiced, and there should be no major problems in comparison.

Three, Apk decompilation attention problems

3.1. The apktool version is too old and the decompilation fails

  I have used some old versions of the apktool tool before, and found that the decompilation is always unsuccessful, and the following error occurs when the decompilation is performed:

  Exception in thread “main” brut.androlib.AndrolibException: Could not decode arsc file

  

  This problem is caused by the low version of apktool, and the solution to this problem is to use the latest version of apktool. The download address of the latest version is: https://bitbucket.org/iBotPeaches/apktool/downloads

3.2. "Input file was not found or was not readable" when apktool executes the decompile command

  This problem is because when apktool is upgraded to 2.0 or above, the usage has been replaced, the format is: apktool d [-s] -f <apkPath> -o <folderPath>

  Well, that's all for decompiling apk.
  Finally, I will share with you the three related tools that I have downloaded. The download address is: http://pan.baidu.com/s/1jGKSQyU

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324838952&siteId=291194637