Zelix KlassMaster - Documentation
 

The obfuscateExceptionsExclude Statement

The ZKM Script obfuscateExceptionsExclude statement excludes the specified methods from being exception obfuscated by the Zelix KlassMaster™ obfuscate statement. It has no impact if the obfuscate statement's exceptionObfuscation parameter is set to none. Successive obfuscateExceptionsExclude statements have a cumulative effect. Once an exclusion has been set the only way to remove it is with a resetObfuscateExceptionsExclusions statement.

The remainder of this page is organized into the following sections.

Explanation and Examples

The primary effect of the obfuscateExceptionsExclude statement is to exclude methods from exception obfuscation. You can use either class or method parameters. If you use a class parameter then all of the methods of any matching classes will be excluded from exception obfuscation.

obfuscateExceptionsExclude statement parameters may be loosely categorized into the following groups

Class exclude parameters

Put informally (with mandatory components in bold), the syntax of an obfuscateExceptionsExclude class parameter is:
<classAnnotations> <classModifiers> "<archiveQualifier>"!<packageQualifiers>.<className> <containingClause> <extendsClause> <implementsClause>;

For a class and all of its methods to be excluded from exception obfuscation, all of the following must be true:
  • Its annotations must match any specified annotations.
  • Its modifiers (e.g. public final) must match all parameter modifiers. So if the parameters are public abstract !interface then the class must be public, abstract and NOT an interface to be excluded.
  • If the parameter has an archive qualifier then the class must be contained in an archive which matches that archive qualifier.
  • Its package qualifiers must match any specified package exclude parameter component. If there is no package exclude parameter component then the class must be in the default package.
  • Its unqualified name must match the specified class name specification.
  • If the parameter has a containing clause then the class must contain members which match the specified class
  • If the parameter has an extends clause then the class must be a subclass of the specified class
  • If the parameter has an implements clause then the class must directly or indirectly implement all of the specified interfaces
obfuscateExceptionsExclude 
         * and //exclude all methods in all classes in default package
         *.Class1 and //exclude all methods in all classes with the unqualified class name "Class1"
         //exclude all methods in all classes that start with "Class" except for "Class0" and "Class1"
         *.(Class* && !(Class0 || Class1)) and
         "MyJar*.jar"!*.* and //exclude all classes contained in a JAR file with a name matching "MyJar*.jar"
         //exclude all classes annotated which an annotation matching *.MyAnnotation0
         @*.MyAnnotation0 *.*;  

Method exclude parameters

Put informally (with mandatory components in bold), the syntax of an obfuscateExceptionsExclude method parameter is:
<classAnnotations> <classModifiers> "<archiveQualifier>"!<packageQualifiers>.<className> <extendsClause> <implementsClause>
    <methodAnnotations> <methodModifiers> <methodName>(<argumentTypes>) <throwsClause> +signatureClasses;

For a method to be excluded from exception obfuscation, all of the following must be true:
  • Its containing class must match any class exclude parameter component.
  • Its annotations must match any specified method or method parameter level annotations.
  • Its modifiers (e.g. public native) must match all parameter method modifiers. So if the parameters are public static !synchronized then the method must be public, static and NOT synchronized to be excluded from obfuscation.
  • Its name must match the parameter method name specification. The special name <init> matches all constructors and the special name <clinit> matches all static initializers.
  • Its argument types (e.g. int[], java.lang.String) must match the parameter argument types if they exist. (A single parameter argument type of "*" matches any method argument types including no arguments.) If the parameter has no argument type then the method must take no arguments.
  • Its throws clause must contain all the classes specified in the obfuscateExceptionsExclude parameter's throw clause. So, if the obfuscateExceptionsExclude parameter's throws clause is throws java.io.IOException then the method must throw java.io.IOException or one of its subclasses to be excluded.
