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
            deleteExceptionAttributes=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

obfuscateFlowUnexclude pack1.Class0 foo(int); //Unexclude method "foo(int)" in pack1.Class0

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

stringEncryptionUnexclude pack2.Class2 foo; //Unexclude field "foo" in pack2.Class2

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

accessedByReflection pack1.Class2 foo(*);  //All methods in pack1.Class2 named "foo" accessed by Reflection

accessedByReflectionExclude pack1.Class2 foo(int[]);  //foo(int[]) NOT accessed by Reflection

//Obfuscate all references to method in java.lang.System that are contained in class "pack0.Class0"
obfuscateReferencesInclude containedIn{pack0.Class0 *(*)} java.lang.System *(*); 

//Exclude references to any method named "println" in java.lang.System that are contained in class "pack0.Class0"
obfuscateReferencesExclude  containedIn{pack0.Class0 *(*)} java.lang.System println(*);

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=enhanced      //could be omitted. Default is enhanced
            exceptionObfuscation=light          //could be omitted. Default is light
            autoReflectionHandling=normal   //Default is none for backwards compatability
            autoReflectionPackage="pack0"   //Put autoReflection lookup class into package "pack0"
            autoReflectionHash="SHA-512"    //Use SHA-512 hash in autoReflection lookup class
            collapsePackagesWithDefault="xyz" //could be omitted. Default is to not collapse packages
            obfuscateReferences=normal;       //Obsfuscate references
            obfuscateReferenceStructures=inSpecialClass //could be omitted. Default is to use a special class
            obfuscateReferencesPackage="pack0" //Put special lookup class into package "pack0"
            lineNumbers=delete                //could be omitted. Default is delete
            localVariables=delete             //could be omitted. Default is delete
            methodParameters=keepVisible      //could be omitted. Default is keepVisible
            mixedCaseClassnames=ifInArchive   //could be omitted. Default is ifInArchive
            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
            keepBalancedLocks=false           //could be omitted. Default is false
            preverify=true                    //could be omitted. Default is true
            assumeRuntimeVersion="8"          //Default is derived from lowest version an opened classes
            legalIdentifiers=true             //Deprecated
            hideFieldNames=false              //Deprecated
            hideStaticMethodNames=false;      //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

resetAccessedByReflection;  //remove effect of any preceding accessedByReflection
                            //and accessedByReflectionExclude

resetObfuscateReferenceExclusions; //remove effect of any preceding obfuscateReferencesInclude
                                   //and obfuscateReferencesExclude
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 obfuscate a second time";     //prints to standard out and the log

obfuscate; //Using implicit defaults

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

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