Class ClassReader
java.lang.Object
com.ibm.wala.shrike.shrikeCT.ClassReader
- All Implemented Interfaces:
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
AttrIterator provides access to attributes in the class file. -
Field Summary
Fields inherited from interface com.ibm.wala.shrike.shrikeCT.ClassConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, 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, MAGIC, REF_getField, REF_getStatic, REF_invokeInterface, REF_invokeSpecial, REF_invokeStatic, REF_invokeVirtual, REF_newInvokeSpecial, REF_putField, REF_putStatic
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
byte
getByte
(int i) byte[]
getBytes()
getCP()
This method allows direct read-only access to the constant pool for the class.int
getFieldAccessFlags
(int f) int
getFieldName
(int f) int
getFieldNameIndex
(int f) int
getFieldRawOffset
(int f) int
getFieldRawSize
(int f) getFieldType
(int f) int
getFieldTypeIndex
(int f) int
getInt
(int i) int
getInterfaceName
(int i) int
getInterfaceNameIndex
(int i) int[]
String[]
int
getMagic()
int
int
getMethodAccessFlags
(int m) int
getMethodName
(int m) int
getMethodNameIndex
(int m) int
getMethodRawOffset
(int m) int
getMethodRawSize
(int m) getMethodType
(int m) int
getMethodTypeIndex
(int m) int
getName()
int
int
getShort
(int i) int
int
getUnsignedByte
(int i) int
getUShort
(int i) void
Point iter at the list of attributes for the class.void
initFieldAttributeIterator
(int f, ClassReader.AttrIterator iter) Point iter at the list of attributes for field f.void
initMethodAttributeIterator
(int m, ClassReader.AttrIterator iter) Point iter at the list of attributes for method m.
-
Constructor Details
-
ClassReader
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
- 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
- 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
- Returns:
- the name of the i'th implemented interface
- Throws:
InvalidClassFileException
-
getInterfaceNames
- Returns:
- an array of the names of the implemented interfaces
- Throws:
InvalidClassFileException
-
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
- Returns:
- the name of the f'th field
- Throws:
InvalidClassFileException
-
getFieldType
- 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
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
- Returns:
- the name of method m
- Throws:
InvalidClassFileException
-
getMethodType
- 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
Point iter at the list of attributes for method m.- Throws:
IllegalArgumentException
- if iter is null
-
initClassAttributeIterator
Point iter at the list of attributes for the class.- Throws:
IllegalArgumentException
- if iter is null
-