it-notepad.com

Obfuscate Java executable “jar”

Obfuscate Java executable “jar”

How obfuscate standart java application? It’s very simple: you need use Proguard tool

1. Download and install proguard.
2. Create proguard config file(ex. proguard-project.txt)

 

-injars application.jar
-outjars obfuscate_application.jar
-libraryjars <java.home>/lib/rt.jar

-dontusemixedcaseclassnames
-verbose

-dontoptimize

-libraryjars jni/keyboardhook-win-amd64.lib
-libraryjars jni/libquaqua64.jnilib
-libraryjars libs/keyboardhook-win-amd64.lib
-libraryjars libs/keyboardhook-win-x86.lib

-keepattributes *Annotation*

-keep,includedescriptorclasses public class com.sun.jna.** {
    <fields>;
    <methods>;
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keep class org.sqlite.** { *; }
-keep class org.apache.** { *; }
-keep class com.sun.jna.** { *; }
-keep class de.ksquared.**{ *; }
-keep class ch.randelshofer.**{ *; }
-keep class org.netbeans.**{ *; }
-keep class com.apple.**{ *; }
-keep class org.kobjects.**{ *; }
-keep class org.ksoap2.**{ *; }
-keep class org.xmlpull.**{ *; }
-keep class org.kxml2.**{ *; }

-keep class com.tulskiy.**{ *; }

-dontnote com.sun.jna.**
-dontnote javax.swing.**
-dontnote ch.randelshofer.**
-dontnote org.apache.**
-dontnote org.kobjects.**

-dontwarn com.google.android.gms.**
-dontwarn com.google.common.annotations.**
-dontwarn com.google.common.cache.**
-dontwarn com.google.common.primitives.**
-dontwarn org.xmlpull.v1.**
-dontwarn org.sqlite.**
-dontwarn org.apache.**
-dontwarn com.sun.jna.**
-dontwarn ch.randelshofer.**
-dontwarn org.netbeans.modules.**

-keepclasseswithmembernames class * {
    native <methods>;
}

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

-keepclassmembers class **.R$* {
    public static <fields>;
}

 

3. run command(on Windows cmd.exe or *.nix terminal)
proguard @proguard-project.txt
4. Profit!!!

Explanations:
-injars – input jar file
-outjars – output jar file

Exit mobile version