Android App anti-compilation (ii)-APK package decompile

Source: Internet
Author: User

Chapter Two APK package anti-compilation

Code and resources that have been processed by the compiler have been packaged as APK, and some have even been converted into binary files. But we also have some ways to change the compiled content back to the original, the process called-decompile.

Anti-compilation is divided into two parts: one is a resource file and one is a Java file. So files are the result of C + + compilation, which can be thought of as non-decompile (decompile The assembly instructions, which most people do not understand).

2.1 Anti-compile resource file

APK tool is a powerful anti-compilation tools, it is said that Google provides the official anti-compilation tool, the APK directory can be unpacked, the resource files are all restored to the pre-compilation, and Dex files are compiled into Smail format files (rather than the Java original file we want). The Smail format file is the syntax used by the Android virtual machine when it is executed, and we will not explain this part.

2.1.1 Tool Preparation
    1. Download the latest version on the APK tool's website APKTool ;

2. Download the ' Apktool ' package [script file-apktool.bat] (https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/ Windows/apktool.bat), the contents of which are as follows;

@echo offif"%PATH_BASE%""" set PATH_BASE=%PATH%set PATH=%CD%;%PATH_BASE%;"%~dp0\apktool.jar"%1%2%3%4%5%6%7%8%9

However, the script has a small problem-need to remove apktool.jar the previous one \ ; after the download is complete, open the script with a text editor and modify the paragraph to

@echo offif"%PATH_BASE%""" set PATH_BASE=%PATH%set PATH=%CD%;%PATH_BASE%;"%~dp0apktool.jar"%1%2%3%4%5%6%7%8%9

3. Unzip the downloaded Apktool compressed package and place it in the directory you wish to store with the script file, for example ' D:\Work\apktool ';

4. For ease of use, the storage directory is added to the environment variables of the system; ' My Computer ' right-click ' Properties ', ' Advanced system settings ', ' environment variable ', select ' Path ' to edit;

At the end of the formula bar, enter the path ' D:\Work\apktool ' where Apktool is located, and if there are other paths before the entry, use '; ' to separate;

5. Start the ' CMD Command Line window ', enter ' apktool-version ', if you see something like the following, the installation is successful;

$ apktool -version2.0.3

At this point, the Apktool is installed and setup is complete.
If you are unable to access the official website, please go to the bean network to download the latest version.

2.2.2 Anti-compilation resources

Next start using Apktool,


1. Start up cmd命令行窗口 ;


2. Assume that the APK is placed in D:\Test.apk 目录,输入 apktool d D:\Test.apk ,开始反编译 test.apk ';

$ Apktool DD: \test.apkI:UsingApktool2.0. 3On test.apkI: Loading Resource Table ...I: Decoding Androidmanifest.xml with resources ...I: Loading Resource table from file:C: \users\gym\apktool\framework\1.apkI: Regular Manifest Package ...I: Decoding file-resources ...I: Decoding values */* xmls ...I: Baksmaling Classes.dex ...I: Copying Assets and Libs ...I: Copying Unknown files ...I: Copying Original files ...


3. The compiled result is at the cmd命令行窗口 start of the location, the anti-compilation directory structure is as follows,

Now the resources in the Res directory are restored, the original design can be seen when opened, and the Java source code is deserialized into the Smli format file.

# #2.3 decompile Java source code to see the Java code, there are three ways: 1. Convert Dex files to smail files, and then use specialized tools to translate smail into java;2. Convert the Dex file to Java's generic compiled format class file, and then translate the class into java;3 with a specialized tool. Convert the Dex file to a jar file and then translate the jar into Java using a specialized tool; Here we take the third approach. # # # 2.3.1 Tool prepare to prepare the tool for decompile first.

1. Download the [Dex2jar] (http://sourceforge.net/projects/dex2jar/files/) tool on the website to convert the Dex file in the apk into a jar file;

2. After the download is complete, unzip the package and put it in the directory you wish to store, such as ' D:\Work\dex2jar ';

3. For ease of use, add the storage directory to the environment variables of the system;

4. Download [Jd-gui] (http://jd.benow.ca/) on the official website, it can view the Java source code of the jar file;

5. After the download is complete, unzip the package and put it in the directory you wish to store, such as ' D:\Work\jd-gui ';

At this point, the Java Source Anti-compilation tool is installed and setup is complete. If you do not have access to the official website, please download it on [Http://anddle.com/resource], where the tools are packaged to make it easy for everyone to use. # # #2.3.2 decompile The code then starts using the Anti-compilation tool,

1. Unzip the APK file and locate the ' Class.dex ' in the Android software installation package;

2. Use the Dex2jar tool to generate the Classes.dex jar file, start the ' CMD Command Line window ', enter ' D2j-dex2jar D:\classes.dex ', start to decompile ' Classes.dex ', ' D2j-dex2jar ' The following need to follow the Dex file path to decompile;

$ d2j-dex2jar D:\classes.dex dex2jar classes.dex -> .\classes-dex2jar.jar

The resulting file was generated classes-dex2jar.jar ;


3. Go to the Jd-gui directory, run the Jd-gui tool and open the generated jar file above to see the Java source code.

Android App anti-compilation (ii)-APK package decompile

Related Article

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.