Anti-compilation Android app

Source: Internet
Author: User
Tags java decompiler

Reprint please specify the source: http://blog.csdn.net/allen315410/article/details/44018747Android Anti-compilation introduction when we develop Android applications, we often "reference" "the idea" of others, you know! However, many times we can not see other people's source code, this time the only solution is to decompile the APK, we know that when an Android app developed, will be packaged to generate the APK file, However, the Android packaging tool will compile Java source code into a. Class bytecode file, the layout file garbled processing, will also be nine patch pictures to do special processing, if not through anti-compilation and direct pressure to see its source code or use its resource files, is not ideal, Below I will note how the Common Android anti-compilation tools are used.
Use of the Jd-gui tool JD Project official address:

http://jd.benow.ca/

http://java.decompiler.free.fr (This is the official website, now seems to have not provided)

Readers can go to the official website to see the instructions, although it is English, but not difficult to understand, often the homepage will provide us with more useful information. For example:

Reference: The "Java Decompiler Project" aims to develop tools in order to decompile and analyze Java 5 "byte Code" and the later Versions.

"Java Compiler project" is designed to develop tools to decompile and parse Java 5-byte code "and above versions.

Reference: Jd-gui is a standalone graphical utility that displays Java source codes of ". Class" files. You can browse the reconstructed source code with the Jd-gui for instant access to methods and fields.

Jd-gui is a standalone graphical tool that displays the Java source code ". Class "file. You can browse the Rebuild source code Jd-gui instant access methods and fields.


Use of Jd-gui

Next, we are going to download the Jd-gui tool, Jd-gui is the UI client of JD project, and we use this tool to easily decompile the. Class bytecode file into a. Java source file, which can also be used to decompile. jar files.


, you can click on the link above to download Jd-gui, because I am using windows, so I downloaded the version of Windows, if you use the platform is Linux or Mac, you will download another two versions. Once downloaded, unzip the package with the Unzip tool, and you will see that the package contains the Jd-gui.exe and Readme.txt files. As a rule, we need to read the Readme file, which has some pertinent information that deserves our attention, such as how to use it:

How to use Jd-gui

For example, to Decompile "Object.class", can:

Example: When you decompile a "object.class" file, you can:
-Execute the following command line: "Jd-gui.exe object.class".

Execute the "jd-gui.exe object.class" command on the command line
-select "Open file ..." in the "File" menu and browse to "Object.class".

Select "Open File ..." in the "File" menu list, browse to open "Object.class"
-Drag and Drop "Object.class" onto "Jd-gui".

Direct drag "Object.class" to "Jd-gui"

In conclusion, the third kind of drag and drop is the most convenient, when we use, it is best to use this, in fact, at least I personally is such a habit, you say?!


Jd-eclipse's use of jd-eclipse is a plugin for the Eclipse platform. It allows you to display all Java sources during debugging, even if you do not. When we want to view the source of a jar package in eclipse, sometimes it is not related to the source code, such as Google's Gson.jar is not included in the source code, such as:

Plug - ins: Http://jd.benow.ca/jd-eclipse/downloads/jdeclipse_update_site.zipPlug-in Online installation address: http://jd.benow.ca/jd-eclipse/updateWe recommend using the online install plugin method. The steps are as follows: Click "Help" on Eclipse and "Install New Software"-"ADD" and fill in the popup window with the link to install the plugin online:
Next, "Next" goes on. Finally, you need to agree to an agreement clause:
After the final installation, restart Eclipse, then you can view the source code.
is not very convenient ah, try it!


Use of the Dex2jar tool: https://code.google.com/p/dex2jar/

Official User-guide

This tool is very simple to use, it can decode the Android APK classes.dex into a jar file, Use the method can refer to the official website User-guide as follows:

  1. Download Dex2jar Latest Version http://code.google.com/p/dex2jar/downloads/list
  2. Unzip the Dex2jar-version.zip file to a directory. For example /home/panxiaobo/, c: \
    unzip-x dex2jar-version.zip-d/home/ Panxiaobo
  3. Use Dex2jar to generate. jar files. Dex2jar will generate a Someapk-dex2jar.jar file in the working directory.
    Linux sh/Home/Panxiaobo/Dex2jar-version/d2j-Dex2jar.SH/Home/Panxiaobo/someapk.apk windows C:\Dex2jar-version\d2j-Dex2jar.bat someapk.apk
  4. Use the Anti-compilation tool to get the view source code
    • Jd-gui
    • JAD

