Java Code Examples for org.objectweb.asm.Opcodes#IMUL

The following examples show how to use org.objectweb.asm.Opcodes#IMUL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UselessArithmeticTransformer.java    From deobfuscator with Apache License 2.0 6 votes vote down vote up
private List<AbstractInsnNode> getPossibleInsns3(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() >= 7)
			break;
		ain = ain.getNext();
	}
	if(instrs.size() == 7 && instrs.get(0).getOpcode() == Opcodes.ILOAD
		&& instrs.get(1).getOpcode() == Opcodes.ILOAD
		&& instrs.get(2).getOpcode() == Opcodes.ICONST_1
		&& instrs.get(3).getOpcode() == Opcodes.ISUB
		&& instrs.get(4).getOpcode() == Opcodes.IMUL
		&& instrs.get(5).getOpcode() == Opcodes.ICONST_2
		&& instrs.get(6).getOpcode() == Opcodes.IREM)
		return instrs;
	return null;
}
 
Example 2
Source File: InstructionAssembler.java    From es6draft with MIT License 6 votes vote down vote up
public final void mul(Type type) {
    switch (type.getOpcode(Opcodes.IMUL)) {
    case Opcodes.IMUL:
        imul();
        return;
    case Opcodes.LMUL:
        lmul();
        return;
    case Opcodes.FMUL:
        fmul();
        return;
    case Opcodes.DMUL:
        dmul();
        return;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 3
Source File: UselessArithmeticTransformer.java    From deobfuscator with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: CompilerUtils.java    From jphp with Apache License 2.0 5 votes vote down vote up
public static int getOperatorOpcode(OperatorExprToken operator, StackItem.Type type){
    if (operator instanceof PlusExprToken){
        switch (type){
            case DOUBLE: return Opcodes.DADD;
            case FLOAT: return Opcodes.FADD;
            case LONG: return Opcodes.LADD;
            case BYTE:
            case SHORT:
            case INT: return Opcodes.IADD;
        }
    }

    if (operator instanceof MinusExprToken){
        switch (type){
            case DOUBLE: return Opcodes.DSUB;
            case FLOAT: return Opcodes.FSUB;
            case LONG: return Opcodes.LSUB;
            case BYTE:
            case SHORT:
            case INT: return Opcodes.ISUB;
        }
    }

    if (operator instanceof MulExprToken){
        switch (type){
            case DOUBLE: return Opcodes.DMUL;
            case FLOAT: return Opcodes.FMUL;
            case LONG: return Opcodes.LMUL;
            case BYTE:
            case SHORT:
            case INT: return Opcodes.IMUL;
        }
    }

    throw new IllegalArgumentException("Unknown operator " + operator.getWord() + " for type " + type.name());
}
 
Example 5
Source File: UselessArithmeticTransformer.java    From deobfuscator with Apache License 2.0 4 votes vote down vote up
private List<AbstractInsnNode> getPossibleInsns(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() >= 23)
			break;
		ain = ain.getNext();
	}
	if(instrs.size() == 23 && 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.I2L
			&& instrs.get(14).getOpcode() == Opcodes.ICONST_0
			&& instrs.get(15).getOpcode() == Opcodes.I2L
			&& instrs.get(16).getOpcode() == Opcodes.LCMP
			&& instrs.get(17).getOpcode() == Opcodes.ICONST_1
			&& instrs.get(18).getOpcode() == Opcodes.IXOR
			&& instrs.get(19).getOpcode() == Opcodes.ICONST_1
			&& instrs.get(20).getOpcode() == Opcodes.IAND
			&& instrs.get(21).getOpcode() == Opcodes.IFEQ
			&& instrs.get(22).getOpcode() == Opcodes.IINC)
			return instrs;
	}
	return null;
}
 
