org.objectweb.asm.Opcodes# ICONST_2 ( ) 源码实例Demo

下面列出了org.objectweb.asm.Opcodes# ICONST_2 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: AsmUtil.java

/**
 * Determine if the given opcode is a load of a constant (xCONST_y).
 *
 * @param opcode the opcode
 * @return true if the opcode is one of the constant loading ones, false otherwise
 */
public static boolean isXconst(final int opcode) {
  switch(opcode) {
  case Opcodes.ICONST_0:
  case Opcodes.ICONST_1:
  case Opcodes.ICONST_2:
  case Opcodes.ICONST_3:
  case Opcodes.ICONST_4:
  case Opcodes.ICONST_5:
  case Opcodes.ICONST_M1:
  case Opcodes.DCONST_0:
  case Opcodes.DCONST_1:
  case Opcodes.FCONST_0:
  case Opcodes.FCONST_1:
  case Opcodes.LCONST_0:
  case Opcodes.LCONST_1:
    return true;
  }

  return false;
}
 
源代码2 项目: Cafebabe   文件: OpcodeFormatting.java

/**
 * Gets the integer value of a given opcode.
 * 
 * @param opcode
 * @return
 */
public static int getIntValue(int opcode) {
	if (opcode == Opcodes.ICONST_0) {
		return 0;
	} else if (opcode == Opcodes.ICONST_1) {
		return 1;
	} else if (opcode == Opcodes.ICONST_2) {
		return 2;
	} else if (opcode == Opcodes.ICONST_3) {
		return 3;
	} else if (opcode == Opcodes.ICONST_4) {
		return 4;
	} else if (opcode == Opcodes.ICONST_5) {
		return 5;
	} else {
		return -1;
	}
}
 
源代码3 项目: Cafebabe   文件: OpcodeFormatting.java

/**
 * Given an integer, returns an InsnNode that will properly represent the int.
 * 
 * @param i
 * @return
 */
public static AbstractInsnNode toInt(int i) {
	switch (i) {
	case -1:
		return new InsnNode(Opcodes.ICONST_M1);
	case 0:
		return new InsnNode(Opcodes.ICONST_0);
	case 1:
		return new InsnNode(Opcodes.ICONST_1);
	case 2:
		return new InsnNode(Opcodes.ICONST_2);
	case 3:
		return new InsnNode(Opcodes.ICONST_3);
	case 4:
		return new InsnNode(Opcodes.ICONST_4);
	case 5:
		return new InsnNode(Opcodes.ICONST_5);
	}
	if (i > -129 && i < 128) {
		return new IntInsnNode(Opcodes.BIPUSH, i);
	}
	return new LdcInsnNode(i);
}
 
源代码4 项目: zelixkiller   文件: OpUtils.java

/**
 * Gets the integer value of a given opcode.
 * 
 * @param opcode
 * @return
 */
public static int getIntValue(int opcode) {
	if (opcode == Opcodes.ICONST_0) {
		return 0;
	} else if (opcode == Opcodes.ICONST_1) {
		return 1;
	} else if (opcode == Opcodes.ICONST_2) {
		return 2;
	} else if (opcode == Opcodes.ICONST_3) {
		return 3;
	} else if (opcode == Opcodes.ICONST_4) {
		return 4;
	} else if (opcode == Opcodes.ICONST_5) {
		return 5;
	} else {
		return -1;
	}
}
 
源代码5 项目: zelixkiller   文件: OpUtils.java

/**
 * Given an integer, returns an InsnNode that will properly represent the
 * int.
 * 
 * @param i
 * @return
 */
public static AbstractInsnNode toInt(int i) {
	switch (i) {
	case -1:
		return new InsnNode(Opcodes.ICONST_M1);
	case 0:
		return new InsnNode(Opcodes.ICONST_0);
	case 1:
		return new InsnNode(Opcodes.ICONST_1);
	case 2:
		return new InsnNode(Opcodes.ICONST_2);
	case 3:
		return new InsnNode(Opcodes.ICONST_3);
	case 4:
		return new InsnNode(Opcodes.ICONST_4);
	case 5:
		return new InsnNode(Opcodes.ICONST_5);
	}
	if (i > -129 && i < 128) {
		return new IntInsnNode(Opcodes.BIPUSH, i);
	}
	return new LdcInsnNode(i);
}
 
