Android development decompilation code and prevention of decompilation and android Decompilation

Source: Internet
Author: User

Android development decompilation code and prevention of decompilation and android Decompilation

1. decompile the apk File

Install ApkTool, which decodes the resource file but does not obtain the Java source file.
Installation environment: JRE1.6 needs to be installed


1> to http://code.google.com/p/android-apktool/
Download the apktool1.3.2.tar.bz2 and apktool-install-windows-2.2_r01-3.tar.bz2 files.
Decompress the two files and put them together, for example, c: \ apktool.
2> Import aapt.exe in the system variable path, such as:; c: \ apktool \ aapt.exe
3> enter the directory of apktool. jar in the DOS window.
Run the doscommand: apktool d-s c: \ soft \ xxx.apk c: \ soft \ source.
Command Format: apktool d [opts] <file.apk> d in [dir] indicates decoding, [opts] indicates the option, and-s indicates that the source file is not decoded.


2. The Apktool tool can only decompile it into an smali intermediate code file. You need to use another open-source tool Dex2Jar,
This tool can convert dex files into jar files. This tool cannot be directly translated into a java file, but it can convert the dex file to a jar file.
: Http://code.google.com/p/dex2jar/
1> extract classes. dex from the APK installation package to a directory, such as c: \ soft.
2> enter dex2jar in the DOS window. bat directory, execute the doscommand: dex2jar. bat c: \ soft \ source \ classes. dex c: \ soft \ source, command to generate classes. dex. dex2jar. jar file.


3. Install jd-gui, which decompile the jar file into a Java source file
: Http://java.decompiler.free.fr/jd-gui/downloads/jd-gui-0.3.3.windows.zip.
Run the software and open the classes. dex. dex2jar. jar file to view the java source code.


Summary:
Jar package of The Decompilation tool apktool1.4.1.tar.bz2
Apktool-install-windows-r04-brut1.tar.bz2 windows to call the execute jar exe file

1. Decompress these two files and copy apktool. jar in apktool1.4.1 to the apktool-install-windows-r04-brut1 directory. The files include:



Red indicates the apk file to be decompiled.


Run cmd to switch to the directory and run:
> Apktool d-s queryNumber.apk./source generate the source directory in the current directory, and the resource file is placed below



2. Decompress dex2jar-0.0.7.11-snapshot.zip and copy classes. dex to the directory. Execute:
> Dex2jar class. dex
Generate the classes_dex2jar.jar File

It contains all. class files.



3. Open jd-gui.exe and drag classes_dex2jar.jar to the jd-gui.
Now we can see all the source files:

 

 

How to Prevent decompilation ....

Because the apk is loaded by the Android virtual machine, it has certain specifications. After the apk is encrypted, Dalvik cannot identify the apk.
It is impossible to avoid it completely. Someone can always crack your code. However, there are several ways to improve the difficulty of code decompilation.


1. The key code uses jni to call local code and is written in c or c ++. Therefore, it is relatively difficult to decompile the code.


2. obfuscated java code. Obfuscation adds or renames useless code without changing the code logic, making it difficult to understand the decompiled source code.
There are many open-source java code obfuscation tools on the Internet, which are usually compiled in ant mode.

 


 

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.