Zelix KlassMaster - Documentation

Calling Zelix KlassMaster™ from Gradle

Zelix KlassMaster™ exposes a generic Java API that allows it to be called by a build tool. A basic Gradle plugin for the Zelix KlassMaster™ obfuscator is built on this API and can be downloaded as zkm-gradle-plugin-1.0.0.zip. An example of how to use the Gradle plugin can be downloaded as zkm-gradle-plugin-use-1.0.0.zip.

Note that versions of Gradle after Gradle 6.5.1 can automatically alter the bytecode that they run. We have found that this can cause Zelix KlassMaster™ to fail. If you are using a version of Gradle newer than Gradle 6.5.1 then you should set org.gradle.internal.instrumentation.agent=false in your gradle.properties but even this will not work in all cases.

This problem has been reported to the Gradle development team.

The plugin

The plugin can be built and installed with the following command.

gradle build install

Note that the ZKM_JAR_PATH property in the gradle.properties must be set to the path to your Zelix KlassMaster™ distribution's ZKM.jar file. Also note that the JAVA_HOME environment variable may need to be set.

Using the plugin

Once the plugin has been installed, it can be used with the following command.

gradle zkmTask

As mentioned above, an example of how to use the Gradle plugin can be downloaded as zkm-gradle-plugin-use-1.0.0.zip. Note that the ZKM_JAR_PATH property in the gradle.properties must be set to the path to your Zelix KlassMaster™ distribution's ZKM.jar file. Also note that the JAVA_HOME environment variable may need to be set.

An example build.gradle, gradle.properties and ZKM Script for using the plugin are shown below.

Example build.gradle

apply plugin: 'com.zelix.gradle.plugin'

zkmSetting {
    //Must be set to the ZKM Script to execute.
    scriptName = "/Projects/myScript.txt" 
	
    /* Optionally can also set the following.  
	   They are shown with their default settings.
       logFileName = "ZKM_log.txt"
       trimLogFileName = "ZKM_TrimLog.txt"
       defaultExcludeFileName = "defaultExclude.txt"
       defaultTrimExcludeFileName = "defaultTrimExclude.txt"
       defaultDirectoryName
       isVerbose = true
       isParseOnly = false
       extraProperties = new Properties()
    */
}

buildscript {
    repositories {
        mavenLocal()
    }
    dependencies {
	    //ZKM_JAR_PATH must point to your ZKM.jar
        classpath files("$ZKM_JAR_PATH") 
        classpath 'com.zelix.gradle:plugin:1.0.0'
    }
}

Example gradle.properties

#ZKM_JAR_PATH must be set to point to your ZKM.jar
ZKM_JAR_PATH=/Projects/ZKM.jar
#Other properties that are set here will be accessible in the ZKM Script
CLASSPATH_LIBS=/libs/Jar0.jar;/libs/Jar1.jar
OPEN_DIR=/Projects
JAR_FILE_TO_OBFUSCATE=MyJarFile.jar
IS_KEEP_GENERICS=true
SAVE_DIR=/Projects/save

Example ZKM Script

//System variables shown in blue. 
//These will be replaced with corresponding values in System properties 
//or gradle.properties.
classpath "%CLASSPATH_LIBS%"
          ;

open      "%OPEN_DIR%%file.separator%%JAR_FILE_TO_OBFUSCATE%";

trimExclude *.*^ public static main(java.lang.String[]);

trim;

exclude     *.^*^ public static main(java.lang.String[]);

obfuscate   keepInnerClassInfo=false
            keepGenericsInfo=%IS_KEEP_GENERICS%
            obfuscateFlow=aggressive
            exceptionObfuscation=heavy
            encryptStringLiterals=flowObfuscate
            ;

saveAll   "%SAVE_DIR%";
 
Documentation Table of Contents
Zelix KlassMaster - Java Obfuscator