源代码6 项目: JByteMod-Beta   文件: OpUtils.java

/**
 * Gets the integer value of a given opcode.
 * 
 * @param opcode
 * @return
 */
public static int getIntValue(int opcode) {
  if (opcode == Opcodes.ICONST_0) {
    return 0;
  } else if (opcode == Opcodes.ICONST_1) {
    return 1;
  } else if (opcode == Opcodes.ICONST_2) {
    return 2;
  } else if (opcode == Opcodes.ICONST_3) {
    return 3;
  } else if (opcode == Opcodes.ICONST_4) {
    return 4;
  } else if (opcode == Opcodes.ICONST_5) {
    return 5;
  } else {
    return -1;
  }
}
 
源代码7 项目: JByteMod-Beta   文件: OpUtils.java

/**
 * Given an integer, returns an InsnNode that will properly represent the int.
 * 
 * @param i
 * @return
 */
public static AbstractInsnNode toInt(int i) {
  switch (i) {
  case -1:
    return new InsnNode(Opcodes.ICONST_M1);
  case 0:
    return new InsnNode(Opcodes.ICONST_0);
  case 1:
    return new InsnNode(Opcodes.ICONST_1);
  case 2:
    return new InsnNode(Opcodes.ICONST_2);
  case 3:
    return new InsnNode(Opcodes.ICONST_3);
  case 4:
    return new InsnNode(Opcodes.ICONST_4);
  case 5:
    return new InsnNode(Opcodes.ICONST_5);
  }
  if (i > -129 && i < 128) {
    return new IntInsnNode(Opcodes.BIPUSH, i);
  }
  return new LdcInsnNode(i);
}
 
源代码8 项目: deobfuscator   文件: LoadIntStep.java

public LoadIntStep() {
    super((a) -> 
    {
    	if(!(a instanceof LdcInsnNode))
    		return true;
    	return ((LdcInsnNode)a).cst instanceof Integer;
    },Opcodes.ICONST_M1,
            Opcodes.ICONST_0,
            Opcodes.ICONST_1,
            Opcodes.ICONST_2,
            Opcodes.ICONST_3,
            Opcodes.ICONST_4,
            Opcodes.ICONST_5,
            Opcodes.LDC,
            Opcodes.BIPUSH,
            Opcodes.SIPUSH
    );
}
 
源代码9 项目: deobfuscator   文件: Utils.java

public static AbstractInsnNode getNumberInsn(int num) {
    switch (num) {
    	case -1:
    		return new InsnNode(Opcodes.ICONST_M1);
        case 0:
            return new InsnNode(Opcodes.ICONST_0);
        case 1:
            return new InsnNode(Opcodes.ICONST_1);
        case 2:
            return new InsnNode(Opcodes.ICONST_2);
        case 3:
            return new InsnNode(Opcodes.ICONST_3);
        case 4:
            return new InsnNode(Opcodes.ICONST_4);
        case 5:
            return new InsnNode(Opcodes.ICONST_5);
        default:
        	if(num >= -128 && num <= 127)
        		return new IntInsnNode(Opcodes.BIPUSH, num);
        	else if(num >= -32768 && num <= 32767)
        		return new IntInsnNode(Opcodes.SIPUSH, num);
        	else
        		return new LdcInsnNode(num);
    }
}
 
源代码10 项目: CodenameOne   文件: BasicInstruction.java

@Override
public boolean isConstant() {
    switch (opcode) {
        case Opcodes.ACONST_NULL:
        case Opcodes.ICONST_0:
        case Opcodes.ICONST_1:
        case Opcodes.ICONST_2:
        case Opcodes.ICONST_3:
        case Opcodes.ICONST_4:
        case Opcodes.ICONST_5:
        case Opcodes.ICONST_M1:
        case Opcodes.FCONST_0:
        case Opcodes.FCONST_1:
        case Opcodes.FCONST_2:
        case Opcodes.DCONST_0:
        case Opcodes.DCONST_1:
        case Opcodes.LCONST_0:
        case Opcodes.LCONST_1:
        case Opcodes.LDC:
            return true;
    }
    return super.isConstant();
}
 
源代码11 项目: pitest   文件: AbstractCRCRVisitor.java

