public final class ClassFileReader extends Object
ClassFileReader is responsible for reading in a class file
and constructing a ClassFile object from it.| Modifier and Type | Class and Description |
|---|---|
protected static class |
ClassFileReader.ClassConstant
This class represents a class constant.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
ACC_ABSTRACT |
static int |
ACC_ANNOTATION |
static int |
ACC_BRIDGE |
static int |
ACC_ENUM |
static int |
ACC_FINAL |
static int |
ACC_INTERFACE |
static int |
ACC_NATIVE |
static int |
ACC_PRIVATE |
static int |
ACC_PROTECTED |
static int |
ACC_PUBLIC |
static int |
ACC_STATIC |
static int |
ACC_STRICT |
static int |
ACC_SUPER |
static int |
ACC_SYNCHRONIZED |
static int |
ACC_SYNTHETIC |
static int |
ACC_TRANSIENT |
static int |
ACC_VARARGS |
static int |
ACC_VOLATILE |
static int |
ADD |
static int |
AND |
protected static char |
ANNOTATION |
protected static char |
ARRAY |
static int |
ARRAYLENGTH |
static int |
ARRAYLOAD |
static int |
ARRAYSTORE |
protected static char |
BOOLEAN |
protected static char |
BYTE |
protected static char |
CHAR |
static int |
CHECKCAST |
protected static char |
CLASS |
static int |
CMP |
static int |
CMPG |
static int |
CMPL |
protected static int |
CONSTANT_Class |
protected static int |
CONSTANT_Double |
protected static int |
CONSTANT_FieldRef |
protected static int |
CONSTANT_Float |
protected static int |
CONSTANT_Integer |
protected static int |
CONSTANT_InterfaceMethodRef |
protected static int |
CONSTANT_Long |
protected static int |
CONSTANT_MethodRef |
protected static int |
CONSTANT_NameAndType |
protected static int |
CONSTANT_String |
protected static int |
CONSTANT_Utf8 |
static int |
CONVERT |
static int |
DIV |
protected static char |
DOUBLE |
static int |
DUP |
static int |
DUPX1 |
static int |
DUPX2 |
protected static char |
ENUM |
static int |
EQUALS |
static int |
FIELDLOAD |
static int |
FIELDSTORE |
protected static char |
FLOAT |
static int |
GOTO |
static int |
GREATERTHAN |
static int |
GREATERTHANEQUALS |
static int |
IF |
static int |
IFCMP |
static int |
IINC |
static int |
INSN_MASK |
static int |
INSTANCEOF |
protected static char |
INT |
static int |
INVOKE |
static int |
JSR |
static int |
LESSTHAN |
static int |
LESSTHANEQUALS |
static int |
LOADCONST |
static int |
LOADVAR |
protected static char |
LONG |
static int |
MONITORENTER |
static int |
MONITOREXIT |
static int |
MUL |
static int |
NEG |
static int |
NEW |
static int |
NONNULL |
static int |
NOP |
static int |
NOTEQUALS |
static int |
NULL |
static int[] |
opmap |
static int |
OR |
static int |
POP |
static int |
REM |
static int |
RET |
static int |
RETURN |
static int |
SHL |
protected static char |
SHORT |
static int |
SHR |
static int |
STORECONST |
static int |
STOREVAR |
protected static char |
STRING |
static int |
SUB |
static int |
SWAP |
static int |
SWITCH |
static int |
THROW |
static int |
USHR |
static byte |
VM_BOOLEAN |
static byte |
VM_BYTE |
static byte |
VM_CHAR |
static byte |
VM_DOUBLE |
static byte |
VM_FLOAT |
static byte |
VM_INT |
static byte |
VM_LONG |
static byte |
VM_SHORT |
static int |
WIDE_INSN |
static int |
XOR |
| Constructor and Description |
|---|
ClassFileReader(byte[] bytes,
BytecodeAttribute.Reader... readers)
Construct reader from byte array representing classfile.
|
ClassFileReader(byte[] bytes,
Collection<BytecodeAttribute.Reader> readers)
Construct reader from byte array representing classfile.
|
ClassFileReader(InputStream in,
BytecodeAttribute.Reader... readers)
Construct reader for classfile from InputStream
|
ClassFileReader(InputStream in,
Collection<BytecodeAttribute.Reader> readers)
Construct reader for classfile from InputStream
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
annotationLength(int offset) |
protected static JvmType.Array |
buildArraytype(int atype) |
Object |
convert(Constant.Info constant)
Convert a constant pool item into a Java constant object (e.g.
|
protected String |
createBranchLabel(int target,
HashMap<Integer,String> labels) |
protected JvmType.Primitive |
decodeConversionType(int offset) |
protected Bytecode |
decodeInstruction(int offset,
int start,
HashMap<Integer,String> labels,
int line) |
protected String |
decodeInstructionBranchTarget(int offset,
int start,
HashMap<Integer,String> labels,
int line)
Determine the relative offset for the destination of a branching
instruction.
|
protected Object |
decodeInstructionConstant(int offset,
int line) |
protected int |
decodeInstructionLength(int offset,
int codeOffsetP14) |
protected Triple<JvmType.Clazz,String,JvmType> |
decodeInstructionOwnerNameType(int offset,
int line) |
protected JvmType |
decodeInstructionType(int offset) |
protected int |
decodeInstructionVariable(int offset,
int line) |
Pair<Integer,JvmType>[] |
exceptionHandlers(int offset,
int exceptionTableOffset) |
String |
getClassName(int index)
This method is slightly ugly and it would be nice to get rid of it.
|
Constant.Info |
getConstant(int index)
Read constant value from this classfile's constant pool.
|
JvmType |
getConstantType(int index)
Get the type of the constant value from this classfile's constant pool.
|
String |
getString(int index)
Read string from this classfile's constant pool.
|
protected BytecodeAttribute |
parseAttribute(int offset,
ClassFile.Method enclosingMethod,
ClassFile enclosingClass) |
protected ArrayList<BytecodeAttribute> |
parseAttributes(int attributes,
ClassFile.Method enclosingMethod,
ClassFile enclosingClass)
parse any attributes associated with this field.
|
static JvmType.Clazz |
parseClassDescriptor(String descriptor)
This method parses a descriptor of the form "Lxxx.yyy.zzz$aaa$bbb;"
|
protected Triple<List<JvmType.Reference>,JvmType.Clazz,List<JvmType.Clazz>> |
parseClassSigDesc(String descriptor)
The class signature provides information about the generic type
parameters declared for a class.
|
protected Code |
parseCode(int offset,
String name,
ClassFile.Method enclosingMethod) |
protected ConstantValue |
parseConstantValue(int offset,
String name) |
static JvmType |
parseDescriptor(String descriptor)
This method parses a general type descriptor.
|
protected Exceptions |
parseExceptions(int offset,
String name) |
protected ClassFile.Field |
parseField(int offset) |
protected ArrayList<ClassFile.Field> |
parseFields(int fields)
parse array of fields defined in this class
|
static Pair<JvmType.Variable,Integer> |
parseFormalType(String descriptor,
int pos) |
protected InnerClasses |
parseInnerClasses(int offset,
String name,
JvmType.Clazz type) |
protected ArrayList<JvmType.Clazz> |
parseInterfaces(int interfaces)
Get array of interfaces implemented by this class.
|
static Pair<JvmType.Clazz,Integer> |
parseInternalClassDescriptor(String descriptor,
int pos) |
static Pair<JvmType,Integer> |
parseInternalDescriptor(String descriptor,
int pos) |
protected ClassFile.Method |
parseMethod(int offset,
String owner) |
static JvmType.Function |
parseMethodDescriptor(String descriptor) |
protected ArrayList<ClassFile.Method> |
parseMethods(int methods,
String owner)
parse array of methods defined in this class
|
ClassFile |
readClass()
Parse classfile and construct ClassInfo object.
|
protected static byte[] |
readStream(InputStream is) |
protected static final char BYTE
protected static final char CHAR
protected static final char DOUBLE
protected static final char FLOAT
protected static final char INT
protected static final char LONG
protected static final char SHORT
protected static final char BOOLEAN
protected static final char STRING
protected static final char ENUM
protected static final char CLASS
protected static final char ANNOTATION
protected static final char ARRAY
public static final int ACC_PUBLIC
public static final int ACC_PRIVATE
public static final int ACC_PROTECTED
public static final int ACC_STATIC
public static final int ACC_FINAL
public static final int ACC_VOLATILE
public static final int ACC_TRANSIENT
public static final int ACC_SYNTHETIC
public static final int ACC_BRIDGE
public static final int ACC_VARARGS
public static final int ACC_ANNOTATION
public static final int ACC_ENUM
public static final int ACC_SYNCHRONIZED
public static final int ACC_NATIVE
public static final int ACC_ABSTRACT
public static final int ACC_STRICT
public static final int ACC_INTERFACE
public static final int ACC_SUPER
protected static final int CONSTANT_Class
protected static final int CONSTANT_FieldRef
protected static final int CONSTANT_MethodRef
protected static final int CONSTANT_InterfaceMethodRef
protected static final int CONSTANT_String
protected static final int CONSTANT_Integer
protected static final int CONSTANT_Float
protected static final int CONSTANT_Long
protected static final int CONSTANT_Double
protected static final int CONSTANT_NameAndType
protected static final int CONSTANT_Utf8
public static final byte VM_BOOLEAN
public static final byte VM_CHAR
public static final byte VM_FLOAT
public static final byte VM_DOUBLE
public static final byte VM_BYTE
public static final byte VM_SHORT
public static final byte VM_INT
public static final byte VM_LONG
public static final int INSN_MASK
public static final int WIDE_INSN
public static final int NOP
public static final int LOADVAR
public static final int STOREVAR
public static final int LOADCONST
public static final int STORECONST
public static final int ARRAYLOAD
public static final int ARRAYSTORE
public static final int ARRAYLENGTH
public static final int IINC
public static final int NEW
public static final int THROW
public static final int CHECKCAST
public static final int INSTANCEOF
public static final int MONITORENTER
public static final int MONITOREXIT
public static final int SWITCH
public static final int CONVERT
public static final int POP
public static final int DUP
public static final int DUPX1
public static final int DUPX2
public static final int SWAP
public static final int ADD
public static final int SUB
public static final int MUL
public static final int DIV
public static final int REM
public static final int NEG
public static final int SHL
public static final int SHR
public static final int USHR
public static final int AND
public static final int OR
public static final int XOR
public static final int CMP
public static final int CMPL
public static final int CMPG
public static final int IF
public static final int IFCMP
public static final int GOTO
public static final int JSR
public static final int RET
public static final int RETURN
public static final int FIELDLOAD
public static final int FIELDSTORE
public static final int INVOKE
public static final int EQUALS
public static final int NOTEQUALS
public static final int LESSTHAN
public static final int GREATERTHANEQUALS
public static final int GREATERTHAN
public static final int LESSTHANEQUALS
public static final int NULL
public static final int NONNULL
public static final int[] opmap
public ClassFileReader(InputStream in, BytecodeAttribute.Reader... readers) throws IOException
in - InputStream from which class file is readreaders - Collection of attribute readersIOExceptionpublic ClassFileReader(InputStream in, Collection<BytecodeAttribute.Reader> readers) throws IOException
in - InputStream from which class file is readreaders - Collection of attribute readersIOExceptionpublic ClassFileReader(byte[] bytes,
BytecodeAttribute.Reader... readers)
bytes - the byte array from which this class file is read.readers - Collection of attribute readersClassFormatError - if the classfile is invalid.public ClassFileReader(byte[] bytes,
Collection<BytecodeAttribute.Reader> readers)
bytes - the byte array from which this class file is read.readers - Collection of attribute readersClassFormatError - if the classfile is invalid.public ClassFile readClass()
ClassFormatError - if the classfile is invalid.protected ArrayList<JvmType.Clazz> parseInterfaces(int interfaces)
protected ArrayList<ClassFile.Field> parseFields(int fields)
protected ClassFile.Field parseField(int offset)
protected ArrayList<ClassFile.Method> parseMethods(int methods, String owner)
protected ClassFile.Method parseMethod(int offset, String owner)
protected ArrayList<BytecodeAttribute> parseAttributes(int attributes, ClassFile.Method enclosingMethod, ClassFile enclosingClass)
protected BytecodeAttribute parseAttribute(int offset, ClassFile.Method enclosingMethod, ClassFile enclosingClass)
protected Exceptions parseExceptions(int offset, String name)
protected ConstantValue parseConstantValue(int offset, String name)
protected InnerClasses parseInnerClasses(int offset, String name, JvmType.Clazz type)
public static JvmType parseDescriptor(String descriptor)
descriptor - public static JvmType.Clazz parseClassDescriptor(String descriptor)
descriptor - protected Triple<List<JvmType.Reference>,JvmType.Clazz,List<JvmType.Clazz>> parseClassSigDesc(String descriptor)
public static Pair<JvmType,Integer> parseInternalDescriptor(String descriptor, int pos)
public static Pair<JvmType.Clazz,Integer> parseInternalClassDescriptor(String descriptor, int pos)
public static Pair<JvmType.Variable,Integer> parseFormalType(String descriptor, int pos)
public static JvmType.Function parseMethodDescriptor(String descriptor)
protected Code parseCode(int offset, String name, ClassFile.Method enclosingMethod)
protected Bytecode decodeInstruction(int offset, int start, HashMap<Integer,String> labels, int line)
protected int decodeInstructionVariable(int offset,
int line)
protected int decodeInstructionLength(int offset,
int codeOffsetP14)
protected String decodeInstructionBranchTarget(int offset, int start, HashMap<Integer,String> labels, int line)
offset - start - line - protected JvmType decodeInstructionType(int offset)
protected static final JvmType.Array buildArraytype(int atype)
protected JvmType.Primitive decodeConversionType(int offset)
protected Object decodeInstructionConstant(int offset, int line)
public Object convert(Constant.Info constant)
java.lang.Integer, java.lang.String, etc).constant - Constant pool item to be converted. Should be an instance of
Constant.String, Constant.Integer,
Constant.Long, Constant.Float,
Constant.Double.protected Triple<JvmType.Clazz,String,JvmType> decodeInstructionOwnerNameType(int offset, int line)
public Pair<Integer,JvmType>[] exceptionHandlers(int offset, int exceptionTableOffset)
protected int annotationLength(int offset)
public final String getString(int index)
index - index into constant poolpublic final Constant.Info getConstant(int index)
index - public final JvmType getConstantType(int index)
index - public final String getClassName(int index)
index - protected static byte[] readStream(InputStream is) throws IOException
IOExceptionCopyright © 2016. All rights reserved.