Anti-compile Android apk and prevent apk program from being recompiled

Source: Internet
Author: User

Original source anti-compile Android apk and prevent apk program from being decompile how reverse engineer to decompile Android APK

Google Android Development is open source, some of the development process will encounter some features, they do not know how to do, but other software has already had, this time can be used in the way of anti-compilation, to solve the other procedures, to understand some of its practices, at the same time, but also can draw on other people's software structure, resource files; As a developer, you may be wondering how these effects interfaces are implemented, and you can then decompile the APK for the app.此方式主要目的是为了促进开发者学习,借鉴好的代码,提升自我开发水平。请勿去破解人家的软件或其他操作

Anti-compilation Toolkit
    • Apktools-currently the most powerful anti-compilation tool

Easily decompile apk, parse out the resource file, XML file, generate Smali file, and can also put the modified file you want to generate APK.作用:资源文件获取,可以提取出图片文件和布局文件进行使用查看

    • Dex2jar

Convert the Dex file in the apk into a jar file, many people will not look at the Smali file, or look at the Java class file is more comfortable, this time can use this tool to turn to Java, but also support Windows,linux,mac.作用:将apk反编译成java源码(classes.dex转化成jar文件)

    • Jd-gui

Viewing the jar file, you can basically see the Java class file, and also support Mac,windows,linux.作用:查看APK中classes.dex转化成出的jar文件,即源码文件

Anti-compilation process one, ready to decompile the software

Second, apk anti-compilation to get the program's source code, pictures, XML configuration, language resources and other files
    1. use Apktools apk decompile to get the program source code, picture, XML configuration, language resources and other files

      Place the APK file you want to decompile into the directory, open the command line interface (run-cmd), navigate to the Apktool folder, and enter the following command:

      Apktool.bat d-f emanager.apk Emanager

(emanager.apk in the command refers to the full name of the apk file to decompile, emanager the directory name for the post-compilation resource file, which is:apktool.bat d -f [apk文件 ] [输出文件夹])

    • Once you have succeeded, you can view all the resource files for that app.

    • If you want to repackage the anti-compiled files into an apk, you can: enter
      apktool.bat b emanager(你编译出来文件夹) 便可,这就不述说了。

Third, apk anti-compilation get Java source code
    1. APK anti-compilation get Java source code

      Download the Dex2jar and Jd-gui in the above tool, unzip the apk suffix to be recompiled to. rar or. zip, and extract the amount classes.dex文件 (it is the Java file compiled and then packaged by the DX tool), Put the acquired classes.dex into the previously extracted tool dex2jar-0.0.9.15 文件夹内 , navigate to the Dex2jar.bat directory under the command line, enter
      dex2jar.bat classes.dex

    • Directory will generate a classes_dex2jar.jar file, and then open the tool Jd-gui folder, and then jd-gui.exe Open with the tool, 之前生成的classes_dex2jar.jar文件 you can see the source code, the effect is as follows:

    • (The name of the class file and the name of the method inside will be a,b,c ...). Style name):

You can see that the anti-compilation code and the original code are not very different, the main difference is that the original resource references have all become numbers.

即使那些代码是混淆过的,你可以得到他的大体思路对你的开发有益无害

Prevent the APK program from being recompiled

As an Android app developer, you have to face an awkward situation where your hard-to-develop apps can be easily recompiled by others.

Google seems to have found the problem, starting with SDK2.3 we can see a little more under Android-sdk-windows\tools\.proguard文件夹

Proguard is a Java code obfuscation tool, through proguard, even if the other people decompile your APK package, you will only see some difficult to understand the code, so as to achieve the role of protection Code.

    1. Let's start by describing what is code obfuscation:

      Code obfuscation, also known as the flower Directive, is the act of translating the Code of a computer program into a functionally equivalent, but difficult-to-read and understandable form of obfuscated. Code obfuscation can be used for program source code, or for program-compiled intermediate code. A program that executes code obfuscation is called a code-obfuscation. There are many different kinds of code obfuscation.
      Rewrite the names of various elements in the code, such as variables, functions, and classes, into meaningless names. For example, a single letter, or a short, meaningless combination of letters, or even a symbol such as "__", makes it impossible for a reader to guess its use by name. Rewrite some of the logic in the code, turning it into a functionally equivalent, but more difficult form to understand. For example, the For loop is rewritten as a while loop, the loop is rewritten as recursive, the intermediate variable is streamlined, and so on. Disrupts the formatting of the code. For example, delete a space, squeeze multiple lines of code into one line, or break a line of code into multiple lines, and so on.

Proguard.cfg

-optimizationpasses5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations!code/simplification/arithmetic,!field/*,!class/Merging/*-keep PublicClass *ExtendsAndroid.App.Activity-keep PublicClass *ExtendsAndroid.App.Application-keep PublicClass *ExtendsAndroid.App.Service-keep PublicClass *ExtendsAndroid.Content.Broadcastreceiver-keep PublicClass *ExtendsAndroid.Content.Contentprovider-keep PublicClass *ExtendsAndroid.App.Backup.Backupagenthelper-keep PublicClass *ExtendsAndroid.Preference.Preference-keep PublicClassCom.Android.Vending.Licensing.Ilicensingservice-keepclasseswithmembernamesClass * {native <methods>;} -keepclasseswithmembersclass * {public <init> (Android.content.Context, android.util.AttributeSet);} -keepclasseswithmembers class * {public <init> ( Android.content.Context, Android.util.AttributeSet, int);} -keepclassmembers class * extends Span class= "Hljs-title" >android. app.activity {public void * (Android.view.View);} -keepclassmembers enum * {public static **[] values (), public static * * VALUEOF (java.lang.String);} -keep class * implements android. os. parcelable {public static final Android.os.parcelable$creator *;}     

proguard.cfg起作用的做法很简单,就是在eclipse自动生成的default.properties文件中加上一句“proguard.config=proguard.cfg”就可以了

The default.properties file should look like this:

# This file was automatically generated by Android Tools. #DoNotmodify this file --YOUR CHANGES would be erased! # # file must be checked in  Version Control Systems. # # to Customize properties used by the Ant build system use, #  "Build.properties", and override values to adapt the script to your #  Project structure. # project target target=android-9 proguard.config= Proguard.cfg                

Welcome to Exchange, enter the blog site: www.wangsong520.com to exchange messages, and there is more knowledge to share!

Anti-compile Android apk and prevent apk program from being recompiled

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.