Android Code obfuscation

Source: Internet
Author: User

Android code obfuscation has always been a special headache, I also on the Internet or other people's blog reference a lot, the general idea is the same. I'll write about my own steps and some of the problems I've encountered when writing code obfuscation. for reference only!

1.

First make sure that you create the Android program in the presence of these two files, if not, don't worry, copy the two files from someone else's program and put them in your program .

2. #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt in file project.properties: Proguard-project.txt the # symbol in this sentence is removed.

3. The next step is to write the code in Proguard-project.tex, which is most important. First of all, there are third-party class libraries in your program, and some class libraries are not confusing. When you call these class libraries, the official web site should have an introduction

Grammar

<span style= "FONT-SIZE:14PX;" >-basedirectory {DirectoryName} specifies the underlying directory for the later relative file name-injars {Class_path} specifies the application to process jar,war,ear and directory-outjars {clas S_path} Specifies the name of the Jar,war,ear and directory to output after processing,-libraryjars {classpath} specifies the library files required for the application Jar,war,ear and directories to be processed-dontskipnonpubli   clibraryclasses specifies that non-public library classes are not ignored.    -dontskipnonpubliclibraryclassmembers specifies that the members of the Library class that the package is visible are not ignored. The Preserve option-keep {Modifier} {class_specification} protects the specified class file and the members of the class-keepclassmembers {Modifier} {Class_specification} protection refers to   Members of the class, if this class is protected they will protect the better-keepclasseswithmembers {class_specification} protects the specified class and members of the class, but the condition is that all the specified classes and class members are to be present. -keepnames {class_specification} protects the names of the members of the specified class and class (if they are not removed in the compression step)-keepclassmembernames {class_specification} protects the specified class The name of the member (if they are not removed in the compression step)-keepclasseswithmembernames {class_specification} protects the name of the member of the specified class and class, if all the specified class members are present (after the compression step)-print Seeds {filename} lists the members of the class and class-keep option, standard output to the given file compression-dontshrink does not compress the input class file-printusage {filename}-whyareyouk      eeping {class_specification}   Optimization-dontoptimize does not optimize the input class file-assumenosideeffects {class_specification} optimizations when the specified method is assumed, without any side effects-allowaccessmodifi     Cation optimizations allow access to and modify members of classes and classes with modifiers-dontobfuscate do not confuse the input class file-printmapping {filename}-applymapping {filename} Reuse Mappings Add confusion-obfuscationdictionary {filename} applies intrusive overloads when using a keyword in a given file as the name of the method to be obfuscated-overloadaggressively obfuscation-useuniq Ueclassmembernames determines the member name of the uniform obfuscation class to increase confusion-flattenpackagehierarchy {package_name} repack all the renamed packages and place them in a given single package-repackagecl The package_name} repack all the renamed class files in a given single package-dontusemixedcaseclassnames confusion does not result in a variety of class names-keepattributes {attribute    _name,...}   Protects the given optional attributes, such as linenumbertable, Localvariabletable, sourcefile, Deprecated, synthetic, Signature, and innerclasses. -renamesourcefileattribute {String} sets the string constant given in the source file </span></span>

