Android is confusing the code

Source: Internet
Author: User

The previous blog post has written about the apk of the method, the result is really shocking, their hard-working code, the result is so easily by the ulterior motives of the people to steal, crying no place to cry. What should we do in the face of this problem? This blog post tells you how to confuse a team code.

Confusion is the re-organization and processing of the published program, so that the processed code and the pre-processing code to complete the same function, and the confusing code is difficult to decompile, even if the anti-compilation success is difficult to derive the true semantics of the program. The obfuscated program code, still in accordance with the original file format and instruction set, the execution result is the same as before, but the confusion of all the variables, functions, classes in the code to the name of the short English letter code, in the absence of the corresponding function name and program comments, even if it is anti-compilation, it will be difficult to read. At the same time confusion is irreversible, in the process of confusion, some information that does not affect the normal operation will be lost permanently, the loss of this information makes the program more difficult to understand.

The role of the obfuscation is not only to protect the code, it also has the function of simplifying the size of the compiled program. Because of the shortened variables and function names described above, and the reasons for missing some information, the size of the jar file can be reduced by approximately 25%, which makes sense for the current cost of the wireless network transmission is more expensive.

Depending on the SDK version, the method of obfuscation is different:

The lower version of the SDK,The project contains bothproguard.cfgand theproject.propertiesfile, you only need to project.properties fileadd at the endProguard. config=proguard.cfg to export the project again. I'm not going to say much here.

Now the common version of the SDK,The project contains bothProguard-project.txtand theproject.propertiesfile, you need to project.properties configuration of the following information in the file, and thenthen export the project to.

Proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt

The above sentence eclipse is automatically generated, but there will be # to comment out, you just have to let go of it, and now to export, the effect of anti-compilation is as follows:


There are a lot of package names and class names have been modified, and many of the packages are empty, so that our purpose is achieved.

One problem is why the activity and view have not been renamed?? Let's see what proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt means.

Found it.. \android-sdk-windows\tools\proguard directory you will find a proguard-android.txt, open it is the following:

-optimizationpasses 5 # Specify the compression level of the Code
-dontusemixedcaseclassnames # Whether to use case blending
-dontskipnonpubliclibraryclasses # Whether to confuse third-party jars
-dontpreverify # Whether to do pre-calibration when confusing
-verbose # Whether logs are logged when confused
-optimizations!code/simplification/arithmetic,!field/*,!class/merging/* # algorithm used to confuse


-keep public class * extends Android.app.Activity # Keep What classes are not confused
-keep public class * extends Android.app.Application # Keep What classes are not confused
-keep public class * extends Android.app.Service # Keep What classes are not confused
-keep public class * extends Android.content.BroadcastReceiver # Keep What classes are not confused
-keep public class * extends Android.content.ContentProvider # Keep What classes are not confused
-keep public class * extends Android.app.backup.BackupAgentHelper # Keep What classes are not confused
-keep public class * extends Android.preference.Preference # Keep What classes are not confused
-keep public class Com.android.vending.licensing.ILicensingService # Keep What classes are not confused


-keepclasseswithmembernames class * {# Keep Native method not to be confused
Native <methods>;
}


-keepclasseswithmembers class * {# Keep custom control classes from being confused
Public <init> (Android.content.Context, Android.util.AttributeSet);
}


-keepclasseswithmembers class * {
Public <init> (Android.content.Context, Android.util.AttributeSet, int.); # Keep your custom control classes from being confused
}


-keepclassmembers class * extends android.app.Activity {# Keep custom control classes from being confused
public void * (Android.view.View);
}


-keepclassmembers enum * {# keep Enum enum class not to be confused
public static **[] values ();
public static * * VALUEOF (java.lang.String);
}


-keep class * Implements android.os.Parcelable {# keep parcelable from being confused
public static final Android.os.parcelable$creator *;
}


-keep class MyClass; # Keep your defined classes from being confused

Most of these settings cannot be changed, otherwise the APK will not run.

If you don't want to confuse a package simply add the following code to the proguard-project.txt

-dontwarn com.wangpeng.libs.utills.**
-keep class com.wangpeng.libs.utills.** {*;}

Handling of third-party jars

#不混淆第三方jar包中的类
-keep class com.baidu.mapapi.** {*;}
-keep class com.tencent.tauth.** {*;}
-keep class Org.Apache. http.entity.mime.** {*;}
-keep class android.support.v4.** {*;}
-keep class Android.Net. http.** {*;}
-keep class com.weibo.sdk.android.** {*;}
-keep class com.sina.sso.** {*;}

#声明第三方jar包, regardless of the. So file in the third-party jar package (if any)
-libraryjars Libs/baidumapapi.jar
-libraryjars Libs/tencent_openapi.jar
-libraryjars Libs/httpmime-4.1.3.jar
-libraryjars Libs/weibo.sdk.android.sso.jar
-libraryjars Libs/android-support-v4.jar


Android is confusing the code

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.