Class ClassReader

java.lang.Object
com.ibm.wala.shrike.shrikeCT.ClassReader
All Implemented Interfaces:
ClassConstants

public final class ClassReader extends Object implements ClassConstants
This is the core class for reading class file data.

ClassReader performs lazy parsing, and thus most of the methods can throw an InvalidClassFileException.

  • Constructor Details

    • ClassReader

      public ClassReader(byte[] bytes) throws InvalidClassFileException
      Build a reader.

      If the class file data is corrupt an exception might not be thrown immediately. Instead an exception might be thrown later, during the execution of some access method. This is a consequence of the 'lazy parsing' performed by ClassReader.

      Parameters:
      bytes - the class file data
      Throws:
      InvalidClassFileException - the class file data is corrupt
  • Method Details

    • getBytes

      public byte[] getBytes()
      Returns:
      the raw class data bytes
    • getMagic

      public int getMagic()
      Returns:
      the magic number at the start of the class file.
    • getMinorVersion

      public int getMinorVersion()
      Returns:
      the minor version of the class file
    • getMajorVersion

      public int getMajorVersion()
      Returns:
      the major version of the class file
    • getAccessFlags

      public int getAccessFlags()
      Returns:
      the access flags for the class
    • getNameIndex

      public int getNameIndex()
      Returns:
      the index of the constant pool entry for the class name
    • getName

      public String getName() throws InvalidClassFileException
      Returns:
      the name of the class in JVM format (e.g., java/lang/Object)
      Throws:
      InvalidClassFileException
    • getSuperNameIndex

      public int getSuperNameIndex()
      Returns:
      the constant pool index of the superclass name, or 0 if this is java.lang.Object
    • getSuperName

      public String getSuperName() throws InvalidClassFileException
      Returns:
      the superclass name in JVM format (e.g., java/lang/Object), or null if this class is java.lang.Object
      Throws:
      InvalidClassFileException
    • getInterfaceCount

      public int getInterfaceCount()
      Returns:
      the number of interfaces this class implements
    • getInterfaceNameIndex

      public int getInterfaceNameIndex(int i)
      Returns:
      the constant pool index of the name of the i'th implemented interface
    • getInterfaceNameIndices

      public int[] getInterfaceNameIndices()
      Returns:
      an array of the constant pool indices for the names of the implemented interfaces
    • getInterfaceName

      public String getInterfaceName(int i) throws InvalidClassFileException
      Returns:
      the name of the i'th implemented interface
      Throws:
      InvalidClassFileException
    • getInterfaceNames

      public String[] getInterfaceNames() throws InvalidClassFileException
      Returns:
      an array of the names of the implemented interfaces
      Throws:
      InvalidClassFileException
    • getCP

      public ConstantPoolParser getCP()
      This method allows direct read-only access to the constant pool for the class.
      Returns:
      the constant pool for the class
    • getInt

      public int getInt(int i)
      Returns:
      the signed 32-bit value at offset i in the class data
    • getUShort

      public int getUShort(int i)
      Returns:
      the unsigned 16-bit value at offset i in the class data
    • getShort

      public int getShort(int i)
      Returns:
      the signed 16-bit value at offset i in the class data
    • getByte

      public byte getByte(int i)
      Returns:
      the signed 8-bit value at offset i in the class data
    • getUnsignedByte

      public int getUnsignedByte(int i)
      Returns:
      the unsigned 8-bit value at offset i in the class data
    • getFieldCount

      public int getFieldCount()
      Returns:
      the number of fields in the class
    • getFieldAccessFlags

      public int getFieldAccessFlags(int f)
      Returns:
      the access flags for the f'th field
    • getFieldName

      public String getFieldName(int f) throws InvalidClassFileException
      Returns:
      the name of the f'th field
      Throws:
      InvalidClassFileException
    • getFieldType

      public String getFieldType(int f) throws InvalidClassFileException
      Returns:
      the type of the f'th field, in JVM format (e.g., I, Z, java/lang/Object)
      Throws:
      InvalidClassFileException
    • getFieldNameIndex

      public int getFieldNameIndex(int f)
      Returns:
      the index of the constant pool entry for the name of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)
    • getFieldTypeIndex

      public int getFieldTypeIndex(int f)
      Returns:
      the index of the constant pool entry for the type of the f'th field, in JVM format (e.g., I, Z, Ljava/lang/Object;)
    • initFieldAttributeIterator

      public void initFieldAttributeIterator(int f, ClassReader.AttrIterator iter)
      Point iter at the list of attributes for field f.
      Throws:
      IllegalArgumentException - if iter is null
    • getFieldRawOffset

      public int getFieldRawOffset(int f)
      Returns:
      the offset of the raw class data for field f
    • getFieldRawSize

      public int getFieldRawSize(int f)
      Returns:
      the size of the raw class data for field f
    • getMethodCount

      public int getMethodCount()
      Returns:
      the number of methods in the class
    • getMethodRawOffset

      public int getMethodRawOffset(int m)
      Returns:
      the offset of the raw class data for method m
    • getMethodRawSize

      public int getMethodRawSize(int m)
      Returns:
      the size of the raw class data for method m
    • getMethodAccessFlags

      public int getMethodAccessFlags(int m)
      Returns:
      the access flags for method m
    • getMethodName

      public String getMethodName(int m) throws InvalidClassFileException
      Returns:
      the name of method m
      Throws:
      InvalidClassFileException
    • getMethodType

      public String getMethodType(int m) throws InvalidClassFileException
      Returns:
      the method descriptor of method m in JVM format (e.g., (ILjava/lang/Object;)V )
      Throws:
      InvalidClassFileException
    • getMethodNameIndex

      public int getMethodNameIndex(int m)
      Returns:
      the constant pool index of the name of method m
    • getMethodTypeIndex

      public int getMethodTypeIndex(int m)
      Returns:
      the constant pool index of the method descriptor of method m
    • initMethodAttributeIterator

      public void initMethodAttributeIterator(int m, ClassReader.AttrIterator iter)
      Point iter at the list of attributes for method m.
      Throws:
      IllegalArgumentException - if iter is null
    • initClassAttributeIterator

      public void initClassAttributeIterator(ClassReader.AttrIterator iter)
      Point iter at the list of attributes for the class.
      Throws:
      IllegalArgumentException - if iter is null