The Android Anti-compilation tool uses

Source: Internet
Author: User

Catalogue

    • Directory
    • Objective
    • Tools
    • Flow chart
    • Get Classesdex
      • apk
      • Jar
      • Odex
        • Baksmail
        • Smail
    • Classesdex-classes-dex2jarjar
    • Jd-gui
    • View resource files and XML
      • APK installation
      • Unpacking apk
      • Pack apk

Preface

Why do I need to decompile?

    1. Anti-compilation apk. For example, there are many good apk in the market, the implementation of some very good features, and these features can not be easily Google to the time, we could by anti-compilation apk to see the implementation of these excellent features. (It seems a bit shameless, but in the heart of some technology, not for profit, I think it is acceptable).
    2. The anti-compilation jar package. For example, my current job is the system porting, often encounter due to the compilation system caused by the strange problem, this time have the ability to decompile the framework directory of the jar package is very useful.

What you need to declare is :

This article only covers the use of the Android Anti-compilation tool and does not cover the rationale. (PS: Mainly because a lot of the original reason things I also do not understand, do not want to fraught! )

Tools

As the saying goes, "工欲善其事, its prerequisite", to decompile Android, we need the following four powerful tools (PS: These tools can be cross-platform):

    1. Dex2jar
    2. Jd-gui
    3. Baksmali
    4. Smali
Flowchart

In Android development, it is common to encounter apk, jar package, and Odex files that need to be recompiled. I'll use a flowchart to describe the anti-compilation process and the anti-compilation tools that need to be used.

Get Classes.dex

Based on the flowchart, let's take a look at how the APK, jar, Odex, and other files get the Classes.dex file.

apk

We need to unzip the APK with unzip. The specific commands are as follows:

-d /tmp/test

After the decompression is complete, we can find the Classes.dex file in the Extract directory (PS: above is/tmp/test).

Jar

The jar is also a collection of Java files, which we can extract using the JAR-XF command. We often use this command when we decompile the jar files in the Android/system/framework directory.

jar -xf classes.jar

After the decompression is complete, you can generally see the Classes.dex file.

Odex

Trying to get classes.dex from the Odex file is a bit trickier than the APK, jar package, and requires some conversion in the middle.

The Odex file first needs to be converted to the Smail file collection using the Baksmail tool, and then the Smail file collection is packaged as a Classes.dex file through the Smail tool.

The following is an example of the Telephony-common.odex file in the/system/framework directory, which describes how to use the Baksamil and Smail tools.

Baksmail

Use the Baksmail.jar file to decompose the Odex file, with the following specific commands:

java -jar baksmali-2.0.6.jar -x telephony-common.odex

If successful, an out directory will be generated in the current directory, with some files with a suffix of ". Smail".

For more information on the use of Baksmail, you can run directly on the command line:

java -jar baksmali-2.0.6.jar

The results of the implementation section are as follows:

Smail

The next step is to package the resulting out directory into a classes.dex file using the Smail tool. The specific commands are as follows:

java -Xmx1024M -jar smali-2.0.3.jar out -o classes.dex

If the process doesn't get an error, we've converted the Odex file to a Dex file.

Classes.dex-Classes-dex2jar.jar

Next, use this artifact to convert the Classes.dex file to a Classes-dex2jar.jar file. The specific commands are as follows:

bash -x d2j-dex2jar.sh classes.dex

Note that you need to execute permissions for d2j-dex2jar.sh and d2j_invoke.sh two scripts.

Jd-gui

Like my Ubuntu 13.10 64-bit version when using Jd-gui, you may encounter the following error:

while loading shared libraries:...

The main is the lack of 32-bit libraries, the following installation commands can solve these problems:

sudo apt-get install libgtk2.0-0:i386 libxxf86vm1:i386 libsm6:i386 lib32stdc++6

Then, directly with Jd-gui open just dex2jar.sh generated Classes-dex2jar.jar can see the source of the anti-compilation. Such as:

However, as shown, most of the current market-released APK will be confusing code.

View resource files and XML

Use Dex2jar and Jd-gui, etc. can only see the program's source code, cannot see the resource file and XML layout file. To view the APK's resource file and XML, you need to use another artifact: Apktool.

APK Installation

Since I am a Ubuntu13.10 system, I only explain how to install Apktool in the Ubuntu environment.

    1. First, you need to download the Apktool execution script. Open the Apktool script URL and right-click to save the apktool.sh script file.
    2. Second, download Apktool.jar, for: Apktool.jar, select the latest v2.0.0 version can be.
    3. Finally, put apktool.sh and Apktool.jar in the same directory.
Unpacking apk

The command to unpack the APK is as follows:

./apktool.sh d test.apk
Pack apk

The command to package the APK is as follows:

./apktool.sh b test

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The Android Anti-compilation tool uses

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.