### methodParameterChangesExclude Matching Examples Source: http://www.zelix.com/klassmaster/docs/methodParameterChangesExcludeStatement.html Examples demonstrating various matching patterns for methods based on modifiers, names, arguments, and annotations. ```text methodParameterChangesExclude *.* *(*) and //Match references to all methods *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match references to all methods that throw "java.io.IOException". //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*); and ``` -------------------------------- ### ObfuscateExceptionsUnexclude Configuration Examples Source: http://www.zelix.com/klassmaster/docs/obfuscateExceptionsUnexcludeStatement.html Examples demonstrating various patterns for unexcluding methods, constructors, and classes from exception obfuscation. ```text obfuscateExceptionsUnexclude pack2.Class1 method1(int) and //Unexclude method1(int) in class pack2.Class1 from exception obfuscation *.* *(*) and //Unexclude all methods from exception obfuscation *.* (*) and //Unexclude all contructors from exception obfuscation *.* (*) and //Unexclude all static initializers from exception obfuscation *.* m*() and //Unexclude all methods taking no parameters with names matching "m*" *.* *(*) throws java.io.IOException and //Unexclude all methods that throw java.io.IOException. !(pack1*.)* (m* && !(ma* || me*))() and //Unexclude all methods in packages that don't start with "pack1" //and that have names that start with "m" but not "ma" or "me" *.* abstract *(java.lang.String) and //Unexclude the names of all "abstract" methods that //take a single String. //Unexclude all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and "MyJar*.jar"!*.* and //Unexclude all classes contained in a JAR file with a name matching "MyJar*.jar" //Unexclude all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### methodParameterChangesInclude Syntax Examples Source: http://www.zelix.com/klassmaster/docs/methodParameterChangesIncludeStatement.html Examples demonstrating various method matching patterns including modifiers, argument types, annotations, and interface implementation. ```text methodParameterChangesInclude *.* *(*) and //Match references to all methods *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match references to all methods that throw "java.io.IOException". //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*); and ``` -------------------------------- ### Build and Install Plugin Command Source: http://www.zelix.com/klassmaster/docs/buildToolGradle.html Command to build and install the Zelix KlassMasterâ„¢ Gradle plugin. ```bash gradle build install ``` -------------------------------- ### Install Zelix KlassMaster Plugin Source: http://www.zelix.com/klassmaster/docs/buildToolMaven.html Command to install the zkm-plugin-1.0.4.jar into the local Maven repository. ```bash mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -D"file=zkm-plugin-1.0.4.jar" -D"ZKM_HOME=_pathToDirectory_" ``` -------------------------------- ### Method Prefix Exclude Configuration Source: http://www.zelix.com/klassmaster/docs/excludeStatement.html Examples of excluding 'get' and 'set' prefixes for methods with specific parameter signatures. ```text exclude *.* get() and //Exclude the "get" prefix in all method names starting with "get" that take no parameters *.* set(java.lang.String); //Exclude "set" prefix in all methods starting with "set" which take a single String parameter ``` -------------------------------- ### Obfuscate Flow Exclude Configuration Examples Source: http://www.zelix.com/klassmaster/docs/obfuscateFlowExcludeStatement.html Various examples demonstrating how to exclude specific methods, constructors, initializers, and methods based on patterns, annotations, or interfaces. ```text obfuscateFlowExclude pack2.Class1 method1(int) and //Exclude method1(int) in class pack2.Class1 from flow obfuscation *.* *(*) and //Exclude all methods from flow obfuscation *.* (*) and //Exclude all contructors from flow obfuscation *.* (*) and //Exclude all static initializers from flow obfuscation *.* m*() and //Exclude all methods taking no parameters with names matching "m*" *.* *(*) throws java.io.IOException and //Exclude all methods that throw java.io.IOException. !(pack1*.)* (m* && !(ma* || me*))() and //Exclude all methods in packages that don't start with "pack1" //and that have names that start with "m" but not "ma" or "me" *.* abstract *(java.lang.String) and //Exclude the names of all "abstract" methods that //take a single String. //Exclude all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Exclude all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### ObfuscateFlowUnexclude Configuration Examples Source: http://www.zelix.com/klassmaster/docs/obfuscateFlowUnexcludeStatement.html Examples of various obfuscateFlowUnexclude configurations for targeting specific classes, methods, constructors, and annotations. ```text obfuscateFlowUnexclude pack2.Class1 method1(int) and //Unexclude method1(int) in class pack2.Class1 from flow obfuscation *.* *(*) and //Unexclude all methods from flow obfuscation *.* (*) and //Unexclude all contructors from flow obfuscation *.* (*) and //Unexclude all static initializers from flow obfuscation *.* m*() and //Unexclude all methods taking no parameters with names matching "m*" *.* *(*) throws java.io.IOException and //Unexclude all methods that throw java.io.IOException. !(pack1*.)* (m* && !(ma* || me*))() and //Unexclude all methods in packages that don't start with "pack1" //and that have names that start with "m" but not "ma" or "me" *.* abstract *(java.lang.String) and //Unexclude the names of all "abstract" methods that //take a single String. //Unexclude all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and "MyJar*.jar"!*.* and //Unexclude all classes contained in a JAR file with a name matching "MyJar*.jar" //Unexclude all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### Method Parameter Obfuscation Include Examples Source: http://www.zelix.com/klassmaster/docs/methodParameterObfuscationIncludeStatement.html Examples demonstrating various matching patterns for methods, including modifiers, argument types, exceptions, and annotations. ```text methodParameterObfuscationInclude *.* *(*) and //Match references to all methods *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match references to all methods that throw "java.io.IOException". //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*); and ``` -------------------------------- ### Class Suffix Exclude Configuration Examples Source: http://www.zelix.com/klassmaster/docs/excludeStatement.html Examples demonstrating how to define exclusion rules for RMI stubs, Java Bean info, and interface-based naming patterns. ```text exclude *.__Skel and //Exclude the "_" prefix and the "_Skel" suffix in all classes //with unqualified names starting with "_" and ending with "_Skel" BeanInfo search pack1.*, pack2 and //Exclude the "BeanInfo" suffix in all classes that end with it //that are in the default package. Search packages matching //"pack1.*" or "pack2" for a class with an original name //matching the non-suffix part of the class name. pack1.X implements pack2.Class2; //Exclude the "X" suffix in all classes that end with it //that are in "pack1" and implement "pack2.Class". ``` -------------------------------- ### Exclude Statement Examples Source: http://www.zelix.com/klassmaster/docs/excludeStatement.html Examples demonstrating various ways to exclude methods using class, modifier, signature, and annotation patterns. ```text exclude *.* *(*) and //Exclude all method names *.* !static m*() and //Exclude all non-static methods taking no parameters with names matching "m*" //Exclude all "native" methods. Also exclude the containing package and class names. *.^*^ native *(*) and *.* *(*) throws java.io.IOException and //Exclude all methods that throw java.io.IOException. //Exclude the names of all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and pack1.Class1 *(*) +signatureClasses and //Exclude all method names in pack1.Class1 along with //the matching methods' return and parameter types //Exclude all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Exclude all methods annotated with a class matching *.MyAnnotation0. "MyJar*.jar"!*.* *(*) and //exclude all methods contained in a JAR file with a name matching "MyJar*.jar" *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### Run ZKM with Reproducible Configuration Source: http://www.zelix.com/klassmaster/docs/tutorials/reproducibleOutputTutorial.html Command line example for Windows to execute ZKM with specific flags for reproducible output. ```bash java -D"ZKM_USE_PARALLEL=false" -D"ZKM_REPRODUCIBLE_RANDOM=true" -D"ZKM_RANDOM_SEED=962008" -jar ZKM.jar MyScript.txt ``` -------------------------------- ### Example Obfuscated Stack Trace Source: http://www.zelix.com/klassmaster/docs/toolsStackTraceTranslate.html A sample stack trace showing obfuscated class and method names. ```text Exception in thread "main" java.lang.NullPointerException at a.a.c.a(c.java:7) at a.a.b.a(b.java:7) at a.a.a.a(a.java:3) at a.a.a.main(a.java:10) ``` -------------------------------- ### Class Specification Examples Source: http://www.zelix.com/klassmaster/docs/ignoreMissingReferencesStatement.html Demonstrates ignoring missing classes using various package and name patterns. ```text ignoreMissingReferences * and //Ignore all missing classes in the default package *.Class1 and //Ignore all missing classes with the unqualified class name "Class1" pack0.*.* and //Ignore all missing classes in a sub-package of "pack0" pack1..*; //Ignore all missing classes in "pack1" or any sub-package of "pack1" ``` -------------------------------- ### Package Unexclude Parameters Source: http://www.zelix.com/klassmaster/docs/unexcludeStatement.html Examples of package unexclusion patterns using wildcards and logical operators. ```text unexclude pack1.pack2. and //unexclude the package "pack1.pack2" *. and //unexclude all packages p*1.*.p*1. and //unexclude any package matching "p*1.*.p1" pack2.*. and //unexclude all the sub-packages of "pack2" pack3.. and //unexclude "pack3" and all sub-packages of "pack3" (pack4.*. && !(pack3.pack0. || pack3.pack2.)); //unexclude all the sub-packages of "pack4" except for "pack0" and "pack2" ``` -------------------------------- ### Configure build.gradle for ZKM Source: http://www.zelix.com/klassmaster/docs/buildToolGradle.html Example configuration for applying the ZKM plugin and defining buildscript dependencies. ```groovy 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' } } ``` -------------------------------- ### removeMethodCallsExclude Statement Examples Source: http://www.zelix.com/klassmaster/docs/removeMethodCallsExcludeStatement.html Various examples demonstrating how to match and exclude method references using different criteria such as package, modifiers, annotations, and signatures. ```text removeMethodCallsExclude *.* *(*) and //Match references to all methods containedIn{pack0.* *(*)} *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //where the reference occurs in a method within the "pack0" package *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match references to all methods that throw "java.io.IOException". //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all methods in pack1.Class1 along with the matching methods' return and parameter types //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*) and //Match references to all methods in java.lang.System which occur in a method annotated with a class matching "*.MyAnnotation0". containedIn{*.* @*.MyAnnotation0 *(*)} java.lang.System *(*); ``` -------------------------------- ### Execute ZKM Task Command Source: http://www.zelix.com/klassmaster/docs/buildToolGradle.html Command to run the obfuscation task after plugin installation. ```bash gradle zkmTask ``` -------------------------------- ### Method Specification Examples Source: http://www.zelix.com/klassmaster/docs/ignoreMissingReferencesStatement.html Demonstrates ignoring missing methods, including constructors and methods based on interface implementation. ```text ignoreMissingReferences *.* *(*) and //Ignore all missing methods *.* () and //Ignore all missing no argument constructors //Ignore all missing the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) ; ``` -------------------------------- ### removeMethodCallsInclude Statement Examples Source: http://www.zelix.com/klassmaster/docs/removeMethodCallsIncludeStatement.html Various examples demonstrating how to target method references using different criteria such as modifiers, annotations, and containment clauses. ```text removeMethodCallsInclude *.* *(*) and //Match references to all methods containedIn{pack0.* *(*)} *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //where the reference occurs in a method within the "pack0" package *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match references to all methods that throw "java.io.IOException". //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all methods in pack1.Class1 along with the matching methods' return and parameter types //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*) and //Match references to all methods in java.lang.System which occur in a method annotated with a class matching "*.MyAnnotation0". containedIn{*.* @*.MyAnnotation0 *(*)} java.lang.System *(*); ``` -------------------------------- ### Method reference include parameters Source: http://www.zelix.com/klassmaster/docs/obfuscateReferencesIncludeStatement.html Examples of method reference matching patterns including signatures, throws clauses, and containment constraints. ```text obfuscateReferencesInclude *.* *(*) and //Match references to all methods //Match references to all non-static methods taking no parameters with names matching "m*" //where the reference occurs in a method within the "pack0" package containedIn{pack0.* *(*)} *.* !static m*() and //Match references to all non-static methods taking no parameters with names matching "m*" *.* !static m*() and //Match references to all "native" methods. Also match the containing class. *.*^ native *(*) and //Match references to all methods that throw "java.io.IOException". *.* *(*) throws java.io.IOException and //Match references to all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match references to all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match references to all classes contained in a JAR file with a name matching "MyJar*.jar" "MyJar*.jar"!*.* and //Match references to all methods annotated with a class matching "*.MyAnnotation0". *.* @*.MyAnnotation0 *(*) and //Match references to all methods in java.lang.System which occur in a method annotated //with a class matching "*.MyAnnotation0". containedIn{*.* @*.MyAnnotation0 *(*)} java.lang.System *(*); ``` -------------------------------- ### Windows Classpath Configuration Source: http://www.zelix.com/klassmaster/docs/classpathStatement.html Examples for setting the classpath on Windows environments for Java versions before and after Java 9. ```ZKM Script classpath "." "c:\jdk1.8.0\jre\lib\rt.jar" "c:\lib\*.jar"; ``` ```ZKM Script classpath ".;c:\jdk1.8.0\jre\lib\rt.jar;c:\lib\*.jar"; ``` ```ZKM Script classpath "." "c:\JDK\jdk1.9.0\lib\jrt-fs.jar" "c:\lib\*.jar"; ``` ```ZKM Script classpath ".;c:\JDK\jdk1.9.0\lib\jrt-fs.jar;c:\lib\*.jar"; ``` -------------------------------- ### Trim Statement Usage Source: http://www.zelix.com/klassmaster/docs/trimStatement.html Examples of using the trim statement with default settings and explicit parameter configuration. ```ZKM Script trim; //Trim using the defaults trim deleteSourceFileAttributes=false //Don't remove Source File Attributes deleteDeprecatedAttributes=true //Remove Deprecated Attributes deleteAnnotationAttributes=false //Don't remove annotation attributes deleteExceptionAttributes=false //Don't remove exception attributes deleteDebugExtensionAttributes=true //Remove SourceDebugExtension attributes deleteUnknownAttributes=false; //Don't remove unrecognized attributes ``` -------------------------------- ### Define ZKMScript.txt Customizing Statements Source: http://www.zelix.com/klassmaster/docs/tutorials/proGuardTranslateTutorial.html Example of a ZKMScript.txt file using the PROGUARD_LOG_DIR system property to configure obfuscation settings. ```text obfuscate flow=light, exception=light, stringEncryption=on, logDir="${PROGUARD_LOG_DIR}"; ``` -------------------------------- ### Method Exclusion Parameters Source: http://www.zelix.com/klassmaster/docs/accessedByReflectionStatement.html Examples of method matching patterns including argument types, constructors, and exception signatures. ```text accessedByReflection *.* *(*) and //Match all methods *.* !static m*() and //Match all non-static methods taking no parameters with names matching "m*" *.* public () and //Match all public no argument constructors //Match all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match all methods that throw java.io.IOException. //Match all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match all methods in pack1.Class1 along with the matching methods' return and parameter types pack1.Class1 *(*) +signatureClasses and //Match all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### Define Fixed Classes Statement Source: http://www.zelix.com/klassmaster/docs/fixedClassesStatement.html Example demonstrating the syntax for defining multiple fixed classes using various qualifiers and annotations. ```text fixedClasses pack2.Class1 and //Treat class pack2.Class1 as a fixed class pack3.* and //Treat all classes in package "pack3" as fixed classes //Treat all classes contained in a JAR file with a name matching "MyJar*.jar" as fixed classes "MyJar*.jar"!*.* and //Treat all classes annotated which an annotation matching *.MyAnnotation0 as fixed classes @*.MyAnnotation0 *.*; ``` -------------------------------- ### Define ZKM Script Source: http://www.zelix.com/klassmaster/docs/buildToolGradle.html Example ZKM script utilizing system variables defined in gradle.properties. ```text //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%"; ``` -------------------------------- ### Obfuscated Method Reference Example Source: http://www.zelix.com/klassmaster/docs/tutorials/referenceObfuscationTutorial.html The same method after applying reference obfuscation, string encryption, and method parameter changing. ```java private static final String c; public static void method0(final long n4) { /*invokedynamic(j:(Ljava/io/PrintStream;Ljava/lang/String;JJ)V, invokedynamic(\u00ee:(JJ)Ljava/io/PrintStream;, -7703503747166308699L, n4), MyClass.c, -7703568321494008229L, n4)*/ } ``` -------------------------------- ### Configure integerEncryptionExclude parameters Source: http://www.zelix.com/klassmaster/docs/integerEncryptionExcludeStatement.html Examples of exclusion rules for integer constants in methods, using wildcards and specific class paths. ```text integerEncryptionExclude *.* public static *(*) and //Exclude integer constants referenced in any //public static method in any class from encryption pack2.Class1 *(*); //Exclude integer constants referenced in any method //in pack2.Class1 from encryption ``` -------------------------------- ### Configure Method Exclude Parameters Source: http://www.zelix.com/klassmaster/docs/accessedByReflectionExcludeStatement.html Examples of method exclusion patterns including constructors, exceptions, and signature matching. ```text accessedByReflectionExclude *.* *(*) and //Match all methods *.* !static m*() and //Match all non-static methods taking no parameters with names matching "m*" *.* public () and //Match all public no argument constructors //Match all "native" methods. Also match the containing class. *.*^ native *(*) and *.* *(*) throws java.io.IOException and //Match all methods that throw java.io.IOException. //Match all "abstract" methods that take a single String. *.* abstract *(java.lang.String) and //Match all methods in pack1.Class1 along with the matching methods' return and parameter types pack1.Class1 *(*) +signatureClasses and //Match all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Match all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### Package exclude parameters Source: http://www.zelix.com/klassmaster/docs/excludeStatement.html Examples of excluding packages, sub-packages, and using logical operators for package exclusion. ```ZKM Script exclude pack1.pack2. and //exclude the package "pack1.pack2" *. and //exclude all packages p*1.*.p*1. and //exclude any package matching "p*1.*.p1" pack2.*. and //exclude all the sub-packages of "pack2" pack3.. and //exclude "pack3" and all sub-packages of "pack3" (pack4.*. && !(pack3.pack0. || pack3.pack2.)); //exclude all the sub-packages of "pack4" except for "pack0" and "pack2" ``` -------------------------------- ### Simple Stand Alone Translation Example Source: http://www.zelix.com/klassmaster/docs/stackTraceTranslateApi.html Basic usage of the ZKMStackTraceTranslate class to translate a stack trace string. ```java import com.zelix.ZKMStackTraceTranslate; ZKMStackTraceTranslate translator = new ZKMStackTraceTranslate("/projects/ChangeLog.txt", "/projects/MyApplication.jar:/projects/SomeClassLibrary.jar"); String translatedStackTrace = translator.getTranslatedStackTrace(myStackTraceString); ``` -------------------------------- ### Configure pom.xml for Zelix KlassMaster Source: http://www.zelix.com/klassmaster/docs/buildToolMaven.html Example configuration for the zkm-plugin within a Maven project's pom.xml file. ```xml 4.0.0 com.zelix.plugins test 1.0.4 jar Test of ZelixKlassMasterMojo true 4.11 UTF-8 1.8 1.8 junit junit ${junit.version} compile org.apache.maven.plugins maven-compiler-plugin 3.1 1.8 1.8 ** com.zelix.plugins zkm-plugin 1.0.4 com.zelix.plugins ZKM 20.0.0 system ${ZKM_HOME}/ZKM.jar package obfuscate false script.txt ${java.home}/lib/rt.jar D:\Java\apache-ant-1.9.2\lib\ant.jar ** ``` -------------------------------- ### Integer Encryption Unexclude Examples Source: http://www.zelix.com/klassmaster/docs/integerEncryptionUnexcludeStatement.html Demonstrates various ways to unexclude integer constants from encryption using class-based patterns. ```text integerEncryptionUnexclude pack2.Class1 and //unexclude **all** integer constants in class pack2.Class1 from encryption *.* and //unexclude **all** integer constants in all classes from encryption //unexclude **all** integer constants in all classes contained in a JAR file with a name matching "MyJar*.jar" "MyJar*.jar"!*.* and //unexclude **all** integer constants in all classes annotated which an annotation matching *.MyAnnotation0 @*.MyAnnotation0 *.*; ``` -------------------------------- ### Usage of obfuscateExceptionsUnexclude Source: http://www.zelix.com/klassmaster/docs/obfuscateExceptionsUnexcludeStatement.html Examples demonstrating how to unexclude various classes and methods from exception obfuscation using different selection patterns. ```ZKM Script obfuscateExceptionsUnexclude * and //unexclude all methods in all classes in default package *.Class1 and //unexclude all methods in all classes with the unqualified class name "Class1" //unexclude all methods in all classes that start with "Class" except for "Class0" and "Class1" *.(Class* && !(Class0 || Class1)) and //unexclude all classes annotated which an annotation matching *.MyAnnotation0 @*.MyAnnotation0 *.*; ``` -------------------------------- ### Define Class Groupings Source: http://www.zelix.com/klassmaster/docs/groupingsStatement.html Examples of defining class groupings using package wildcards, annotation filters, and class exclusions. ```text groupings {pack1.* and pack2.*} //Classes in packages pack1 and pack2 //Classes in package pack3 and all classes annotated which an annotation matching *.MyAnnotation0 //form the 2nd grouping {pack3.* and @*.MyAnnotation0 *.*}; groupings {pack1.* and pack.*.*} //Classes in package pack1 and its subpackages {pack3.!(Class1)} //Classes in package pack3 except Class1 {pack3.Class1}; //Class pack3.Class1 forms its own one class grouping ``` -------------------------------- ### Encrypted Method Example Source: http://www.zelix.com/klassmaster/docs/tutorials/integerEncryptionTutorial.html The same method after applying Integer Encryption and Method Parameter Changes, showing the added decryption logic. ```java private static final long a = o.a(425868181624802497L, 7792344439649777418L, MethodHandles.lookup().lookupClass()).a(188318979481983L); int method0(long var1) { var1 ^= a; return true.g(14977, 1548317666104588234L ^ var1); } ``` -------------------------------- ### Unix Classpath Configuration Source: http://www.zelix.com/klassmaster/docs/classpathStatement.html Examples for setting the classpath on Unix and Mac OS X environments for Java versions before and after Java 9. ```ZKM Script classpath "." "/opt/jdk1.8.0/jre/lib/rt.jar" "/lib/*.jar"; ``` ```ZKM Script classpath ".:/opt/jdk1.8.0/jre/lib/rt.jar:/lib/*.jar"; ``` ```ZKM Script classpath "." "/opt/jdk1.9.0/lib/jrt-fs.jar" "/lib/*.jar"; ``` ```ZKM Script classpath ".:/opt/jdk1.9.0/lib/jrt-fs.jar:/lib/*.jar"; ``` -------------------------------- ### Class unexclude parameters example Source: http://www.zelix.com/klassmaster/docs/longEncryptionUnexcludeStatement.html Demonstrates various ways to unexclude long constants in classes using class-level parameters. ```ZKM Script longEncryptionUnexclude pack2.Class1 and //unexclude **all** long constants in class pack2.Class1 from encryption *.* and //unexclude **all** long constants in all classes from encryption //unexclude **all** long constants in all classes contained in a JAR file with a name matching "MyJar*.jar" "MyJar*.jar"!*.* and //unexclude **all** long constants in all classes annotated which an annotation matching *.MyAnnotation0 @*.MyAnnotation0 *.*; ``` -------------------------------- ### Class exclude parameter examples Source: http://www.zelix.com/klassmaster/docs/accessedByReflectionExcludeStatement.html Demonstrates various patterns for excluding classes from reflection handling, including wildcards, modifiers, and annotations. ```ZKM Script accessedByReflectionExclude * and //Match all classes in the default package *.Class1 and //Match all classes with the unqualified class name "Class1" public !final *.* and //Match all public non-final classes package abstract *.C*s extends pack1.Class1 and //Match all "public abstract" classes that //have an unqualified name matching "C*s" and extend "pack1.Class1". p*.* and //Match all classes in packages that start with the character "p" //Match all classes with the unqualified class name "Class1" also exclude all fields and methods of those classes *.* Class2 + and //Match all classes with a name that start with "Class" except for "Class0" and "Class1" *.(Class* && !(Class0 || Class1)) and "MyJar*.jar"!*.* and //Match all classes contained in a JAR file with a name matching "MyJar*.jar" @*.MyAnnotation0 *.*; //Match all classes annotated which an annotation matching *.MyAnnotation0 ``` -------------------------------- ### Comprehensive ZKM Script Example Source: http://www.zelix.com/klassmaster/docs/langZKMScript.html A sample script demonstrating the usage of various ZKM Script statements, including classpath configuration, file loading, and obfuscation exclusions. ```ZKM Script /*****************************************************************************/ /* Sample ZKM Script using every statement and parameter */ /*****************************************************************************/ classpath ".;c:\jdk1.8.0\jre\lib\rt.jar"; ignoreMissingReferences pack9.Class9 *(*); //ignore missing methods in pack9.Class9 //must precede the open statement open openNestedArchives=true //open nested archives. This is the default. "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** removeMethodCallsInclude java.lang.System print*(*); //Remove System print calls //Don't remove printStackTrace calls removeMethodCallsExclude java.lang.System printStackTrace(*); removeMethodCalls java.lang.System printStackTrace(*); //Remove the specified method calls ``` -------------------------------- ### Field Exclusion Specification Examples Source: http://www.zelix.com/klassmaster/docs/excludeFieldType.html Examples of field exclusion strings defining criteria for fields, modifiers, and containing class properties. ```text *.* implements java.io.Serializable @pack2.MyAnnotation0 !static !transient * ``` ```text public final * extends pack1.Class1 public static final java.lang.String[] f* ``` -------------------------------- ### Comprehensive Zelix KlassMaster Script Example Source: http://www.zelix.com/klassmaster/docs/langZKMScript.html Demonstrates the use of exclusion resets, obfuscation parameters, garbage collection settings, logging, and file system operations. ```Zelix KlassMaster Script //remove effect of any preceding methodParameterChangeInclude or methodParameterChangeExclude resetMethodParameterChangesExclusions; //remove effect of any preceding methodParameterObfuscationInclude //or methodParameterObfuscationExclude resetMethodParameterObfuscationExclusions; 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 deleteXMLComments=false "c:\Temp"; ``` -------------------------------- ### Obfuscate Exceptions Exclude Examples Source: http://www.zelix.com/klassmaster/docs/obfuscateExceptionsExcludeStatement.html Various examples demonstrating how to use the obfuscateExceptionsExclude statement to target specific classes, methods, constructors, and annotations. ```text obfuscateExceptionsExclude pack2.Class1 method1(int) and //Exclude method1(int) in class pack2.Class1 from exception obfuscation *.* *(*) and //Exclude all methods from exception obfuscation *.* (*) and //Exclude all contructors from exception obfuscation *.* (*) and //Exclude all static initializers from exception obfuscation *.* m*() and //Exclude all methods taking no parameters with names matching "m*" *.* *(*) throws java.io.IOException and //Exclude all methods that throw java.io.IOException. !(pack1*.)* (m* && !(ma* || me*))() and //Exclude all methods in packages that don't start with "pack1" //and that have names that start with "m" but not "ma" or "me" *.* abstract *(java.lang.String) and //Exclude the names of all "abstract" methods that //take a single String. //Exclude all the methods of any class implementing "Serializable" in a package that matches "pack1.*" pack1.* implements java.io.Serializable *(*) and //Exclude all methods annotated with a class matching *.MyAnnotation0. *.* @*.MyAnnotation0 *(*); ``` -------------------------------- ### Obfuscate Statement Configuration Examples Source: http://www.zelix.com/klassmaster/docs/obfuscateStatement.html Demonstrates various ways to configure the obfuscate command, from default settings to complex custom configurations. ```Zelix KlassMaster Script obfuscate; //Obfuscate using the defaults obfuscate changeLogFileOut="" //Don't write to a change log file lineNumbers=scramble //Scramble and keep the line number tables obfuscateFlow=none; //Don't obfuscate control flow obfuscate changeLogFileIn="ChangeLogIn.txt" //Use ChangeLogIn.txt as the input change log changeLogFileOut="ChangeLog.txt" //Write to change log file ChangeLog.txt obfuscateFlow=light //Light control flow obfuscation encryptStringLiterals=flowObfuscate //Encrypt String literals using a flow obfuscated decrypt method encryptIntegerConstants=normal //Encrypt integer constants collapsePackagesWithDefault="foo" //Collapse packages into package "foo" newNamesPrefix="Z"; //Prepend "Z" to every new obfuscated name //Use ChangeLogIn0.txt and ChangeLogIn1.txt as loose input change logs obfuscate looseChangeLogFileIn="ChangeLogIn0.txt","ChangeLogIn1.txt"; ``` -------------------------------- ### Decompiled Method Example Source: http://www.zelix.com/klassmaster/docs/tutorials/integerEncryptionTutorial.html A simple method returning an integer constant before encryption. ```java int method0() { return 127; } ``` -------------------------------- ### Decompiled Method Example Source: http://www.zelix.com/klassmaster/docs/tutorials/longEncryptionTutorial.html A standard Java method returning a long constant before obfuscation. ```java long method0() { return 127L; } ``` -------------------------------- ### Open classes with skip clauses Source: http://www.zelix.com/klassmaster/docs/openStatement.html Demonstrates opening a directory of classes while excluding specific files using absolute and relative paths. ```ZKM Script open "C:\directory1\com\mycompany\*.class" //Open all classes in C:\directory1\com\mycompany -"C:\directory1\com\mycompany\X.class" //Don't open X.class -"com\mycompany\Y.class" //Relative path so will match Y.class only if default directory is C:\directory1 ; ``` -------------------------------- ### Field Exclusion Parameters Source: http://www.zelix.com/klassmaster/docs/accessedByReflectionStatement.html Examples of field matching patterns using modifiers, types, and annotations. ```text accessedByReflection *.* * and //Match all fields *.Class1 !transient int f* and //Match all non-transient "int" fields matching "f*" //in classes with the unqualified name "Class1" public *.*^ public volatile * and //Match all "public volatile" fields in //public classes. //Also match the containing class. *.* @*.MyAnnotation0 *; //Match all fields annotated with a class matching *.MyAnnotation0. ``` -------------------------------- ### run(String, Map) Source: http://www.zelix.com/klassmaster/docs/buildToolApi.html Executes a Zelix KlassMaster process using a ProGuard configuration file and a properties map. ```APIDOC ## public static void run(String proGuardConfigFileName, Map propertiesTable) ### Description Executes the ZKM process using a ProGuard-style configuration file. ### Parameters - **proGuardConfigFileName** (String) - Path to the ProGuard configuration file. - **propertiesTable** (Map) - Configuration properties for the execution. ``` -------------------------------- ### Class Unexclude Parameters Source: http://www.zelix.com/klassmaster/docs/unexcludeStatement.html Examples of class unexclusion patterns including modifiers, inheritance, and annotation matching. ```text unexclude * and //unexclude all classes in the default package *.Class1 and //unexclude all classes with the unqualified class name "Class1" pack1..* and //unexclude all classes in "pack1" ot any of its sub-packages public !final *.* and //unexclude all public non-final classes //unexclude all "public abstract" classes that have an unqualified name matching "C*s" and extend "pack1.Class1". package abstract *.C*s extends pack1.Class1 and //unexclude all classes in packages that start with the character "p" and also exclude the names of the enclosing packages. p*.^* and //unexclude all classes that implement Serializable and also exclude all field and method names *.* + implements java.io.Serializable and //unexclude names of all classes that start with "Class" except for "Class0" and "Class1" *.(Class* && !(Class0 || Class1)) and "MyJar*.jar"!*.* and //unexclude all classes contained in a JAR file with a name matching "MyJar*.jar" @*.MyAnnotation0 *.*; //unexclude all classes annotated which an annotation matching *.MyAnnotation0 ``` -------------------------------- ### Apply Method-Level Obfuscation Annotation Source: http://www.zelix.com/klassmaster/docs/tutorials/obfuscationSettingsAnnotationsTutorial.html Example of applying the ZKMMethodLevel annotation to disable obfuscation for a specific method. ```java /** * This method will not be Flow or Exception Obfuscated because of its special annotation. */ @ZKMMethodLevel(obfuscateFlow=FlowObfuscationPolicy.NONE, exceptionObfuscation=ExceptionObfuscationPolicy.NONE) public void m0(int i0) { for(int i=0; i < i0; i++) { if (i == 5) { System.out.println("m0 A"); } else if (i == 6) { System.out.println("m0 B"); } } } ``` -------------------------------- ### Open files and directories Source: http://www.zelix.com/klassmaster/docs/openStatement.html Specify individual files, directories, or patterns to include for obfuscation. ```Zelix KlassMaster open "C:\directory1\Class1.class" //a single class file "C:\directory1\MyJar.jar" //all the class files in a single jar "C:\directory2" //all the class files in a single directory "C:\directory3\*" //all the class files in a single directory AND its subdirectories "C:\directory1\MyJar.jad" //Java ME JAD file will be associated with the JAR it specifies "C:\directory4\*.jar" //all the JAR files in directory4 "C:\directory5\Config.xml" //XML file Config.xml "C:\directory6\*.xml" //all the XML files in directory ; ``` -------------------------------- ### Run Maven Package with ZKM_HOME Source: http://www.zelix.com/klassmaster/docs/buildToolMaven.html Command to execute the package phase while providing the required ZKM_HOME system property. ```bash mvn package -D"ZKM_HOME=_pathToDirectory_" ```