Class DirectClassFile

java.lang.Object
com.android.dx.cf.direct.DirectClassFile
All Implemented Interfaces:
ClassFile, HasAttribute

public class DirectClassFile extends Object implements ClassFile
Class file with info taken from a byte[] or slice thereof.
  • Constructor Details

    • DirectClassFile

      public DirectClassFile(ByteArray bytes, String filePath, boolean strictParse)
      Constructs an instance.
      Parameters:
      bytes - non-null; the bytes of the file
      filePath - non-null; the file path for the class, excluding any base directory specification
      strictParse - whether to be strict about parsing; if false, this avoids doing checks that only exist for purposes of verification (such as magic number matching and path-package consistency checking)
    • DirectClassFile

      public DirectClassFile(byte[] bytes, String filePath, boolean strictParse)
      Constructs an instance.
      Parameters:
      bytes - non-null; the bytes of the file
      filePath - non-null; the file path for the class, excluding any base directory specification
      strictParse - whether to be strict about parsing; if false, this avoids doing checks that only exist for purposes of verification (such as magic number matching and path-package consistency checking)
  • Method Details

    • stringOrNone

      public static String stringOrNone(Object obj)
      Returns the string form of an object or "(none)" (rather than "null") for null.
      Parameters:
      obj - null-ok; the object to stringify
      Returns:
      non-null; the appropriate string form
    • setObserver

      public void setObserver(ParseObserver observer)
      Sets the parse observer for this instance.
      Parameters:
      observer - null-ok; the observer
    • setAttributeFactory

      public void setAttributeFactory(AttributeFactory attributeFactory)
      Sets the attribute factory to use.
      Parameters:
      attributeFactory - non-null; the attribute factory
    • getFilePath

      public String getFilePath()
      Gets the path where this class file is located.
      Returns:
      non-null; the filePath
    • getBytes

      public ByteArray getBytes()
      Gets the ByteArray that this instance's data comes from.
      Returns:
      non-null; the bytes
    • getMagic

      public int getMagic()
      Gets the field magic.
      Specified by:
      getMagic in interface ClassFile
      Returns:
      the value in question
    • getMinorVersion

      public int getMinorVersion()
      Gets the field minor_version.
      Specified by:
      getMinorVersion in interface ClassFile
      Returns:
      the value in question
    • getMajorVersion

      public int getMajorVersion()
      Gets the field major_version.
      Specified by:
      getMajorVersion in interface ClassFile
      Returns:
      the value in question
    • getAccessFlags

      public int getAccessFlags()
      Gets the field access_flags.
      Specified by:
      getAccessFlags in interface ClassFile
      Returns:
      the value in question
    • getThisClass

      public CstType getThisClass()
      Gets the field this_class, interpreted as a type constant.
      Specified by:
      getThisClass in interface ClassFile
      Returns:
      non-null; the value in question
    • getSuperclass

      public CstType getSuperclass()
      Gets the field super_class, interpreted as a type constant if non-zero.
      Specified by:
      getSuperclass in interface ClassFile
      Returns:
      null-ok; the value in question
    • getConstantPool

      public ConstantPool getConstantPool()
      Gets the field constant_pool (along with constant_pool_count).
      Specified by:
      getConstantPool in interface ClassFile
      Returns:
      non-null; the constant pool
    • getInterfaces

      public TypeList getInterfaces()
      Gets the field interfaces (along with interfaces_count).
      Specified by:
      getInterfaces in interface ClassFile
      Returns:
      non-null; the list of interfaces
    • getFields

      public FieldList getFields()
      Gets the field fields (along with fields_count).
      Specified by:
      getFields in interface ClassFile
      Returns:
      non-null; the list of fields
    • getMethods

      public MethodList getMethods()
      Gets the field methods (along with methods_count).
      Specified by:
      getMethods in interface ClassFile
      Returns:
      non-null; the list of fields
    • getAttributes

      public AttributeList getAttributes()
      Gets the field attributes (along with attributes_count).
      Specified by:
      getAttributes in interface ClassFile
      Specified by:
      getAttributes in interface HasAttribute
      Returns:
      non-null; the list of attributes
    • getBootstrapMethods

      public BootstrapMethodsList getBootstrapMethods()
      Gets the bootstrap method attributes.
      Specified by:
      getBootstrapMethods in interface ClassFile
      Returns:
      non-null; the list of bootstrap methods
    • getSourceFile

      public CstString getSourceFile()
      Gets the name out of the SourceFile attribute of this file, if any. This is a convenient shorthand for scrounging around the class's attributes.
      Specified by:
      getSourceFile in interface ClassFile
      Returns:
      non-null; the constant pool
    • makeTypeList

      public TypeList makeTypeList(int offset, int size)
      Constructs and returns an instance of TypeList whose data comes from the bytes of this instance, interpreted as a list of constant pool indices for classes, which are in turn translated to type constants. Instance construction will fail if any of the (alleged) indices turn out not to refer to constant pool entries of type Class.
      Parameters:
      offset - offset into bytes for the start of the data
      size - number of elements in the list (not number of bytes)
      Returns:
      non-null; an appropriately-constructed class list
    • getMagic0

      public int getMagic0()
      Gets the class file field magic, but without doing any checks or parsing first.
      Returns:
      the magic value
    • getMinorVersion0

      public int getMinorVersion0()
      Gets the class file field minor_version, but without doing any checks or parsing first.
      Returns:
      the minor version
    • getMajorVersion0

      public int getMajorVersion0()
      Gets the class file field major_version, but without doing any checks or parsing first.
      Returns:
      the major version