public class BytecodeStream extends Object implements BytecodeConstants
JBC_aaload, JBC_aastore, JBC_aconst_null, JBC_aload, JBC_aload_0, JBC_aload_1, JBC_aload_2, JBC_aload_3, JBC_anewarray, JBC_areturn, JBC_arraylength, JBC_astore, JBC_astore_0, JBC_astore_1, JBC_astore_2, JBC_astore_3, JBC_athrow, JBC_baload, JBC_bastore, JBC_bipush, JBC_caload, JBC_castore, JBC_checkcast, JBC_d2f, JBC_d2i, JBC_d2l, JBC_dadd, JBC_daload, JBC_dastore, JBC_dcmpg, JBC_dcmpl, JBC_dconst_0, JBC_dconst_1, JBC_ddiv, JBC_dload, JBC_dload_0, JBC_dload_1, JBC_dload_2, JBC_dload_3, JBC_dmul, JBC_dneg, JBC_drem, JBC_dreturn, JBC_dstore, JBC_dstore_0, JBC_dstore_1, JBC_dstore_2, JBC_dstore_3, JBC_dsub, JBC_dup, JBC_dup_x1, JBC_dup_x2, JBC_dup2, JBC_dup2_x1, JBC_dup2_x2, JBC_f2d, JBC_f2i, JBC_f2l, JBC_fadd, JBC_faload, JBC_fastore, JBC_fcmpg, JBC_fcmpl, JBC_fconst_0, JBC_fconst_1, JBC_fconst_2, JBC_fdiv, JBC_fload, JBC_fload_0, JBC_fload_1, JBC_fload_2, JBC_fload_3, JBC_fmul, JBC_fneg, JBC_frem, JBC_freturn, JBC_fstore, JBC_fstore_0, JBC_fstore_1, JBC_fstore_2, JBC_fstore_3, JBC_fsub, JBC_getfield, JBC_getstatic, JBC_goto, JBC_goto_w, JBC_i2d, JBC_i2f, JBC_i2l, JBC_iadd, JBC_iaload, JBC_iand, JBC_iastore, JBC_iconst_0, JBC_iconst_1, JBC_iconst_2, JBC_iconst_3, JBC_iconst_4, JBC_iconst_5, JBC_iconst_m1, JBC_idiv, JBC_if_acmpeq, JBC_if_acmpne, JBC_if_icmpeq, JBC_if_icmpge, JBC_if_icmpgt, JBC_if_icmple, JBC_if_icmplt, JBC_if_icmpne, JBC_ifeq, JBC_ifge, JBC_ifgt, JBC_ifle, JBC_iflt, JBC_ifne, JBC_ifnonnull, JBC_ifnull, JBC_iinc, JBC_iload, JBC_iload_0, JBC_iload_1, JBC_iload_2, JBC_iload_3, JBC_impdep1, JBC_impdep2, JBC_imul, JBC_ineg, JBC_instanceof, JBC_int2byte, JBC_int2char, JBC_int2short, JBC_invokeinterface, JBC_invokespecial, JBC_invokestatic, JBC_invokevirtual, JBC_ior, JBC_irem, JBC_ireturn, JBC_ishl, JBC_ishr, JBC_istore, JBC_istore_0, JBC_istore_1, JBC_istore_2, JBC_istore_3, JBC_isub, JBC_iushr, JBC_ixor, JBC_jsr, JBC_jsr_w, JBC_l2d, JBC_l2f, JBC_l2i, JBC_ladd, JBC_laload, JBC_land, JBC_lastore, JBC_lcmp, JBC_lconst_0, JBC_lconst_1, JBC_ldc, JBC_ldc_w, JBC_ldc2_w, JBC_ldiv, JBC_length, JBC_lload, JBC_lload_0, JBC_lload_1, JBC_lload_2, JBC_lload_3, JBC_lmul, JBC_lneg, JBC_lookupswitch, JBC_lor, JBC_lrem, JBC_lreturn, JBC_lshl, JBC_lshr, JBC_lstore, JBC_lstore_0, JBC_lstore_1, JBC_lstore_2, JBC_lstore_3, JBC_lsub, JBC_lushr, JBC_lxor, JBC_monitorenter, JBC_monitorexit, JBC_multianewarray, JBC_name, JBC_new, JBC_newarray, JBC_nop, JBC_pop, JBC_pop2, JBC_putfield, JBC_putstatic, JBC_ret, JBC_return, JBC_saload, JBC_sastore, JBC_sipush, JBC_swap, JBC_tableswitch, JBC_wide, JBC_xxxunusedxxx
Constructor and Description |
---|
BytecodeStream(IMethod m,
byte[] bc) |
Modifier and Type | Method and Description |
---|---|
void |
alignInvokeInterface()
Skips the extra stuff after an invokeinterface instruction Used for invokeinterface
|
void |
alignSwitch()
Skips the padding of a switch instruction Used for tableswitch, lookupswitch
|
int |
computeLookupSwitchOffset(int value,
int num)
Returns the offset for a given value of the lookupswitch (as a signed int) or 0 if the value is not in the table.
|
int |
computeTableSwitchOffset(int value,
int low,
int high)
Returns the offset for a given value of the tableswitch (as a signed int) or 0 if the value is out of range.
|
IClass |
declaringClass()
Returns the declaring class that this bytecode stream is from
|
int |
getArrayDimension()
Returns the dimension of the array (as an unsigned byte) Used for multianewarray
|
int |
getArrayElementType()
Returns the element type (primitive) of the array (as an unsigned byte) Used for newarray
|
int |
getBranchOffset()
Returns the offset of the branch (as a signed short) Used for if
|
int |
getByteValue()
Returns a signed byte value Used for bipush
|
int |
getConstantIndex()
Returns the constant pool index of a constant (as an unsigned byte) Used for ldc
|
int |
getDefaultSwitchOffset()
Returns the default offset of the switch (as a signed int) Used for tableswitch, lookupswitch
|
int |
getHighSwitchValue()
Returns the highest value of the tableswitch (as a signed int) Used for tableswitch
|
int |
getIncrement()
Returns an increment value (as a signed byte) Used for iinc
|
int |
getLocalNumber()
Returns the number of the local (as an unsigned byte) Used for iload, lload, fload, dload, aload, istore, lstore, fstore,
dstore, astore, iinc, ret
|
int |
getLookupSwitchOffset(int num)
Returns the numbered offset of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at
the start of the pair table NOTE: Will NOT advance cursor
|
int |
getLookupSwitchValue(int num)
Returns the numbered value of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the
start of the pair table NOTE: Will NOT advance cursor
|
int |
getLowSwitchValue()
Returns the lowest value of the tableswitch (as a signed int) Used for tableswitch
|
int |
getOpcode()
Returns the opcode of the current instruction in the sequence Note: if skipInstruction has been called, but nextInstruction has
not, this method will return the opcode of the skipped instruction!
|
int |
getShortValue()
Returns a signed short value Used for sipush
|
int |
getSwitchLength()
Returns the number of match-offset pairs in the lookupswitch (as a signed int) Used for lookupswitch
|
int |
getTableSwitchOffset(int num)
Returns the numbered offset of the tableswitch (as a signed int) Used for tableswitch The "cursor" has to be positioned at the
start of the offset table NOTE: Will NOT advance cursor
|
int |
getWideBranchOffset()
Returns the wide offset of the branch (as a signed int) Used for goto_w, jsr_w
|
int |
getWideConstantIndex()
Returns the wide constant pool index of a constant (as an unsigned short) Used for ldc_w, ldc2_w
|
int |
getWideIncrement()
Returns an increment value (as a signed short) Used for iinc prefixed by wide
|
int |
getWideLocalNumber()
Returns the wide number of the local (as an unsigned short) Used for iload, lload, fload, dload, aload, istore, lstore, fstore,
dstore, astore, iinc prefixed by wide
|
int |
getWideOpcode()
Returns the opcode of the wide instruction Used for wide Can be one of iload, lload, fload, dload, aload, istore, lstore,
fstore, dstore, astore, iinc
|
boolean |
hasMoreBytecodes()
Does the stream have more bytecodes in it?
|
int |
index()
Returns the current bytecode index
|
boolean |
isWide()
Are we currently processing a wide instruction?
|
int |
length()
Returns the length of the bytecode stream Returns 0 if the method doesn't have any bytecodes (i.e.
|
IMethod |
method()
Returns the method that this bytecode stream is from
|
int |
nextInstruction()
Sets up the next instruction in the sequence
|
int |
peekNextOpcode()
Returns the opcode of the next instruction in the sequence without advancing to it
|
void |
reset()
Resets the stream to the beginning
|
void |
reset(int index)
Resets the stream to a given position Use with caution
|
void |
skipInstruction()
Skips the current instruction
|
void |
skipInstruction(int opc,
boolean w)
Skips the current instruction (without using the opcode field) A slightly optimized version of skipInstruction()
|
void |
skipLookupSwitchPairs(int num)
Skips the match-offset pairs of a lookupswitch instruction Used for lookupswitch
|
void |
skipTableSwitchOffsets(int num)
Skips the offsets of a tableswitch instruction Used for tableswitch
|
public BytecodeStream(IMethod m, byte[] bc)
m
- the method containing the bytecodesbc
- the array of bytecodesIllegalArgumentException
- if bc is nullIllegalArgumentException
- if m is nullpublic final IMethod method()
public final IClass declaringClass()
public final int length()
public final int index()
public final void reset()
public final void reset(int index)
index
- the position to reset the stream topublic final boolean hasMoreBytecodes()
public final int peekNextOpcode()
nextInstruction()
public final int nextInstruction()
peekNextOpcode()
public final int getOpcode()
nextInstruction()
,
isWide()
public final boolean isWide()
nextInstruction()
,
getOpcode()
public final void skipInstruction()
skipInstruction(int,boolean)
public final void skipInstruction(int opc, boolean w)
opc
- current opcodew
- whether current instruction follows wideskipInstruction()
public final int getByteValue()
public final int getShortValue()
public final int getLocalNumber()
getWideLocalNumber()
public final int getWideLocalNumber()
getLocalNumber()
public final int getIncrement()
getWideIncrement()
public final int getWideIncrement()
getIncrement()
public final int getBranchOffset()
getWideBranchOffset()
public final int getWideBranchOffset()
getBranchOffset()
public final void alignSwitch()
public final int getDefaultSwitchOffset()
public final int getLowSwitchValue()
getHighSwitchValue()
public final int getHighSwitchValue()
getLowSwitchValue()
public final void skipTableSwitchOffsets(int num)
num
- the number of offsets to skipgetTableSwitchOffset(int)
public final int getTableSwitchOffset(int num)
num
- the number of the offset to retrievepublic final int computeTableSwitchOffset(int value, int low, int high)
value
- the value to retrieve offset forlow
- the lowest value of the tableswitchhigh
- the highest value of the tableswitchpublic final int getSwitchLength()
public final void skipLookupSwitchPairs(int num)
num
- the number of match-offset pairs to skipgetLookupSwitchValue(int)
,
getLookupSwitchOffset(int)
public final int getLookupSwitchOffset(int num)
num
- the number of the offset to retrievegetLookupSwitchValue(int)
public final int getLookupSwitchValue(int num)
num
- the number of the value to retrievegetLookupSwitchOffset(int)
public final int computeLookupSwitchOffset(int value, int num)
value
- the value to retrieve offset fornum
- the number of match-offset pairs in the lookupswitchpublic final void alignInvokeInterface()
public final int getArrayElementType()
public final int getArrayDimension()
public final int getWideOpcode()
public final int getConstantIndex()
getWideConstantIndex()
public final int getWideConstantIndex()
getConstantIndex()