Number translateToNumber(final int opcode) {
    switch (opcode) {
        case Opcodes.ICONST_M1:
            return Integer.valueOf(-1);
        case Opcodes.ICONST_0:
            return Integer.valueOf(0);
        case Opcodes.ICONST_1:
            return Integer.valueOf(1);
        case Opcodes.ICONST_2:
            return Integer.valueOf(2);
        case Opcodes.ICONST_3:
            return Integer.valueOf(3);
        case Opcodes.ICONST_4:
            return Integer.valueOf(4);
        case Opcodes.ICONST_5:
            return Integer.valueOf(5);
        case Opcodes.LCONST_0:
            return Long.valueOf(0L);
        case Opcodes.LCONST_1:
            return Long.valueOf(1L);
        case Opcodes.FCONST_0:
            return Float.valueOf(0F);
        case Opcodes.FCONST_1:
            return Float.valueOf(1F);
        case Opcodes.FCONST_2:
            return Float.valueOf(2F);
        case Opcodes.DCONST_0:
            return Double.valueOf(0D);
        case Opcodes.DCONST_1:
            return Double.valueOf(1D);
        default:
            return null;
    }
}
 
源代码12 项目: Concurnas   文件: BytecodeGenUtils.java

public static void intOpcode(MethodVisitor mv, int input)
{//TODO: nasty copy paste
	if(input ==-1)
	{
		mv.visitInsn(Opcodes.ICONST_M1);
	}
	else if(input > -1 && input <= 5)
	{
		int res = Opcodes.ICONST_5;
		switch(input)
		{
			case 0: res =  Opcodes.ICONST_0; break;
			case 1: res =  Opcodes.ICONST_1; break;
			case 2: res =  Opcodes.ICONST_2; break;
			case 3: res =  Opcodes.ICONST_3; break;
			case 4: res =  Opcodes.ICONST_4; break;
		}
		mv.visitInsn(res);
	}
	else if( -128 <= input && input <= 127)
	{//8 bit
		mv.visitIntInsn(Opcodes.BIPUSH, input);
	}
	else if( -32768 <= input && input <= 32767)
	{//16 bit
		mv.visitIntInsn(Opcodes.SIPUSH, input);
	}
	else
	{//32 bit - ldc
		mv.visitLdcInsn(new Integer(input));
	}
}
 
源代码13 项目: Concurnas   文件: Utils.java

public static void intOpcode(BytecodeOutputter mv, int input)
{
	if(input ==-1)
	{
		mv.visitInsn(Opcodes.ICONST_M1);
	}
	else if(input >= 0 && input <= 5)
	{
		int res = Opcodes.ICONST_5;
		switch(input)
		{
			case 0: res =  Opcodes.ICONST_0; break;
			case 1: res =  Opcodes.ICONST_1; break;
			case 2: res =  Opcodes.ICONST_2; break;
			case 3: res =  Opcodes.ICONST_3; break;
			case 4: res =  Opcodes.ICONST_4; break;
		}
		mv.visitInsn(res);
	}
	else if( -128 <= input && input <= 127)
	{//8 bit
		mv.visitIntInsn(Opcodes.BIPUSH, input);
	}
	else if( -32768 <= input && input <= 32767)
	{//16 bit
		mv.visitIntInsn(Opcodes.SIPUSH, input);
	}
	else
	{//32 bit - ldc
		mv.visitLdcInsn(new Integer(input));
	}
}
 

@Test
public void test_checkTableSwitch() throws Exception {
    List<BasicBlock> hashCodeBlocks = METHOD_BLOCKS.get("checkTableSwitch(I)I");
    int[][] expectedHashCodeBlocks = new int[][]{
            {Opcodes.ICONST_5, Opcodes.ISTORE, Opcodes.ILOAD, Opcodes.TABLESWITCH},
            {Opcodes.ICONST_1, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_2, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_3, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_0, Opcodes.ISTORE},
            {Opcodes.ILOAD, Opcodes.IRETURN},
    };
    int[][] expectedSwitchCounts = new int[][]{
        {4},
        {},
        {},
        {},
        {},
        {},
    };
    
    // Verify the shape of the blocks.
    boolean didMatch = compareBlocks(expectedHashCodeBlocks, hashCodeBlocks);
    Assert.assertTrue(didMatch);
    
    // Verify the switch option value.
    didMatch = compareSwitches(expectedSwitchCounts, hashCodeBlocks);
    Assert.assertTrue(didMatch);
}
 