Example 6
Source File: UselessArithmeticTransformer.java    From deobfuscator with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 7
Source File: AllocationMethodAdapter.java    From allocation-instrumenter with Apache License 2.0 4 votes vote down vote up
private void pushProductOfIntArrayOnStack() {
  Label beginScopeLabel = new Label();
  Label endScopeLabel = new Label();

  int dimsArrayIndex = newLocal("[I", beginScopeLabel, endScopeLabel);
  int counterIndex = newLocal("I", beginScopeLabel, endScopeLabel);
  int productIndex = newLocal("I", beginScopeLabel, endScopeLabel);
  Label loopLabel = new Label();
  Label endLabel = new Label();

  super.visitLabel(beginScopeLabel);

  // stack: ... intArray
  super.visitVarInsn(Opcodes.ASTORE, dimsArrayIndex);
  // -> stack: ...

  // counter = 0
  super.visitInsn(Opcodes.ICONST_0);
  super.visitVarInsn(Opcodes.ISTORE, counterIndex);
  // product = 1
  super.visitInsn(Opcodes.ICONST_1);
  super.visitVarInsn(Opcodes.ISTORE, productIndex);
  // loop:
  super.visitLabel(loopLabel);
  // if index >= arraylength goto end:
  super.visitVarInsn(Opcodes.ILOAD, counterIndex);
  super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
  super.visitInsn(Opcodes.ARRAYLENGTH);
  super.visitJumpInsn(Opcodes.IF_ICMPGE, endLabel);
  // product = product * max(array[counter],1)
  super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
  super.visitVarInsn(Opcodes.ILOAD, counterIndex);
  super.visitInsn(Opcodes.IALOAD);
  super.visitInsn(Opcodes.DUP);
  Label nonZeroDimension = new Label();
  super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension);
  super.visitInsn(Opcodes.POP);
  super.visitInsn(Opcodes.ICONST_1);
  super.visitLabel(nonZeroDimension);
  super.visitVarInsn(Opcodes.ILOAD, productIndex);
  super.visitInsn(Opcodes.IMUL); // if overflow happens it happens.
  super.visitVarInsn(Opcodes.ISTORE, productIndex);
  // iinc counter 1
  super.visitIincInsn(counterIndex, 1);
  // goto loop
  super.visitJumpInsn(Opcodes.GOTO, loopLabel);
  // end:
  super.visitLabel(endLabel);
  // re-push dimensions array
  super.visitVarInsn(Opcodes.ALOAD, dimsArrayIndex);
  // push product
  super.visitVarInsn(Opcodes.ILOAD, productIndex);

  super.visitLabel(endScopeLabel);
}
 
Example 8
Source File: AllocationMethodAdapter.java    From allocation-instrumenter with Apache License 2.0 4 votes vote down vote up
void calculateArrayLengthAndDispatch(String typeName, int dimCount) {
  // Since the dimensions of the array are not known at instrumentation
  // time, we take the created multi-dimensional array and peel off nesting
  // levels from the left.  For each nesting layer we probe the array length
  // and accumulate a partial product which we can then feed the recording
  // function.

  // below we note the partial product of dimensions 1 to X-1 as productToX
  // (so productTo1 == 1 == no dimensions yet).  We denote by aref0 the
  // array reference at the current nesting level (the containing aref's [0]
  // element).  If we hit a level whose arraylength is 0 or whose
  // reference is null, there's no point continuing, so we shortcut
  // out.

  // This approach works pretty well when you create a new array with the
  // newarray bytecodes.  You can also create a new array by cloning an
  // existing array; an existing multidimensional array might have had some
  // of its [0] elements nulled out.  We currently deal with this by bailing
  // out, but arguably we should do something more principled (like calculate
  // the size of the multidimensional array from scratch if you are using
  // clone()).
  // TODO(java-platform-team): Do something about modified multidimensional
  // arrays and clone().
  Label zeroDimension = new Label();
  super.visitInsn(Opcodes.DUP); // -> stack: ... origaref aref0
  super.visitLdcInsn(1); // -> stack: ... origaref aref0 productTo1
  for (int i = 0; i < dimCount; ++i) {
    // pre: stack: ... origaref aref0 productToI
    super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref productToI aref
    super.visitInsn(Opcodes.DUP);

    Label nonNullDimension = new Label();
    // -> stack: ... origaref productToI aref aref
    super.visitJumpInsn(Opcodes.IFNONNULL, nonNullDimension);
    // -> stack: ... origaref productToI aref
    super.visitInsn(Opcodes.SWAP);
    // -> stack: ... origaref aref productToI
    super.visitJumpInsn(Opcodes.GOTO, zeroDimension);
    super.visitLabel(nonNullDimension);

    // -> stack: ... origaref productToI aref
    super.visitInsn(Opcodes.DUP_X1);
    // -> stack: ... origaref aref0 productToI aref
    super.visitInsn(Opcodes.ARRAYLENGTH);
    // -> stack: ... origaref aref0 productToI dimI

    Label nonZeroDimension = new Label();
    super.visitInsn(Opcodes.DUP);
    // -> stack: ... origaref aref0 productToI dimI dimI
    super.visitJumpInsn(Opcodes.IFNE, nonZeroDimension);
    // -> stack: ... origaref aref0 productToI dimI
    super.visitInsn(Opcodes.POP);
    // -> stack: ... origaref aref0 productToI
    super.visitJumpInsn(Opcodes.GOTO, zeroDimension);
    super.visitLabel(nonZeroDimension);
    // -> stack: ... origaref aref0 productToI max(dimI,1)

    super.visitInsn(Opcodes.IMUL);
    // -> stack: ... origaref aref0 productTo{I+1}
    if (i < dimCount - 1) {
      super.visitInsn(Opcodes.SWAP);
      // -> stack: ... origaref productTo{I+1} aref0
      super.visitInsn(Opcodes.ICONST_0);
      // -> stack: ... origaref productTo{I+1} aref0 0
      super.visitInsn(Opcodes.AALOAD);
      // -> stack: ... origaref productTo{I+1} aref0'
      super.visitInsn(Opcodes.SWAP);
    }
    // post: stack: ... origaref aref0 productTo{I+1}
  }
  super.visitLabel(zeroDimension);

  super.visitInsn(Opcodes.SWAP); // -> stack: ... origaref product aref0
  super.visitInsn(Opcodes.POP); // -> stack: ... origaref product
  super.visitInsn(Opcodes.SWAP); // -> stack: ... product origaref
  invokeRecordAllocation(typeName);
}
 
