Zelix KlassMaster - Documentation
 

The ZKM Script Language

The ZKM Script language is used to write scripts that automate the process of using Zelix KlassMaster. They allow you to integrate Zelix KlassMaster into your development procedures. A quick way to experiment with and learn the language is by using the interactive "ZKM Script Helper" tool.

A ZKM Script consists of a sequence of comments and ZKM Script statements. White space is ignored and note that ZKM Script is case sensitive. ZKM Script comments are identical to Java comments. You can use "//" to comment a line or "/* ... */" to comment a block.

Preprocessor directives are not part of the ZKM Script language. They are actioned by the preprocessor prior to the ZKM Script being parsed and executed. The ZKM Script interpreter doesn't understand and normally will never see preprocessor directives.

In describing the syntax of ZKM Script statements the following notation is used:
  • X | Y | Z means X or Y or Z
  • [X] means X is optional
  • (X)* means zero or more occurrences of X
  • (X)+ means one or more occurrences of X
  • X means X is a key word

A ZKM Script statement is always terminated by a ";". The ZKM Script statements are:
 

An example using every statement and parameter with color coding


/*****************************************************************************/
/* Sample ZKM Script using every statement and parameter                     */
/*****************************************************************************/

classpath   ".;c:\jdk1.4.0\jre\lib\rt.jar";

open     "c:\directory1\Class1.class" //load a specific class
         "c:\directory1\MyZip.zip"    //load all classes in a zip file
         "c:\directory1\MyJar.jar"    //load all classes in a jar file
         "c:\directory2"              //load all classes in a specific directory
         "c:\directory3\*";           //load all classes in a directory and its subdirectories

trimExclude pack1.Class1^ public static main(java.lang.String[]) and
            pack2.*.* public *(*);  

trimUnexclude pack2.pack3.* public method(*); //Don't exclude public methods in pack2.pack3

trim        deleteSourceFileAttributes=false  //could be omitted. Default is false
            deleteDeprecatedAttributes=true   //could be omitted. Default is true
            deleteAnnotationsAttributes=false //could be omitted. Default is false
            deleteUnknownAttributes=false;    //could be omitted. Default is false 

exclude     p*2.* and
            p*.C*1 and
            *.Class2 implements pack3.Class3, pack4.Class4 and
            @pack2.MyAnnotation *.* @pack2.MyAnnotation *(@*.* int, *) and
            public abstract *.* private transient java.lang.String f* and
            *.* extends pack2.Class2 public native m*(*) and
            *.<link>_Skel extends pack2.Class2 implements pack3.Class3 search pack4, pack4.p*5;

unexclude   pack2.Class4; //Don't exclude pack2.Class4

obfuscateFlowExclude pack2.Class2 method1() and //Don't flow obfuscate method1() in pack2.Class2
                     pack1.* *(*) and //Don't flow obfuscate any method in package pack1
                     pack1.*; //Don't flow obfuscate methods or add special fields to pack1 classes

stringEncryptionExclude pack2.Class2 and //Don't string encrypt any String literals in pack2.Class2
                        *.* public *; //Don't string encrypt the value of any public field

existingSerializedClasses pack2.Class2; //Changes to pack2.Class2 must be Serialization compatible

fixedClasses pack2.Class2; //Insulates pack2.Class2 from any obfuscation

groupings {pack1.* and pack2.*}   //1st grouping contains pack1 and pack2 classes
          {pack3.* and pack4.*};  //2nd grouping contains pack3 and pack4 classes

obfuscate   changeLogFileIn="ChangeLogIn.txt" //omit parameter if no input change log
            changeLogFileOut="ChangeLog.txt" //could be omitted. Default is ChangeLog.txt
            aggressiveMethodRenaming=false      //could be omitted. Default is false
            keepInnerClassInfo=false            //could be omitted. Default is false
            keepGenericsInfo=true               //could be omitted. Default is true
            obfuscateFlow=light                 //could be omitted. Default is light
            encryptStringLiterals=flowObfuscate //could be omitted. Default is flowObfuscate
            collapsePackagesWithDefault="xyz" //could be omitted. Default is to not collapse packages
            lineNumbers=delete                //could be omitted. Default is delete
            localVariables=delete             //could be omitted. Default is delete
            newNamesPrefix="Z"                //Prefix all newly generated names with "Z"
            randomize=false                   //could be omitted. Default is false
            allClassesOpened=true             //could be omitted. Default is true
            deriveGroupingsFromInputChangeLog=false //could be omitted. Default is false
            legalIdentifiers=true             //Deprecated
            hideFieldNames=false              //Deprecated
            hideStaticMethodNames=false       //Deprecated
            addCorruptInfo=light;             //Deprecated

resetTrimExclusions;          //remove the effect of any preceding trimExclude statement

resetExclusions;              //remove the effect of any preceding exclude statement

resetObfuscateFlowExclusions; //remove effect of any preceding obfuscateFlowExclude statement

resetStringEncryptionExclusions; //remove effect of any preceding stringEncryptionExclude

resetExistingSerializedClasses; //remove effect of any preceding existingSerializedClasses

resetFixedClasses; //remove effect of any preceding fixedClasses

resetGroupings; //remove effect of any preceding groupings

exclude     *. and          //exclude all packages
            *.* and         //exclude all classes
            *.* * and       //exclude all fields
            *.* *(*);       //exclude all methods

gc 500;     //500 could have been omitted. 500ms sleep is the default.

print       "About to unobfuscate";     //prints to standard out and the log

//Note that the "unobfuscated" statement is deprecated!
unobfuscate changeLogFileIn="ChangeLogIn.txt"       //omit parameter if no input change log
            changeLogFileOut="ChangeLog.txt"        //could be omitted. Default is ChangeLog.txt
            keepInnerClassInfo=false                //could be omitted. Default is false
            deriveSubclassNamesFromSuperclass=true; //could be omitted. Default is true

execute     "deltree /Y c:\Temp"; //executes a simple OS command

saveAll     archiveCompression=asIs "c:\Temp";    
 
Documentation Table of Contents