@Test
public void test_checkLookupSwitch() throws Exception {
    List<BasicBlock> hashCodeBlocks = METHOD_BLOCKS.get("checkLookupSwitch(I)I");
    int[][] expectedHashCodeBlocks = new int[][]{
            {Opcodes.ICONST_5, Opcodes.ISTORE, Opcodes.ILOAD, Opcodes.LOOKUPSWITCH},
            {Opcodes.ICONST_1, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_2, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_3, Opcodes.ISTORE, Opcodes.GOTO},
            {Opcodes.ICONST_0, Opcodes.ISTORE},
            {Opcodes.ILOAD, Opcodes.IRETURN},
    };
    int[][] expectedSwitchCounts = new int[][]{
        {4},
        {},
        {},
        {},
        {},
        {},
    };
    
    // Verify the shape of the blocks.
    boolean didMatch = compareBlocks(expectedHashCodeBlocks, hashCodeBlocks);
    Assert.assertTrue(didMatch);
    
    // Verify the switch option value.
    didMatch = compareSwitches(expectedSwitchCounts, hashCodeBlocks);
    Assert.assertTrue(didMatch);
}
 
源代码16 项目: pitest   文件: AbstractCRCRVisitor.java

void translateToByteCode(final Integer constant) {
    switch (constant) {
        case -1:
            super.visitInsn(Opcodes.ICONST_M1);
            break;
        case 0:
            super.visitInsn(Opcodes.ICONST_0);
            break;
        case 1:
            super.visitInsn(Opcodes.ICONST_1);
            break;
        case 2:
            super.visitInsn(Opcodes.ICONST_2);
            break;
        case 3:
            super.visitInsn(Opcodes.ICONST_3);
            break;
        case 4:
            super.visitInsn(Opcodes.ICONST_4);
            break;
        case 5:
            super.visitInsn(Opcodes.ICONST_5);
            break;
        default:
            super.visitLdcInsn(constant);
            break;
    }
}
 
源代码17 项目: pitest   文件: InlineConstantMutator.java

/**
 * Translates the opcode to a number (inline constant) if possible or
 * returns <code>null</code> if the opcode cannot be translated.
 *
 * @param opcode
 *          that might represent an inline constant.
 * @return the value of the inline constant represented by opcode or
 *         <code>null</code> if the opcode does not represent a
 *         number/constant.
 */
private Number translateToNumber(final int opcode) {
  switch (opcode) {
  case Opcodes.ICONST_M1:
    return Integer.valueOf(-1);
  case Opcodes.ICONST_0:
    return Integer.valueOf(0);
  case Opcodes.ICONST_1:
    return Integer.valueOf(1);
  case Opcodes.ICONST_2:
    return Integer.valueOf(2);
  case Opcodes.ICONST_3:
    return Integer.valueOf(3);
  case Opcodes.ICONST_4:
    return Integer.valueOf(4);
  case Opcodes.ICONST_5:
    return Integer.valueOf(5);
  case Opcodes.LCONST_0:
    return Long.valueOf(0L);
  case Opcodes.LCONST_1:
    return Long.valueOf(1L);
  case Opcodes.FCONST_0:
    return Float.valueOf(0F);
  case Opcodes.FCONST_1:
    return Float.valueOf(1F);
  case Opcodes.FCONST_2:
    return Float.valueOf(2F);
  case Opcodes.DCONST_0:
    return Double.valueOf(0D);
  case Opcodes.DCONST_1:
    return Double.valueOf(1D);
  default:
    return null;
  }
}
 

private List<AbstractInsnNode> getPossibleInsns4(AbstractInsnNode ain)
{
	List<AbstractInsnNode> instrs = new ArrayList<>();
	while(ain != null)
	{
		if(ain instanceof LineNumberNode || ain instanceof FrameNode)
		{
			ain = ain.getNext();
			continue;
		}
		instrs.add(ain);
		if(instrs.size() >= 11)
			break;
		ain = ain.getNext();
	}
	if(instrs.size() == 11 && instrs.get(0).getOpcode() == Opcodes.ILOAD
		&& instrs.get(1).getOpcode() == Opcodes.ICONST_1
		&& instrs.get(2).getOpcode() == Opcodes.ISUB
		&& instrs.get(3).getOpcode() == Opcodes.ISTORE)
	{
		int var1 = ((VarInsnNode)instrs.get(0)).var;
		int var2 = ((VarInsnNode)instrs.get(3)).var;
		if(instrs.get(4).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(4)).var == var1
			&& instrs.get(5).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(5)).var == var2
			&& instrs.get(6).getOpcode() == Opcodes.IMUL
			&& instrs.get(7).getOpcode() == Opcodes.ISTORE
			&& ((VarInsnNode)instrs.get(7)).var == var2
			&& instrs.get(8).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(8)).var == var2
			&& instrs.get(9).getOpcode() == Opcodes.ICONST_2
			&& instrs.get(10).getOpcode() == Opcodes.IREM)
		return instrs;
	}
	return null;
}
 