Example 9
Source File: BytecodeUtils.java    From turin-programming-language with Apache License 2.0 4 votes vote down vote up
public static MathOperationBS createMathOperation(JvmTypeCategory operandsType, MathOperation.Operator operator) {
    int opcode;
    switch (operator) {
        case MULTIPLICATION:
            switch (operandsType) {
                case INT:
                    opcode = Opcodes.IMUL;
                    break;
                case LONG:
                    opcode = Opcodes.LMUL;
                    break;
                case FLOAT:
                    opcode = Opcodes.FMUL;
                    break;
                case DOUBLE:
                    opcode = Opcodes.DMUL;
                    break;
                default:
                    throw new UnsupportedOperationException(operator + " " +operandsType.name());
            }
            break;
        case SUM:
            switch (operandsType) {
                case INT:
                    opcode = Opcodes.IADD;
                    break;
                case LONG:
                    opcode = Opcodes.LADD;
                    break;
                case FLOAT:
                    opcode = Opcodes.FADD;
                    break;
                case DOUBLE:
                    opcode = Opcodes.DADD;
                    break;
                default:
                    throw new UnsupportedOperationException(operator + " " +operandsType.name());
            }
            break;
        case SUBTRACTION:
            switch (operandsType) {
                case INT:
                    opcode = Opcodes.ISUB;
                    break;
                case LONG:
                    opcode = Opcodes.LSUB;
                    break;
                case FLOAT:
                    opcode = Opcodes.FSUB;
                    break;
                case DOUBLE:
                    opcode = Opcodes.DSUB;
                    break;
                default:
                    throw new UnsupportedOperationException(operator + " " +operandsType.name());
            }
            break;
        case DIVISION:
            switch (operandsType) {
                case INT:
                    opcode = Opcodes.IDIV;
                    break;
                case LONG:
                    opcode = Opcodes.LDIV;
                    break;
                case FLOAT:
                    opcode = Opcodes.FDIV;
                    break;
                case DOUBLE:
                    opcode = Opcodes.DDIV;
                    break;
                default:
                    throw new UnsupportedOperationException(operator + " " +operandsType.name());
            }
            break;
        default:
            throw new UnsupportedOperationException(operator.name());
    }
    return new MathOperationBS(opcode);
}
 
