Class 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 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 descriptor
        isDisplay - 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 name
        isDisplay - 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 log
        replaceClassNameStrings - 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 nm
        replaceClassNameStrings - the replace class name strings
        log - the log
      • write

        public void write​(java.io.DataOutput dout)
                   throws java.io.IOException
        Export 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