源代码19 项目: bazel   文件: LambdaDesugaring.java

/**
 * Returns whether a given instruction can be used to push argument of {@code type} on stack.
 */
private /* static */ boolean isPushForType(AbstractInsnNode insn, Type type) {
  int opcode = insn.getOpcode();
  if (opcode == type.getOpcode(Opcodes.ILOAD)) {
    return true;
  }
  // b/62060793: AsyncAwait rewrites bytecode to convert java methods into state machine with
  // support of lambdas. Constant zero values are pushed on stack for all yet uninitialized
  // local variables. And SIPUSH instruction is used to advance an internal state of a state
  // machine.
  switch (type.getSort()) {
    case Type.BOOLEAN:
      return opcode == Opcodes.ICONST_0 || opcode == Opcodes.ICONST_1;

    case Type.BYTE:
    case Type.CHAR:
    case Type.SHORT:
    case Type.INT:
      return opcode == Opcodes.SIPUSH
          || opcode == Opcodes.ICONST_0
          || opcode == Opcodes.ICONST_1
          || opcode == Opcodes.ICONST_2
          || opcode == Opcodes.ICONST_3
          || opcode == Opcodes.ICONST_4
          || opcode == Opcodes.ICONST_5
          || opcode == Opcodes.ICONST_M1;

    case Type.LONG:
      return opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1;

    case Type.FLOAT:
      return opcode == Opcodes.FCONST_0
          || opcode == Opcodes.FCONST_1
          || opcode == Opcodes.FCONST_2;

    case Type.DOUBLE:
      return opcode == Opcodes.DCONST_0 || opcode == Opcodes.DCONST_1;

    case Type.OBJECT:
    case Type.ARRAY:
      return opcode == Opcodes.ACONST_NULL;

    default:
      // Support for BIPUSH and LDC* opcodes is not implemented as there is no known use case.
      return false;
  }
}
 

private List<AbstractInsnNode> getPossibleInsns2(AbstractInsnNode ain)
{
	List<AbstractInsnNode> instrs = new ArrayList<>();
	while(ain != null)
	{
		if(ain instanceof LineNumberNode || ain instanceof FrameNode)
		{
			ain = ain.getNext();
			continue;
		}
		instrs.add(ain);
		if(instrs.size() >= 14)
			break;
		ain = ain.getNext();
	}
	if(instrs.size() == 14 && instrs.get(0).getOpcode() == Opcodes.ILOAD
		&& instrs.get(1).getOpcode() == Opcodes.ICONST_1
		&& instrs.get(2).getOpcode() == Opcodes.ISUB
		&& instrs.get(3).getOpcode() == Opcodes.ISTORE)
	{
		int var1 = ((VarInsnNode)instrs.get(0)).var;
		int var2 = ((VarInsnNode)instrs.get(3)).var;
		if(instrs.get(4).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(4)).var == var1
			&& instrs.get(5).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(5)).var == var2
			&& instrs.get(6).getOpcode() == Opcodes.IMUL
			&& instrs.get(7).getOpcode() == Opcodes.ISTORE
			&& ((VarInsnNode)instrs.get(7)).var == var2
			&& instrs.get(8).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(8)).var == var2
			&& instrs.get(9).getOpcode() == Opcodes.ICONST_2
			&& instrs.get(10).getOpcode() == Opcodes.IREM
			&& instrs.get(11).getOpcode() == Opcodes.ISTORE
			&& ((VarInsnNode)instrs.get(11)).var == var2
			&& instrs.get(12).getOpcode() == Opcodes.ILOAD
			&& ((VarInsnNode)instrs.get(12)).var == var2
			&& instrs.get(13).getOpcode() == Opcodes.IADD)
		return instrs;
	}
	return null;
}
 
 方法所在类
 同类方法