|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjasm.io.ClassFileReader
public final class ClassFileReader
The ClassFileReader
is responsible for reading in a class file
and constructing a ClassFile
object from it.
Nested Class Summary | |
---|---|
protected static class |
ClassFileReader.ClassConstant
This class represents a class constant. |
Field Summary | |
---|---|
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 Summary | |
---|---|
ClassFileReader(byte[] b,
BytecodeAttribute.Reader... readers)
Construct reader from byte array representing classfile. |
|
ClassFileReader(byte[] b,
java.util.Collection<BytecodeAttribute.Reader> readers)
Construct reader from byte array representing classfile. |
|
ClassFileReader(java.io.InputStream in,
BytecodeAttribute.Reader... readers)
Construct reader for classfile from InputStream |
|
ClassFileReader(java.io.InputStream in,
java.util.Collection<BytecodeAttribute.Reader> readers)
Construct reader for classfile from InputStream |
Method Summary | |
---|---|
protected int |
annotationLength(int offset)
|
protected static JvmType.Array |
buildArraytype(int atype)
|
java.lang.Object |
convert(Constant.Info constant)
Convert a constant pool item into a Java constant object (e.g. |
protected java.lang.String |
createBranchLabel(int target,
java.util.HashMap<java.lang.Integer,java.lang.String> labels)
|
protected JvmType.Primitive |
decodeConversionType(int offset)
|
protected Bytecode |
decodeInstruction(int offset,
int start,
java.util.HashMap<java.lang.Integer,java.lang.String> labels,
int line)
|
protected java.lang.String |
decodeInstructionBranchTarget(int offset,
int start,
java.util.HashMap<java.lang.Integer,java.lang.String> labels,
int line)
Determine the relative offset for the destination of a branching instruction. |
protected java.lang.Object |
decodeInstructionConstant(int offset,
int line)
|
protected int |
decodeInstructionLength(int offset,
int codeOffsetP14)
|
protected Triple<JvmType.Clazz,java.lang.String,JvmType> |
decodeInstructionOwnerNameType(int offset,
int line)
|
protected JvmType |
decodeInstructionType(int offset)
|
protected int |
decodeInstructionVariable(int offset,
int line)
|
Pair<java.lang.Integer,JvmType>[] |
exceptionHandlers(int offset,
int exceptionTableOffset)
|
java.lang.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. |
java.lang.String |
getString(int index)
Read string from this classfile's constant pool. |
protected BytecodeAttribute |
parseAttribute(int offset,
ClassFile.Method enclosingMethod,
ClassFile enclosingClass)
|
protected java.util.ArrayList<BytecodeAttribute> |
parseAttributes(int attributes,
ClassFile.Method enclosingMethod,
ClassFile enclosingClass)
parse any attributes associated with this field. |
static JvmType.Clazz |
parseClassDescriptor(java.lang.String descriptor)
This method parses a descriptor of the form "Lxxx.yyy.zzz$aaa$bbb;" |
protected Triple<java.util.List<JvmType.Reference>,JvmType.Clazz,java.util.List<JvmType.Clazz>> |
parseClassSigDesc(java.lang.String descriptor)
The class signature provides information about the generic type parameters declared for a class. |
protected Code |
parseCode(int offset,
java.lang.String name,
ClassFile.Method enclosingMethod)
|
protected ConstantValue |
parseConstantValue(int offset,
java.lang.String name)
|
static JvmType |
parseDescriptor(java.lang.String descriptor)
This method parses a general type descriptor. |
protected Exceptions |
parseExceptions(int offset,
java.lang.String name)
|
protected ClassFile.Field |
parseField(int offset)
|
protected java.util.ArrayList<ClassFile.Field> |
parseFields(int fields)
parse array of fields defined in this class |
static Pair<JvmType.Variable,java.lang.Integer> |
parseFormalType(java.lang.String descriptor,
int pos)
|
protected InnerClasses |
parseInnerClasses(int offset,
java.lang.String name,
JvmType.Clazz type)
|
protected java.util.ArrayList<JvmType.Clazz> |
parseInterfaces(int interfaces)
Get array of interfaces implemented by this class. |
static Pair<JvmType.Clazz,java.lang.Integer> |
parseInternalClassDescriptor(java.lang.String descriptor,
int pos)
|
static Pair<JvmType,java.lang.Integer> |
parseInternalDescriptor(java.lang.String descriptor,
int pos)
|
protected ClassFile.Method |
parseMethod(int offset,
java.lang.String owner)
|
static JvmType.Function |
parseMethodDescriptor(java.lang.String descriptor)
|
protected java.util.ArrayList<ClassFile.Method> |
parseMethods(int methods,
java.lang.String owner)
parse array of methods defined in this class |
ClassFile |
readClass()
Parse classfile and construct ClassInfo object. |
protected static byte[] |
readStream(java.io.InputStream is)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
public ClassFileReader(java.io.InputStream in, BytecodeAttribute.Reader... readers) throws java.io.IOException
fileName
- The filename of the java classfile. Use dot notation for
specifying packages.
java.io.IOException
public ClassFileReader(java.io.InputStream in, java.util.Collection<BytecodeAttribute.Reader> readers) throws java.io.IOException
fileName
- The filename of the java classfile. Use dot notation for
specifying packages.
java.io.IOException
public ClassFileReader(byte[] b, BytecodeAttribute.Reader... readers)
b
- the byte array!
java.lang.ClassFormatError
- if the classfile is invalid.public ClassFileReader(byte[] b, java.util.Collection<BytecodeAttribute.Reader> readers)
b
- the byte array!
java.lang.ClassFormatError
- if the classfile is invalid.Method Detail |
---|
public ClassFile readClass()
java.lang.ClassFormatError
- if the classfile is invalid.protected java.util.ArrayList<JvmType.Clazz> parseInterfaces(int interfaces)
protected java.util.ArrayList<ClassFile.Field> parseFields(int fields)
protected ClassFile.Field parseField(int offset)
protected java.util.ArrayList<ClassFile.Method> parseMethods(int methods, java.lang.String owner)
protected ClassFile.Method parseMethod(int offset, java.lang.String owner)
protected java.util.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, java.lang.String name)
protected ConstantValue parseConstantValue(int offset, java.lang.String name)
protected InnerClasses parseInnerClasses(int offset, java.lang.String name, JvmType.Clazz type)
public static JvmType parseDescriptor(java.lang.String descriptor)
descriptor
-
public static JvmType.Clazz parseClassDescriptor(java.lang.String descriptor)
descriptor
-
protected Triple<java.util.List<JvmType.Reference>,JvmType.Clazz,java.util.List<JvmType.Clazz>> parseClassSigDesc(java.lang.String descriptor)
public static Pair<JvmType,java.lang.Integer> parseInternalDescriptor(java.lang.String descriptor, int pos)
public static Pair<JvmType.Clazz,java.lang.Integer> parseInternalClassDescriptor(java.lang.String descriptor, int pos)
public static Pair<JvmType.Variable,java.lang.Integer> parseFormalType(java.lang.String descriptor, int pos)
public static JvmType.Function parseMethodDescriptor(java.lang.String descriptor)
protected Code parseCode(int offset, java.lang.String name, ClassFile.Method enclosingMethod)
protected Bytecode decodeInstruction(int offset, int start, java.util.HashMap<java.lang.Integer,java.lang.String> labels, int line)
protected int decodeInstructionVariable(int offset, int line)
protected int decodeInstructionLength(int offset, int codeOffsetP14)
protected java.lang.String decodeInstructionBranchTarget(int offset, int start, java.util.HashMap<java.lang.Integer,java.lang.String> labels, int line)
offset
- start
- line
-
protected java.lang.String createBranchLabel(int target, java.util.HashMap<java.lang.Integer,java.lang.String> labels)
protected JvmType decodeInstructionType(int offset)
protected static final JvmType.Array buildArraytype(int atype)
protected JvmType.Primitive decodeConversionType(int offset)
protected java.lang.Object decodeInstructionConstant(int offset, int line)
public java.lang.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,java.lang.String,JvmType> decodeInstructionOwnerNameType(int offset, int line)
public Pair<java.lang.Integer,JvmType>[] exceptionHandlers(int offset, int exceptionTableOffset)
protected int annotationLength(int offset)
public final java.lang.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 java.lang.String getClassName(int index)
index
-
protected static byte[] readStream(java.io.InputStream is) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |