Package com.yworks.yguard.obf
Class ClassTree
- java.lang.Object
-
- com.yworks.yguard.obf.ClassTree
-
- All Implemented Interfaces:
NameMapper
public class ClassTree extends java.lang.Object implements NameMapper
Tree structure of package levels, classes, methods and fields used for obfuscation.
-
-
Field Summary
Fields Modifier and Type Field Description static charCLASS_LEVELThe constant CLASS_LEVEL.static charMETHOD_FIELD_LEVELThe constant METHOD_FIELD_LEVEL.static charPACKAGE_LEVELThe constant PACKAGE_LEVEL.
-
Constructor Summary
Constructors Constructor Description ClassTree()Ctor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddClassFile(ClassFile cf)Add a classfile's package, class, method and field entries to database.voiddump(java.io.PrintWriter log)Dump the content of the class tree to the specified file (used for logging).ClfindClassForName(java.lang.String name)walks the tree of TreeItems in order to find a class forNameTreeItemfindSubItem(TreeItem parent, java.lang.String childName)TreeItemfindTreeItem(java.lang.String[] nameParts)finds tree items by looking for name components only...voidgenerateNames()Traverse the class tree, generating obfuscated names within each namespace.java.lang.String[]getAttrsToKeep()Return a list of attributes marked to keep.java.lang.String[]getAttrsToKeep(java.lang.String className)Return a list of attributes marked to keep.ClgetCl(java.lang.String fullName)Get class in tree from the fully qualified name, returning null if name not found.java.util.EnumerationgetClEnum(java.lang.String fullName)Get classes in tree from the fully qualified name (can be wildcarded).java.util.EnumerationgetClEnum(java.lang.String fullName, int classMode)Get classes in tree from the fully qualified name (can be wildcarded).FdgetFd(java.lang.String fullName)Get field in tree from the fully qualified name.java.util.EnumerationgetFdEnum(java.lang.String fullName)Get fields in tree from the fully qualified, and possibly wildcarded, name.MdgetMd(java.lang.String fullName, java.lang.String descriptor)Get method in tree from the fully qualified name.java.util.EnumerationgetMdEnum(java.lang.String fullName, java.lang.String descriptor)Get methods in tree from the fully qualified, and possibly wildcarded, name.static java.util.EnumerationgetNameEnum(java.lang.String name)Return a fully qualified name broken into package/class segments.java.lang.StringgetOutName(java.lang.String inName)Update the path of the passed filename, if that path corresponds to a package.PkgetPk(java.lang.String fullName)Get package in tree from the fully qualified name, returning null if name not found.PkgetRoot()Return the root node.booleanisPedantic()Getter for property pedantic.booleanisReplaceClassNameStrings()Getter for property replaceClassNameStrings.java.lang.StringmapAnnotationField(java.lang.String className, java.lang.String methodName)Mapping for annotation field/method name, of fully qualified class.java.lang.StringmapClass(java.lang.String className)Mapping for fully qualified class name.java.lang.StringmapDescriptor(java.lang.String descriptor)Mapping for descriptor of field or method.java.lang.StringmapField(java.lang.String className, java.lang.String fieldName)Mapping for field name, of fully qualified class.booleanmapLineNumberTable(java.lang.String className, java.lang.String methodName, java.lang.String methodSignature, LineNumberTableAttrInfo info)Mapping for the line number table.java.lang.StringmapLocalVariable(java.lang.String thisClassName, java.lang.String methodName, java.lang.String descriptor, java.lang.String string)Map local variable string.java.lang.StringmapMethod(java.lang.String className, java.lang.String methodName, java.lang.String descriptor)Mapping for method name, of fully qualified class.java.lang.StringmapPackage(java.lang.String packageName)Mapping for package names.java.lang.StringmapSignature(java.lang.String signature)Mapping for signatures (used for generics in 1.5).java.lang.StringmapSourceFile(java.lang.String className, java.lang.String sourceFileName)Mapping for the source file attribute of a file.voidresolveClasses()Resolve the polymorphic dependencies of each class.voidretainAttribute(java.lang.String name)Mark an attribute type for retention.voidretainAttributeForClass(java.lang.String className, java.lang.String attributeDescriptor)Retain attribute for class.voidretainClass(java.lang.String name, int classLevel, int methodLevel, int fieldLevel, boolean retainHierarchy)Mark a class/interface type (and possibly methods and fields defined in class) for retention.voidretainClassMap(java.lang.String name, java.lang.String obfName)Mark a class/interface type for retention, and specify its new name.voidretainField(java.lang.String name)Mark a field type for retention.voidretainFieldMap(java.lang.String name, java.lang.String obfName)Mark a field type for retention, and specify its new name.voidretainLineNumberTable(java.lang.String name, LineNumberTableMapper lineNumberTableMapper)Retain line number table.voidretainMethod(java.lang.String name, java.lang.String descriptor)Mark a method type for retention.voidretainMethodMap(java.lang.String name, java.lang.String descriptor, java.lang.String obfName)Mark a method type for retention, and specify its new name.voidretainPackage(java.lang.String packageName)Retain package.voidretainPackageMap(java.lang.String name, java.lang.String obfName)Mark a package for retention, and specify its new name.voidretainSourceFileAttributeMap(java.lang.String name, java.lang.String obfName)Retain source file attribute map.voidsetPedantic(boolean pedantic)Setter for property pedantic.voidsetReplaceClassNameStrings(boolean replaceClassNameStrings)Setter for property replaceClassNameStrings.static java.lang.StringtoUtf8XmlString(java.lang.String s)To utf 8 xml string string.voidwalkTree(TreeAction ta)Walk the whole tree taking action once only on each package level, class, method and field.
-
-
-
Field Detail
-
PACKAGE_LEVEL
public static final char PACKAGE_LEVEL
The constant PACKAGE_LEVEL.- See Also:
- Constant Field Values
-
CLASS_LEVEL
public static final char CLASS_LEVEL
The constant CLASS_LEVEL.- See Also:
- Constant Field Values
-
METHOD_FIELD_LEVEL
public static final char METHOD_FIELD_LEVEL
The constant METHOD_FIELD_LEVEL.- See Also:
- Constant Field Values
-
-
Method Detail
-
getNameEnum
public static java.util.Enumeration getNameEnum(java.lang.String name)
Return a fully qualified name broken into package/class segments.- Parameters:
name- the name- Returns:
- the name enum
-
getRoot
public Pk getRoot()
Return the root node.- Returns:
- the root
-
findTreeItem
public TreeItem findTreeItem(java.lang.String[] nameParts)
finds tree items by looking for name components only...- Parameters:
nameParts- the name parts- Returns:
- the tree item
-
findClassForName
public Cl findClassForName(java.lang.String name)
walks the tree of TreeItems in order to find a class forName- Parameters:
name- the name- Returns:
- the cl
-
getOutName
public java.lang.String getOutName(java.lang.String inName)
Update the path of the passed filename, if that path corresponds to a package.- Parameters:
inName- the in name- Returns:
- the out name
-
addClassFile
public void addClassFile(ClassFile cf)
Add a classfile's package, class, method and field entries to database.- Parameters:
cf- the cf
-
retainAttribute
public void retainAttribute(java.lang.String name)
Mark an attribute type for retention.- Parameters:
name- the name
-
retainClass
public void retainClass(java.lang.String name, int classLevel, int methodLevel, int fieldLevel, boolean retainHierarchy)Mark a class/interface type (and possibly methods and fields defined in class) for retention.- Parameters:
name- the nameclassLevel- the class levelmethodLevel- the method levelfieldLevel- the field levelretainHierarchy- the retain hierarchy
-
retainMethod
public void retainMethod(java.lang.String name, java.lang.String descriptor)Mark a method type for retention.- Parameters:
name- the namedescriptor- the descriptor
-
retainField
public void retainField(java.lang.String name)
Mark a field type for retention.- Parameters:
name- the name
-
retainPackageMap
public void retainPackageMap(java.lang.String name, java.lang.String obfName)Mark a package for retention, and specify its new name.- Parameters:
name- the nameobfName- the obf name
-
retainClassMap
public void retainClassMap(java.lang.String name, java.lang.String obfName)Mark a class/interface type for retention, and specify its new name.- Parameters:
name- the nameobfName- the obf name
-
retainMethodMap
public void retainMethodMap(java.lang.String name, java.lang.String descriptor, java.lang.String obfName)Mark a method type for retention, and specify its new name.- Parameters:
name- the namedescriptor- the descriptorobfName- the obf name
-
retainFieldMap
public void retainFieldMap(java.lang.String name, java.lang.String obfName)Mark a field type for retention, and specify its new name.- Parameters:
name- the nameobfName- the obf name
-
generateNames
public void generateNames()
Traverse the class tree, generating obfuscated names within each namespace.
-
resolveClasses
public void resolveClasses() throws java.lang.ClassNotFoundExceptionResolve the polymorphic dependencies of each class. @throws ClassNotFoundException the class not found exception- Throws:
java.lang.ClassNotFoundException- the class not found exception
-
getAttrsToKeep
public java.lang.String[] getAttrsToKeep()
Return a list of attributes marked to keep.- Returns:
- the string [ ]
-
getClEnum
public java.util.Enumeration getClEnum(java.lang.String fullName)
Get classes in tree from the fully qualified name (can be wildcarded).- Parameters:
fullName- the full name- Returns:
- the cl enum
-
getClEnum
public java.util.Enumeration getClEnum(java.lang.String fullName, int classMode)Get classes in tree from the fully qualified name (can be wildcarded).- Parameters:
fullName- the full nameclassMode- the class mode- Returns:
- the cl enum
-
getMdEnum
public java.util.Enumeration getMdEnum(java.lang.String fullName, java.lang.String descriptor)Get methods in tree from the fully qualified, and possibly wildcarded, name.- Parameters:
fullName- the full namedescriptor- the descriptor- Returns:
- the md enum
-
getFdEnum
public java.util.Enumeration getFdEnum(java.lang.String fullName)
Get fields in tree from the fully qualified, and possibly wildcarded, name.- Parameters:
fullName- the full name- Returns:
- the fd enum
-
getCl
public Cl getCl(java.lang.String fullName)
Get class in tree from the fully qualified name, returning null if name not found.- Parameters:
fullName- the full name- Returns:
- the cl
-
getPk
public Pk getPk(java.lang.String fullName)
Get package in tree from the fully qualified name, returning null if name not found.- Parameters:
fullName- the full name- Returns:
- the pk
-
getMd
public Md getMd(java.lang.String fullName, java.lang.String descriptor)
Get method in tree from the fully qualified name.- Parameters:
fullName- the full namedescriptor- the descriptor- Returns:
- the md
-
getFd
public Fd getFd(java.lang.String fullName)
Get field in tree from the fully qualified name.- Parameters:
fullName- the full name- Returns:
- the fd
-
getAttrsToKeep
public java.lang.String[] getAttrsToKeep(java.lang.String className)
Description copied from interface:NameMapperReturn a list of attributes marked to keep.- Specified by:
getAttrsToKeepin interfaceNameMapper- Parameters:
className- the class name- Returns:
- the string [ ]
-
mapLocalVariable
public java.lang.String mapLocalVariable(java.lang.String thisClassName, java.lang.String methodName, java.lang.String descriptor, java.lang.String string)Description copied from interface:NameMapperMap local variable string.- Specified by:
mapLocalVariablein interfaceNameMapper- Parameters:
thisClassName- the this class namemethodName- the method namedescriptor- the descriptorstring- the string- Returns:
- the string
-
mapClass
public java.lang.String mapClass(java.lang.String className)
Mapping for fully qualified class name.- Specified by:
mapClassin interfaceNameMapper- Parameters:
className- the class name- Returns:
- the string
- See Also:
NameMapper.mapClass(java.lang.String)
-
mapMethod
public java.lang.String mapMethod(java.lang.String className, java.lang.String methodName, java.lang.String descriptor)Mapping for method name, of fully qualified class.- Specified by:
mapMethodin interfaceNameMapper- Parameters:
className- the class namemethodName- the method namedescriptor- the descriptor- Returns:
- the string
- See Also:
NameMapper.mapMethod(java.lang.String, java.lang.String, java.lang.String)
-
mapAnnotationField
public java.lang.String mapAnnotationField(java.lang.String className, java.lang.String methodName)Mapping for annotation field/method name, of fully qualified class.- Specified by:
mapAnnotationFieldin interfaceNameMapper- Parameters:
className- the class namemethodName- the annotation field name- Returns:
- the string
- See Also:
NameMapper.mapAnnotationField(java.lang.String, java.lang.String)
-
mapField
public java.lang.String mapField(java.lang.String className, java.lang.String fieldName)Mapping for field name, of fully qualified class.- Specified by:
mapFieldin interfaceNameMapper- Parameters:
className- the class namefieldName- the field name- Returns:
- the string
- See Also:
NameMapper.mapField(java.lang.String, java.lang.String)
-
mapSignature
public java.lang.String mapSignature(java.lang.String signature)
Mapping for signatures (used for generics in 1.5).- Specified by:
mapSignaturein interfaceNameMapper- Parameters:
signature- the signature- Returns:
- the string
- See Also:
NameMapper.mapSignature(java.lang.String)
-
mapSourceFile
public java.lang.String mapSourceFile(java.lang.String className, java.lang.String sourceFileName)Description copied from interface:NameMapperMapping for the source file attribute of a file.- Specified by:
mapSourceFilein interfaceNameMapper- Parameters:
className- the class namesourceFileName- the source file- Returns:
- the string
-
mapLineNumberTable
public boolean mapLineNumberTable(java.lang.String className, java.lang.String methodName, java.lang.String methodSignature, LineNumberTableAttrInfo info)Description copied from interface:NameMapperMapping for the line number table.- Specified by:
mapLineNumberTablein interfaceNameMapper- Parameters:
className- the class namemethodName- the method namemethodSignature- the method signatureinfo- the info- Returns:
falseif the line number table may be discarded
-
mapDescriptor
public java.lang.String mapDescriptor(java.lang.String descriptor)
Mapping for descriptor of field or method.- Specified by:
mapDescriptorin interfaceNameMapper- Parameters:
descriptor- the descriptor- Returns:
- the string
- See Also:
NameMapper.mapDescriptor(java.lang.String)
-
mapPackage
public java.lang.String mapPackage(java.lang.String packageName)
Mapping for package names.- Specified by:
mapPackagein interfaceNameMapper- Parameters:
packageName- the package name- Returns:
- the string
- See Also:
NameMapper.mapPackage(String)
-
dump
public void dump(java.io.PrintWriter log)
Dump the content of the class tree to the specified file (used for logging).- Parameters:
log- the log
-
toUtf8XmlString
public static final java.lang.String toUtf8XmlString(java.lang.String s)
To utf 8 xml string string.- Parameters:
s- the s- Returns:
- the string
-
walkTree
public void walkTree(TreeAction ta)
Walk the whole tree taking action once only on each package level, class, method and field.- Parameters:
ta- the ta
-
isReplaceClassNameStrings
public boolean isReplaceClassNameStrings()
Getter for property replaceClassNameStrings.- Returns:
- Value of property replaceClassNameStrings.
-
setReplaceClassNameStrings
public void setReplaceClassNameStrings(boolean replaceClassNameStrings)
Setter for property replaceClassNameStrings.- Parameters:
replaceClassNameStrings- New value of property replaceClassNameStrings.
-
isPedantic
public boolean isPedantic()
Getter for property pedantic.- Returns:
- Value of property pedantic.
-
setPedantic
public void setPedantic(boolean pedantic)
Setter for property pedantic.- Parameters:
pedantic- New value of property pedantic.
-
retainSourceFileAttributeMap
public void retainSourceFileAttributeMap(java.lang.String name, java.lang.String obfName)Retain source file attribute map.- Parameters:
name- the nameobfName- the obf name
-
retainLineNumberTable
public void retainLineNumberTable(java.lang.String name, LineNumberTableMapper lineNumberTableMapper)Retain line number table.- Parameters:
name- the namelineNumberTableMapper- the line number table mapper
-
retainAttributeForClass
public void retainAttributeForClass(java.lang.String className, java.lang.String attributeDescriptor)Retain attribute for class.- Parameters:
className- the class nameattributeDescriptor- the attribute descriptor
-
retainPackage
public void retainPackage(java.lang.String packageName)
Retain package.- Parameters:
packageName- the package name
-
-