Demo
-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify- Verbose-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*-libraryjars libs/  Alipaysdk-20150610.jar-dontwarn com.alipay.**-dontwarn com.ta.utdid2.**-dontwarn com.ut.device.**-keep  Class com.alipay.** {*;}  -keep class com.ta.utdid2.** {*;}   -keep class com.ut.device.** {*;} -libraryjars Libs/android-async-http-1.4.8.jar-dontwarn com.loopj.android.http.**-keep class com.loopj.android.http.** {*;}-libraryjars Libs/android-support-v4.jar-dontwarn android.support.v4.**-keep Class A    ndroid.support.v4.** {*;}  -keep interface android.support.v4.** {*;} -keep public class * Extends android.support.v4.**-keep public class * extends Android.app.fragment-libraryjars libs/j G_filter_sdk_1.1.jar-libraryjars Libs/libammsdk.jar-dontwarn com.tencent.**-keep class com.tencent.** {*;}-keep Clas s com.tencent.wxop.** {*;}-libraryjars Libs/mid-sdk-2.20.jar-libraryjars Libs/mta-android-stat-sdk-2.1.0_20160111.jar-keep class com.tencent.stat.** {*;} -keep class com.tencent.mid.** {*;} -libraryjars Libs/wup-1.0.0-snapshot.jar-libraryjars Libs/xg_sdk_v2.38_20150616_1057.jar-keep Class com.tencent.android.tpush.** {*;} -keep class com.tencent.mid.** {*;} -libraryjars Libs/armeabi/libtpnssecurity.so-libraryjars Libs/armeabi/libtpnswatchdog.so-keepclassmembers class *    Implements Java.io.Serializable {static final long serialversionuid;    private static final java.io.objectstreamfield[] Serialpersistentfields;    private void WriteObject (Java.io.ObjectOutputStream);    private void ReadObject (Java.io.ObjectInputStream);    Java.lang.Object Writereplace ();  Java.lang.Object readresolve ();} -keepclassmembers class com.shinewonder.shinecloudapp.** {*;} -keepclassmembers class com.shinewonder.shinecloudapp.wxapi.**{*;} -keep class android.** {*;} -keep public class * extends Android.view-keep public class * extends Android.app.fragment-keep public class * extends Android.app.activity-keep public class * extends Android.app.Applicati On-keep public class * extends Android.app.service-keep public class * extends Android.content.broadcastreceiver-keep Pub Lic class * extends Android.content.contentprovider-keep public class * extends Android.app.backup.backupagenthelper-keep public class * extends Android.preference.preference-keep public class Com.android.vending.licensing.ilicensingservice-keep class Com.tencent.mm.sdk.openapi.WXMediaMessage {*;} -keep class com.tencent.mm.sdk.openapi.** implements Com.tencent.mm.sdk.openapi.wxmediamessage$imediaobject {*;} -keep public class * extends Linearlayout-keep public class * extends Android.view.View {public <init> (Android. Content.      Context);      Public <init> (Android.content.Context, Android.util.AttributeSet);      Public <init> (Android.content.Context, Android.util.AttributeSet, int.);  public void set* (...); }-KEEPCLASSESWIThmembernames class * {# All native methods cannot be confused with native <methods>;} -keepclasseswithmembers class * {#某些构造方法不能去混淆public <init> (Android.content.Context, Android.util.AttributeSet );} -keepclasseswithmembers class * {#某些构造方法不能去混淆public <init> (Android.content.Context, Android.util.AttributeSet , int);} -keepclassmembers class * extends Android.app.Activity {# Keep the custom control class from being confused with public void * (Android.view.View);} -keepclassmembers enum * {#枚举类不能去混淆public static **[] values ();p ublic static * * VALUEOF (java.lang.String);} -keep class * Implements Android.os.Parcelable {#aidl文件不能去混淆public static final android.os.parcelable$creator *;} -keepclassmembers class * *. r$* {*;}     #不混淆R文件里的资源-keepclassmembers public class * extends Android.view.View {void set* (* * *);    Get* (); }-keep class com.test.model.response.** {*;} #反射类不能进行混淆编译 </span></span>

Demo is just my own process of confusion, not comprehensive, your own program and what does not need to be confused, you can write it in.


4. Final step: Signature package.

By completing these four steps, your code obfuscation is complete, so check to see if your confusion is successful.

The tool I used to test ApkIDE.exe. Apkide is an anti-compilation of your APK,

The operation is particularly simple, first of all you open the ApkIDE.exe, and you confuse the apk dragged into the inside can be anti-compilation

Proof that the anti-compilation was successful.



The Smali in the compiled program is class, and some of your classes are a,b,c ... The letters have been replaced to prove that your anti-compilation was successful. Congratulations to you!

So much for my code obfuscation.


Warm tips:

Code obfuscation is a particularly troublesome job, with a lot of errors in the middle, causing your confusing apk to not run at all, and you need to use the Ddms.bat tool for debugging.

Android Code obfuscation

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.