Package com.yworks.yguard.obf.classfile
Class ClassFile
- java.lang.Object
-
- com.yworks.yguard.obf.classfile.ClassFile
-
- All Implemented Interfaces:
ClassConstants
public class ClassFile extends java.lang.Object implements ClassConstants
This is a representation of the data in a Java class-file (*.class). A ClassFile instance representing a *.class file can be generated using the static create(DataInput) method, manipulated using various operators, and persisted back using the write(DataOutput) method.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLOG_DANGER_HEADER1The constant LOG_DANGER_HEADER1.static java.lang.StringLOG_DANGER_HEADER2The constant LOG_DANGER_HEADER2.static java.lang.StringLOG_DANGER_HEADER3The constant LOG_DANGER_HEADER3.static java.lang.StringSEP_INNERThe constant SEP_INNER.static java.lang.StringSEP_REGULARThe constant SEP_REGULAR.-
Fields inherited from interface com.yworks.yguard.obf.classfile.ClassConstants
ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ATTR_AnnotationDefault, ATTR_BootstrapMethods, ATTR_Bridge, ATTR_Code, ATTR_ConstantValue, ATTR_Deprecated, ATTR_EnclosingMethod, ATTR_Enum, ATTR_Exceptions, ATTR_InnerClasses, ATTR_LineNumberTable, ATTR_LocalVariableTable, ATTR_LocalVariableTypeTable, ATTR_MethodParameters, ATTR_Module, ATTR_ModuleMainClass, ATTR_ModulePackages, ATTR_NestHost, ATTR_NestMembers, ATTR_PermittedSubclasses, ATTR_Record, ATTR_RuntimeInvisibleAnnotations, ATTR_RuntimeInvisibleParameterAnnotations, ATTR_RuntimeInvisibleTypeAnnotations, ATTR_RuntimeVisibleAnnotations, ATTR_RuntimeVisibleParameterAnnotations, ATTR_RuntimeVisibleTypeAnnotations, ATTR_Signature, ATTR_SourceDebug, ATTR_SourceDebugExtension, ATTR_SourceFile, ATTR_StackMapTable, ATTR_Synthetic, ATTR_Unknown, ATTR_Varargs, CONSTANT_Class, CONSTANT_Double, CONSTANT_Dynamic, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_InvokeDynamic, CONSTANT_Long, CONSTANT_MethodHandle, CONSTANT_Methodref, CONSTANT_MethodType, CONSTANT_Module, CONSTANT_NameAndType, CONSTANT_Package, CONSTANT_String, CONSTANT_Utf8, KNOWN_ATTRS, MAGIC, MAJOR_VERSION, MINOR_VERSION_MAX, REF_getField, REF_getStatic, REF_invokeInterface, REF_invokeSpecial, REF_invokeStatic, REF_invokeVirtual, REF_newInvokeSpecial, REF_putField, REF_putStatic, REQUIRED_ATTRS
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClassFilecreate(java.io.DataInput din)Create a new ClassFile from the class file format data in the DataInput stream.static voiddefineIdString(java.lang.String id)Define a constant String to include in every output class file.voiddump(java.io.PrintWriter pw)Dump the content of the class file to the specified file (used for debugging).java.lang.StringfindModuleName()Returns the module name if this class file represents a "module-info" class and the empty string otherwise.AttrInfo[]getAttributes()Get attributes attr info [ ].intgetClassFileAccess()Get class file access int.ConstantPoolgetConstantPool()Gets constant pool.CpInfogetCpEntry(int cpIndex)Lookup the entry in the constant pool and return as an Object.java.util.EnumerationgetFieldEnum()Return an enumeration of field name/descriptor pairs.java.util.MapgetInnerClassModifiers()Gets inner class modifiers.java.lang.String[]getInterfaces()Return the names of this class's interfaces.java.util.EnumerationgetMethodEnum()Return an enumeration of method name/descriptor pairs.intgetModifiers()Get modifiers int.java.lang.StringgetName()Return the name of this classfile.java.lang.StringgetSuper()Return the name of this class's superclass.java.lang.String[]logDangerousMethods(boolean replaceClassNameStrings)Check for methods which can break the obfuscated code, and log them to a String[].voidlogDangerousMethods(java.io.PrintWriter log, boolean replaceClassNameStrings)Log dangerous methods.voidmarkNTRefs(ConstantPool pool)Check for direct references to NameAndType constant pool entries.voidmarkUtf8Refs(ConstantPool pool)Check for direct references to Utf8 constant pool entries.static java.lang.String[]parseDescriptor(java.lang.String descriptor)Parse a method or field descriptor into a list of parameter names (for methods) and a return type, in same format as the Class.forName() method returns .static java.lang.String[]parseDescriptor(java.lang.String descriptor, boolean isDisplay)Parse a method or field descriptor into a list of parameter names (for methods) and a return type, in same format as the Class.forName() method returns .voidremap(NameMapper nm, boolean replaceClassNameStrings, java.io.PrintWriter log)Remap the entities in the specified ClassFile.static voidresetDangerHeader()Reset danger header.static java.lang.Stringtranslate(java.lang.String name)Translate a class name from the internal '/' convention to the regular '.' one.static java.lang.StringtranslateType(java.lang.String inName, boolean isDisplay)Translate a type specifier from the internal JVM convention to the Class.forName() one.voidtrimAttrsExcept(java.lang.String[] extraAttrs)Trim attributes from the classfile ('Code', 'Exceptions', 'ConstantValue' are preserved, all others except the list in the String[] are killed).voidwrite(java.io.DataOutput dout)Export the representation to a DataOutput stream.
-
-
-
Field Detail
-
SEP_REGULAR
public static final java.lang.String SEP_REGULAR
The constant SEP_REGULAR.- See Also:
- Constant Field Values
-
SEP_INNER
public static final java.lang.String SEP_INNER
The constant SEP_INNER.- See Also:
- Constant Field Values
-
LOG_DANGER_HEADER1
public static final java.lang.String LOG_DANGER_HEADER1
The constant LOG_DANGER_HEADER1.- See Also:
- Constant Field Values
-
LOG_DANGER_HEADER2
public static final java.lang.String LOG_DANGER_HEADER2
The constant LOG_DANGER_HEADER2.- See Also:
- Constant Field Values
-
LOG_DANGER_HEADER3
public static final java.lang.String LOG_DANGER_HEADER3
The constant LOG_DANGER_HEADER3.- See Also:
- Constant Field Values
-
-
Method Detail
-
defineIdString
public static void defineIdString(java.lang.String id)
Define a constant String to include in every output class file.- Parameters:
id- the id
-
create
public static ClassFile create(java.io.DataInput din) throws java.io.IOException
Create a new ClassFile from the class file format data in the DataInput stream.- Parameters:
din- the din- Returns:
- the class file
- Throws:
java.io.IOException- if class file is corrupt or incomplete
-
parseDescriptor
public static java.lang.String[] parseDescriptor(java.lang.String descriptor)
Parse a method or field descriptor into a list of parameter names (for methods) and a return type, in same format as the Class.forName() method returns .- Parameters:
descriptor- the descriptor- Returns:
- the string [ ]
-
parseDescriptor
public static java.lang.String[] parseDescriptor(java.lang.String descriptor, boolean isDisplay)Parse a method or field descriptor into a list of parameter names (for methods) and a return type, in same format as the Class.forName() method returns .- Parameters:
descriptor- the descriptorisDisplay- the is display- Returns:
- the string [ ]
-
translateType
public static java.lang.String translateType(java.lang.String inName, boolean isDisplay)Translate a type specifier from the internal JVM convention to the Class.forName() one.- Parameters:
inName- the in nameisDisplay- the is display- Returns:
- the string
-
translate
public static java.lang.String translate(java.lang.String name)
Translate a class name from the internal '/' convention to the regular '.' one.- Parameters:
name- the name- Returns:
- the string
-
getClassFileAccess
public int getClassFileAccess()
Get class file access int.- Returns:
- the int
-
getModifiers
public int getModifiers()
Get modifiers int.- Returns:
- the int
-
getName
public java.lang.String getName()
Return the name of this classfile.- Returns:
- the name
-
getSuper
public java.lang.String getSuper()
Return the name of this class's superclass.- Returns:
- the super
-
getInterfaces
public java.lang.String[] getInterfaces()
Return the names of this class's interfaces.- Returns:
- the string [ ]
-
getMethodEnum
public java.util.Enumeration getMethodEnum()
Return an enumeration of method name/descriptor pairs.- Returns:
- the method enum
-
getFieldEnum
public java.util.Enumeration getFieldEnum()
Return an enumeration of field name/descriptor pairs.- Returns:
- the field enum
-
getCpEntry
public CpInfo getCpEntry(int cpIndex)
Lookup the entry in the constant pool and return as an Object.- Parameters:
cpIndex- the cp index- Returns:
- the cp entry
-
getConstantPool
public ConstantPool getConstantPool()
Gets constant pool.- Returns:
- the constant pool
-
logDangerousMethods
public java.lang.String[] logDangerousMethods(boolean replaceClassNameStrings)
Check for methods which can break the obfuscated code, and log them to a String[].- Parameters:
replaceClassNameStrings- the replace class name strings- Returns:
- the string [ ]
-
resetDangerHeader
public static void resetDangerHeader()
Reset danger header.
-
logDangerousMethods
public void logDangerousMethods(java.io.PrintWriter log, boolean replaceClassNameStrings)Log dangerous methods.- Parameters:
log- the logreplaceClassNameStrings- the replace class name strings
-
markUtf8Refs
public void markUtf8Refs(ConstantPool pool)
Check for direct references to Utf8 constant pool entries.- Parameters:
pool- the pool
-
markNTRefs
public void markNTRefs(ConstantPool pool)
Check for direct references to NameAndType constant pool entries.- Parameters:
pool- the pool
-
trimAttrsExcept
public void trimAttrsExcept(java.lang.String[] extraAttrs)
Trim attributes from the classfile ('Code', 'Exceptions', 'ConstantValue' are preserved, all others except the list in the String[] are killed).- Parameters:
extraAttrs- the extra attrs
-
getInnerClassModifiers
public java.util.Map getInnerClassModifiers()
Gets inner class modifiers.- Returns:
- the inner class modifiers
-
remap
public void remap(NameMapper nm, boolean replaceClassNameStrings, java.io.PrintWriter log)
Remap the entities in the specified ClassFile.- Parameters:
nm- the nmreplaceClassNameStrings- the replace class name stringslog- the log
-
write
public void write(java.io.DataOutput dout) throws java.io.IOExceptionExport the representation to a DataOutput stream.- Parameters:
dout- the dout- Throws:
java.io.IOException- the io exception
-
dump
public void dump(java.io.PrintWriter pw)
Dump the content of the class file to the specified file (used for debugging).- Parameters:
pw- the pw
-
getAttributes
public AttrInfo[] getAttributes()
Get attributes attr info [ ].- Returns:
- the attr info [ ]
-
findModuleName
public java.lang.String findModuleName()
Returns the module name if this class file represents a "module-info" class and the empty string otherwise.- Returns:
- the string
-
-