It's so simple.


How to use if the user-guide provided in the official documentation above is not good to understand, please see below the use of it, first we have to ensure that the Dex2jar has been downloaded intact, and the decompression is complete. First, because Dex2jar is based on command-line operations, the Windows Command window is opened, and the directory is switched to the Dex2jar's pressurized directory. Because the Dex2jar extract directory contains the dex2jar.bat batch command and other attached files, and then copy the apk file that needs to be recompiled to this Dex2jar's extract directory, execute the command "Dex2jar xxx.apk":

, perhaps the text explanation is not very clear, look at the picture effect will be better, after the completion of the above work, the explanation of the anti-compilation, you will find the decompression directory more such a jar file:

In fact, this jar file is the Dex2jar tool to convert the Dex file in the APK package into a jar file, with the jar file is good, we open the Jd-gui tool described above, directly drag the jar file to Jd-gui above, you can view the source code.

Use of Android-apktool Tools

Android-apktool can put the Androidmanifest.xml file and the res directory under the XML file and Ninepatch images are recompiled to near-original state, and can be recompiled back after compilation

Official download Link:https://code.google.com/p/android-apktool/

Before learning to use Android-apktool, I suggest that you first click on the link to see the key information, such as the latest version, usage requirements, how to use, and so on, very clear. Since the latest version of Android-apktool is 2.x, we will also download this version for use here.


Pre-use requirements1,JDK (JRE) version 1.7 and above. The 2,AAPT command must be added in the environment variable path. 3, it may be helpful to learn about some of the Android SDKs, AAPT, Smali, and how to use Google.
Install Apktool 2.x (Windows environment) 1, download the Windows Script Command (apktool.bat) 2, download Apktool 2.x version 3, rename the downloaded file to "Apktool.jar". (There may be some reason why the file name downloaded to is not Apktool.jar) 4, move the two files (Apktool.bat and Apktool.jar) to the same directory in Windows. (I moved it to a new folder on my desktop)
5, check whether the environment variable contains the AAPT directory, and the JDK version.
Common command commands use the format:Apktool D [Options] <file.apk>

- Fforcibly deletes the target directory. If you try to use the anti-compilationof thefolder already exists
- MKeep as close to the original file as possible. Prevention of reconstruction for analysis
- SThis prevents the compilation of Java source code. This enables the APK the classes. The Dex file is simply moved during compilation. If you only want toEdit the resource. This is the recommendedmoreFast decompile and rebuild.
The Classic use is as follows:

Apktool d-f-m-s abc.apk

More commands.


Use the method to first open the Windows command-line window, switch the current directory to the directory where "Apktool.bat" and "Apktool.jar" are located, and then copy the apk file that needs to be recompiled to this directory and execute the command "apktool d-f-m-s abc.apk"As shown in:
, and then you'll see that the directory has a folder with the same name as the APK, which contains all the files that Apktool has compiled, including all the sub-files in the Androidminifest.xml and res directories, and the pictures, especially the nine The patch image is also restored. We can use the Text tool to view the layout file code or other resource code.

Summary: Android Anti-compilation commonly used three tools to introduce here, master the three tools basically anti-compilation no problem. For more information about the three tools, please refer to the above link, directly into the official website to see it, there will be a lot of help. To be clear, according to my experience, if we just want to decompile the Java source code for Android APK, we just need to convert the Dex file to a jar file using Dex2jar, and then use Jd-gui to interpret the code. Second, if we need to look at the Android resource file, we need to use the Android-apktool tool to decompile, the random Android-apktool tool can also decompile Java source code Smali file,        About Smali file compilation also need to learn other tools, more cumbersome, rather than directly use Dex2jar good. As a result of our special national conditions, these tools are not directly accessible to the official website, so I have provided the following three tools, I have uploaded to my csdn resources (free points).
Jd-gui Download Dex2jar Download android-apktool Download

Anti-compilation Android app

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.