Example 10
Source File: ArithmeticExpression.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isBinaryOp(Instruction instr) {
    switch (instr.getOpcode()) {
        case Opcodes.ISHL:
        case Opcodes.ISHR:
        case Opcodes.LSHL:
        case Opcodes.LSHR:
        case Opcodes.IUSHR:
        case Opcodes.LUSHR:
        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
        case Opcodes.LCMP:
        case Opcodes.IOR:
        case Opcodes.LOR:
        case Opcodes.IXOR:
        case Opcodes.LXOR:
        case Opcodes.IAND:
        case Opcodes.LAND:
        case Opcodes.FADD:
        case Opcodes.DADD:
        case Opcodes.IADD:
        case Opcodes.LADD:
        case Opcodes.FSUB:
        case Opcodes.DSUB:
        case Opcodes.ISUB:
        case Opcodes.LSUB:
        case Opcodes.FDIV:
        case Opcodes.DDIV:
        case Opcodes.LDIV:
        case Opcodes.IDIV:
        case Opcodes.IREM:
        case Opcodes.FREM:
        case Opcodes.DREM:
        case Opcodes.LREM:
        case Opcodes.FMUL:
        case Opcodes.DMUL:
        case Opcodes.IMUL:
        case Opcodes.LMUL:
            return true;
    }
    return false;
}
 
Example 11
Source File: ArithmeticExpression.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isArithmeticOp(Instruction instr) {
    
    switch (instr.getOpcode()) {
        case Opcodes.ISHL:
        case Opcodes.ISHR:
        case Opcodes.LSHL:
        case Opcodes.LSHR:
        case Opcodes.IUSHR:
        case Opcodes.LUSHR:
        
        case Opcodes.DCMPG:
        case Opcodes.DCMPL:
        case Opcodes.FCMPG:
        case Opcodes.FCMPL:
        case Opcodes.LCMP:
        case Opcodes.FNEG:
        case Opcodes.DNEG:
        case Opcodes.INEG:
        case Opcodes.D2F:
        case Opcodes.D2I:
        case Opcodes.D2L:
        case Opcodes.F2D:
        case Opcodes.F2I:
        case Opcodes.F2L:
        case Opcodes.L2D:
        case Opcodes.L2F:
        case Opcodes.L2I:
        case Opcodes.I2L:
        case Opcodes.I2B:
        case Opcodes.I2C:
        case Opcodes.I2D:
        case Opcodes.I2F:
        case Opcodes.I2S:
        case Opcodes.IOR:
        case Opcodes.LOR:
        case Opcodes.IXOR:
        case Opcodes.LXOR:
        case Opcodes.IAND:
        case Opcodes.LAND:
        case Opcodes.FADD:
        case Opcodes.DADD:
        case Opcodes.IADD:
        case Opcodes.LADD:
        case Opcodes.FSUB:
        case Opcodes.DSUB:
        case Opcodes.ISUB:
        case Opcodes.LSUB:
        case Opcodes.FDIV:
        case Opcodes.DDIV:
        case Opcodes.LDIV:
        case Opcodes.IDIV:
        case Opcodes.IREM:
        case Opcodes.FREM:
        case Opcodes.DREM:
        case Opcodes.LREM:
        case Opcodes.FMUL:
        case Opcodes.DMUL:
        case Opcodes.IMUL:
        case Opcodes.LMUL:
            return true;
    }
    return false;
}
 
Example 12
Source File: AOD1Mutator.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
public void visitInsn(int opcode) {
    switch (opcode) {
        case Opcodes.IADD:
        case Opcodes.ISUB:
        case Opcodes.IMUL:
        case Opcodes.IDIV:
        case Opcodes.IREM:
            if (this.shouldMutate("integer"))  {
                mv.visitInsn(Opcodes.POP);
            } else  {
                mv.visitInsn(opcode);
            }
            break;
        case Opcodes.FADD:
        case Opcodes.FSUB:
        case Opcodes.FMUL:
        case Opcodes.FDIV:
        case Opcodes.FREM:
            if (this.shouldMutate("float"))  {
                mv.visitInsn(Opcodes.POP);
            } else  {
                mv.visitInsn(opcode);
            }
            break;
        case Opcodes.LADD:
        case Opcodes.LSUB:
        case Opcodes.LMUL:
        case Opcodes.LDIV:
        case Opcodes.LREM:
            if (this.shouldMutate("long"))  {
                mv.visitInsn(Opcodes.POP2);
            } else  {
                mv.visitInsn(opcode);
            }
            break;
        case Opcodes.DADD:
        case Opcodes.DSUB:
        case Opcodes.DMUL:
        case Opcodes.DDIV:
        case Opcodes.DREM:
            if (this.shouldMutate("double"))  {
                mv.visitInsn(Opcodes.POP2);
            } else  {
                mv.visitInsn(opcode);
            }
            break;
        default:
            mv.visitInsn(opcode);
            break;
    }
}