JDK5 Features - RetroGuard Documentation


Prev   Contents   Next

Annotations (JDK5/1.5 Metadata)

Java now supports class, method, and field metadata; this is described in the Annotations guide at Sun, and in JSR 175 at the Java Community Process.

At the classfile level, these annotations are encoded as attributes named RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, and AnnotationDefault.

To preserve only the run-time accessible annotations, add a script line:

.option RuntimeAnnotations

This is exactly equivalent to the script lines:

.attribute RuntimeVisibleAnnotations
.attribute RuntimeVisibleParameterAnnotations
.attribute AnnotationDefault

To preserve all annotations, add a script line:

.option Annotations

This is exactly equivalent to the script lines:

.attribute RuntimeInvisibleAnnotations
.attribute RuntimeInvisibleParameterAnnotations
.attribute RuntimeVisibleAnnotations
.attribute RuntimeVisibleParameterAnnotations
.attribute AnnotationDefault

Enumerations (JDK5/1.5 'enum')

Java now supports typesafe enums; this is described in the Enums guide at Sun, and as part of JSR 201 at the Java Community Process.

Enumerations will work normally after obfuscation with no special effort. However, if you intend to access the enumerations later from outside the obfuscated jar, use the script line:

.option Enumeration

This is exactly equivalent to the script line:

.class ** public extends java/lang/Enum

To preserve a particular enum, use the script line:

.class com/widgetco/MyEnum public extends java/lang/Enum

RetroGuard always preserves the auto-generated static methods values() and valueOf(...) in enumerations. This is necessary to ensure enumerations work correctly after obfuscation.

Generics (JDK5/1.5)

Java now supports parametric polymorphism, or generic types; this is described in the Generics guide at Sun, in JSR 14 at the Java Community Process, and in the article Using and Programming Generics.

Generics will work normally after obfuscation with no special effort. However, if you intend to compile other classes against your obfuscated code or use reflection to determine generic types, the attribute Signature should be preserved.

The classfile attribute Signature contains generic type information used during reflection by the class java.lang.Class and classes in the package java.lang.reflect. To preserve signature information about generic types during obfuscation, use the script line:

.attribute Signature

[RetroGuard-v2.2.x only]
or the equivalent option:

.option Generic

When debugging information has been generated for a class using the javac -g compiler option and local variables in the Java source have generic types, the attribute LocalVariableTypeTable will appear in the Code attributes of those methods. To preserve local variable generic type information during obfuscation, use the script line:

.attribute LocalVariableTypeTable

The type signatures within the Signature and LocalVariableTypeTable attributes are not currently updated by RetroGuard into their obfuscated versions. So, for these attributes' content to be meaningful, you must also preserve from obfuscation any Java identifiers that are referenced in type signatures.

EnclosingMethod (JDK5/1.5)

To provide additional information about inner classes, the attribute EnclosingMethod has been added to Java. This can be preserved during obfuscation using the script line:

.attribute EnclosingMethod

Prev   Contents   Next
 Copyright © 1998-2007 Retrologic Systems.
 All rights reserved.