obfuscateExceptionsExclude 
         pack2.Class1 method1(int) and //Exclude method1(int) in class pack2.Class1 from exception obfuscation
         *.* *(*) and //Exclude all methods from exception obfuscation
         *.* <init>(*) and //Exclude all contructors from exception obfuscation
         *.* <clinit>(*) 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 *(*);

Syntax

"obfuscateExceptionsExclude" excludeParameter ("and" excludeParameter)* ";"

annotationSpecifier ::= ("@" [packageExcludeParameter] nameSpecifier) | annotationSpecifierAndList

annotationSpecifierAndList ::= ["!"] "(" annotationSpecifierOrList ("&&" annotationSpecifierOrList)* ")"

annotationSpecifierOrList ::= annotationSpecifier ("||" annotationSpecifier)*

classExcludeParameter ::=
   [annotationSpecifier] [["!"] "public" | "package"]
   [["!"] "abstract"] [["!"] "final"] [["!"] "interface"] [["!"] "synthetic"] [["!"] "enum"] [["!"] "annotation"]
   ["\"" archiveQualifier "\"" "!"] [packageExcludeParameter ["."]] nameSpecifier [containingClause]
   [extendsClause] [implementsClause]

containingClause ::= "containing" "{" "memberAndList" "}"

excludeParameter ::= classExcludeParameter |
methodExcludeParameter

extendsClause ::= "extends" [annotationSpecifier] wildcardClassName

fullyQualifiedClassName ::= name ("." name)*

implementsClause ::= "implements" [annotationSpecifier] wildcardClassName ("," [annotationSpecifier] wildcardClassName)*

memberAndList ::= ["!"] "(" memberOrList ("&&" memberOrList)* ")"

memberOrList ::= memberSpecifier ("||" memberSpecifier)*

memberSpecifier ::= fieldExcludeParameter | methodExcludeParameter

nameAndList ::= ["!"] "(" nameOrList ("&&" nameOrList)* ")"

methodExcludeParameter ::=
   classExcludeParameter [annotationSpecifier] [["!"] "public" | "protected"| "package"| "private"]
   [["!"] "abstract"] [["!"] "static"] [["!"] "final"] [["!"] "native"] [["!"] "synchronized"] [["!"] "synthetic"] [["!"] "bridge"]
   (nameSpecifier | "<init>" | "<clinit>") "(" [ "*" | (parameter ("," parameter)*)] ")"
   ["throws" wildcardClassName]

name ::= (["0"-"9","a"-"z","A"-"Z","$","_"])+
   i.e. a Java identifer (e.g. a package, class, field or method name) with no wildcards allowed

nameAndList ::= ["!"] "(" nameOrList ("&&" nameOrList)* ")"

nameOrList ::= nameSpecifier ("||" nameSpecifier)*

nameSpecifier ::= wildcardName | nameAndList

packageExcludeParameter ::= packageName | packageNameAndList

packageName ::= wildcardName ("." wildcardName)* "."
   NB: the final "." is part of the package name

packageNameAndList ::= ["!"] "(" packageNameOrList ("&&" packageNameOrList)* ")"

packageNameOrList ::= packageExcludeParameter ("||" packageExcludeParameter)*

parameter ::= [annotationSpecifier] ("*" | "?" | type)

type ::=
   ("byte" | "short" | "char" | "int" | "long" | "float" | "double"| "boolean" |
   fullyQualifiedClassName) ("[]")*

wildcardClassName ::= wildcardName ("." wildcardName)*

wildcardName ::= (["*","0"-"9","a"-"z","A"-"Z","$","_"])+
   i.e. a Java identifer (e.g. a package, class, field or method name) with the "*" wildcard allowed
Where archiveQualifier is a relative or absolute archive path name with the "*" wildcard allowed. E.g. "/lib/*.jar" or "myJar0.jar"
ZKM Script resetObfuscateFlowExclusions statement The ZKM Script Language ZKM Script obfuscateExceptionsUnexclude statement
Zelix KlassMaster - Java Obfuscator