Zelix KlassMaster - Documentation

Use of Annotations to Specify Obfuscation Settings Tutorial

This tutorial is divided into the following sections:

Overview

Zelix KlassMaster™'s obfuscation settings are normally specified using the clauses of the ZKM Script obfuscate statement and the various exclusion statements such as the obfuscateFlowExclude statement. However, the effects of the obfuscate statement's obfuscateFlow and exceptionObfuscation settings are all or nothing. For example, if you specify exceptionObfuscation=aggressive then that level of Flow Obfuscation will be applied to all methods which have not been excluded from Flow Obfuscation.

However, there are some scenarios where you may wish to have a fine grained control of the obfuscation setting at the level of individual classes or methods. This can be done by annotating specific classes or methods in your Java source code with special Zelix KlassMaster annotations.

The Annotation Classes

package com.zelix.annotation;

import java.lang.annotation.*;

/**
 * Used to override certain obfuscation settings at the class level
 */
@Retention(value=RetentionPolicy.CLASS)
@Target(value={ElementType.TYPE})
public @interface ZKMClassLevel {
   FlowObfuscationPolicy   obfuscateFlow() default FlowObfuscationPolicy.LIGHT;
   ExceptionObfuscationPolicy exceptionObfuscation() default ExceptionObfuscationPolicy.LIGHT;
}

package com.zelix.annotation;

import java.lang.annotation.*;

/**
 * Used to override certain obfuscation settings at the method level
 */
@Retention(value=RetentionPolicy.CLASS)
@Target(value={ElementType.METHOD})
public @interface ZKMMethodLevel {
   FlowObfuscationPolicy   obfuscateFlow() default FlowObfuscationPolicy.LIGHT;
   ExceptionObfuscationPolicy exceptionObfuscation() default ExceptionObfuscationPolicy.LIGHT;
}

package com.zelix.annotation;

/**
 * Indicates that the annotated program element should be excluded from obfuscation.
 */
public enum FlowObfuscationPolicy {
    NONE,
    LIGHT,
    NORMAL,
    AGGRESSIVE
}

package com.zelix.annotation;

/**
 * Indicates that the annotated program element should be excluded from obfuscation.
 */
public enum ExceptionObfuscationPolicy {
    NONE,
    LIGHT,
    HEAVY
}

Using the Annotations

Simply annotate the class or method that you wish to obfuscate with a specific Flow or Exception Obfuscation setting with a ZKMClassLevel or ZKMMethodLevel annotation which specifies that setting.

Note that the annotation will only have an effect
  1. If the relevant transformation setting (i.e. Flow or Exception Obfuscation) has been enabled in the preceding obfuscate statement and
  2. If the annotated class or method has not been explicitly excluded from the relevant transformation by an exclusion statement.
Put another way, the annotations can only change the level of Flow or Exception Obfuscation for the annotated class or method if that class or method would otherwise have been flow or exception obfuscated.
 
Documentation Table of Contents
Zelix KlassMaster - Java Obfuscator