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 Link icon

    • ClassReader Link icon

      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 Link icon

    • getBytes Link icon

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

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

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

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

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

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

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

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

      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 Link icon

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

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

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

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

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

      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 Link icon

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

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

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

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

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

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

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

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

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

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

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

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

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

      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 Link icon

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

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

      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 Link icon

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