Android Code obfuscation

Source: Internet
Author: User

Android code obfuscation-so simple

A xxx.apk is submitted to the test,

OK, go get a glass of water and look at the Web ~~~~~

Well, suddenly I think it's better to give my code a bit more security,

Remember to see the APK can be extracted directly, and then it is easy to decompile. java

Looked for, sure enough, all this is just a minute thing,

1. Get classes.dex files; open the. apk file directly with the unzip software on your machine

Extract the Classes.dex file, (this is the. jar of the previous---actually should say hereafter)

  

2. Restore the. jar file; This step requires a tool Dex2jar (http://code.google.com/p/dex2jar/in Google's code base)

It's not hard to see the name, you know what he did? (yes, just restore Dex to a jar package)

Download finished, unzip, and then put the product of the first step (that is, the Classes.dex file) in the Dex2jar of the Extract directory

(Unzip the directory There are dex2jar.bat files, check, no words to explain the directory is not correct, look again)

  

cmd command line, directory switch to Dex2jar directory (Linux system to execute that. sh file)

"Dex2jar.bat Classes.dex"

After you see "done" on the command line, there will be "Classes.dex.dex2jar.jar" files in the Dex2jar folder.

This is the legendary jar bag.

  

3. View. jar file; This step is traditional anti-compilation, need tool assistance, I use the tool is Jd-gui (Http://java.decompiler.free.fr/?q=jdgui)

Download the corresponding version of your system, unzip, (I XP system) you will see an. exe file, yes it is single file green version

Double-click to select the. jar generated in the second step, OK, is your project completely restored? (internal class words restored after the structure looked a little dislike)

Yes, so simple to let your code exposed, love dearly not?

[I don't have a sticker here, the company's project]

Ok, next talk about how to confuse it, the network of many introduction Proguard confused Android Project article, are copied to paste,

A few of them are talking without a head, no end, I read long time, Leng didn't understand,......

Did you see Proguard in the Android SDK \ Tools directory?

Create a new 2.3.3 project and you will see a proguard.cfg file in the project file?

Well, the great Google has done so much for us, but it's starting from 2.3,

What about my sad project (based on the 2.2 SDK)? (Does it have to be cruel to set the project property to 2.3?)

In fact, even if you do, Google will not for you to the Proguard.cfg file to fill the)

Oh, actually do not, you just have to copy the Proguard.cfg file to your old project is good,

Of course this is not enough, because Google is the default not to confuse the project

To enable Proguard-so-it runs as part of an Ant or Eclipse build,

Set the Proguard.config property in the <project_root>/default. properties file.

The path can be a absolute path or a path relative to the project ' s root.

Google tells us to also configure Default.properties

Well

Add the Proguard.config=proguard.cfg

OK, again, create a new. apk file,

Then use the method above to decompile your project, you will see the AA bb cc package, the AA bb cc class and the AA bb cc variable name, method name.

I'm sure you're getting dizzy with this, right?

And look at the Proguard.cfg file.

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends Android.app.Activity
-keep public class * extends Android.app.Application
-keep public class * extends Android.app.Service
-keep public class * extends Android.content.BroadcastReceiver
-keep public class * extends Android.content.ContentProvider
-keep public class Com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
Native <methods>;
}

-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet, int.);
}

-keepclassmembers enum * {
public static **[] values ();
public static * * VALUEOF (java.lang.String);
}

-keep class * Implements Android.os.Parcelable {
public static final Android.os.parcelable$creator *;
}

Here is Google by default does not confuse Activity, Service ... The subclass of the class, as seen in the above, is reserved for all activity's subclass names.

If you want to customize the details of the confusion, think about the configuration file.

-injars Androidtest.jar "jar Package Address"
-outjars out "Output address"

The jar of the library referenced by-libraryjars ' D:\android-sdk-windows\platforms\android-9\android.jar ', used to parse the jar class specified by Injars "

-optimizationpasses 5
-dontusemixedcaseclassnames "does not produce a variety of class names when confused"
-dontskipnonpubliclibraryclasses "Specifies that non-public library classes are not ignored. 】
-dontpreverify "No pre-check"

-verbose
-optimizations!code/simplification/arithmetic,!field/*,!class/merging/* "Optimization"

-keep public class * extends Android.app.Activity "Do not confuse and remain as is"
-keep public class * extends Android.app.Application
-keep public class * extends Android.app.Service
-keep public class * extends Android.content.BroadcastReceiver
-keep public 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 Public Abstract Interface com.asqw.android.listener{
Public protected <methods>; "All methods are not confused"
}
-keep public class com.asqw.android{
public void Start (java.lang.String); "No confusion with this method"
}

-keepclasseswithmembernames class * {"protects the name of a member of a specified class and class if all the specified class members are present (after the compression step)"

Native <methods>;
}

-keepclasseswithmembers class * {"Protects the members of the specified class and class, but the condition is that all specified classes and class members are to be present." 】
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 {"Protects members of a specified class if this class is protected they will be better protected"
public void * (Android.view.View);
}

-keepclassmembers enum * {
public static **[] values ();
public static * * VALUEOF (java.lang.String);
}

-keep class * Implements Android.os.Parcelable {"Protection of members of specified class files and classes"
public static final Android.os.parcelable$creator *;
}

Reference: http://blog.csdn.net/vrix/article/details/7100841

Several exceptions that often occur after adding a third-party jar package:

Proguard returned with error code 1.See console

Scenario 1:
Proguard returned with error code 1. See console
Error:c:/documents (the system cannot find the specified file)
Later found because the entire project was put on the desktop, and the desktop directory is c:/documents and settings/administrator/desktop, in which there are spaces, and proguard to compile the time is not allowed to have spaces
If the correct path is not good enough, delete Proguard directly.

Note: The SDK and program paths are best not to have whitespace

Scenario 2:

Proguard returned with error code 1. See console
Abnormal:

Java.lang.ArrayIndexOutOfBoundsException

Workaround: Change " -dontpreverify" in Proguard.cfg to "-dontoptimize"

Reference article: http://groups.google.com/group/android-developers/browse_thread/thread/eca3b0f5ce6ad00f

I delete the Proguard folder (which is empty at this time) in the project and then run the project again, OK.

Scenario 3:

[2011-10-21 13:22:32-zmksmarket_build_v1.0] Proguard returned with error code 1. See console

[2011-10-21 13:22:32-zmksmarket_build_v1.0] java.io.IOException:Can ' t read [[email protected]] (No such file or Directo Ry

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Inputreader.readinput (inputreader.java:230)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Inputreader.readinput (inputreader.java:200)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Inputreader.readinput (inputreader.java:178)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Inputreader.execute (inputreader.java:100)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Proguard.readinput (proguard.java:195)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Proguard.execute (proguard.java:78)

[2011-10-21 13:22:32-zmksmarket_build_v1.0] at Proguard. Proguard.main (proguard.java:499)

The reason for throwing such an exception is that the reference path of the third-party jar is incorrect, and the jar package that needs to be ignored is not found.

Reference: Http://stackoverflow.com/questions/4884456/android-proguard-java-io-ioexception-cant-read-proguard-classpathentry

Android Code obfuscation

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.