Introduction |
---|
ProGuard is a Java class file shrinker and obfuscator. It detects and removes unused classes, fields, methods, and attributes, and it renames the remaining classes, fields, and methods using short meaningless names. The resulting jars are smaller and harder to reverse-engineer.
ProGuard can also be used to list unused fields and methods in an application, and to print out the internal structure of class files.
ProGuard typically reads the input jars, shrinks their class files, obfuscates the shrunk class files, and writes them to an output jar. In the shrinking phase, one or more seed methods or classes are required. These seeds are typically main classes or applets. The shrinker can then recursively determine which classes and class members are used, and discard the rest. In the obfuscation phase, all classes and class members get new names, except for the seeds, so they can still be called by their original names.
ProGuard automatically handles Class.forName("SomeClass")
and
SomeClass.class
constructs. The referenced classes are preserved
in the shrinking phase, and the string arguments are properly replaced in the
obfuscation phase. With variable string arguments, it's generally not possible
to determine their possible values (they might be read from a configuration
file, for instance). However, ProGuard will note constructs like
"(SomeClass)Class.forName(variable).newInstance()
". These might
be an indication that the class or interface SomeClass
and/or its
implementations may need to be preserved. The user can adapt his configuration
accordingly.
ProGuard copies all non-class resource files from the input jars to the output jar. Their names and contents remain unchanged.