Java Code Examples for org.objectweb.asm.Opcodes

The following are top voted examples for showing how to use org.objectweb.asm.Opcodes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: QDrill   File: InstructionModifier.java   Source Code and License 6 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  ReplacingBasicValue v;
  if (opcode == Opcodes.ASTORE && (v = peekFromTop(0)) != null) {
    final ValueHolderSub from = oldToNew.get(v.getIndex());

    final ReplacingBasicValue current = getLocal(var);
    // if local var is set, then transfer to it to the existing holders in the local position.
    if (current != null) {
      final ValueHolderSub newSub = oldToNew.get(current.getIndex());
      if (newSub.iden() == from.iden()) {
        final int targetFirst = newSub.first();
        from.transfer(this, targetFirst);
        return;
      }
    }

    // if local var is not set, then check map to see if existing holders are mapped to local var.
    if (oldLocalToFirst.containsKey(var)) {
      final ValueHolderSub sub = oldToNew.get(oldLocalToFirst.lget());
      if (sub.iden() == from.iden()) {
        // if they are, then transfer to that.
        from.transfer(this, sub.first());
        return;
      }
    }

    // map from variables to global space for future use.
    oldLocalToFirst.put(var, v.getIndex());
    return;
  } else if (opcode == Opcodes.ALOAD && (v = getLocal(var)) != null) {
    /*
     * Not forwarding this removes a now unnecessary ALOAD for a holder. The required LOAD/STORE
     * sequences will be generated by the ASTORE code above.
     */
    return;
  }

  super.visitVarInsn(opcode, var);
}
 
Example 2
Project: DirectLeaks-AntiReleak-Remover   File: InstructionAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void visitFieldInsn(final int opcode, final String owner,
        final String name, final String desc) {
    switch (opcode) {
    case Opcodes.GETSTATIC:
        getstatic(owner, name, desc);
        break;
    case Opcodes.PUTSTATIC:
        putstatic(owner, name, desc);
        break;
    case Opcodes.GETFIELD:
        getfield(owner, name, desc);
        break;
    case Opcodes.PUTFIELD:
        putfield(owner, name, desc);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 3
Project: MeziLang   File: ASTCompileVisitor.java   Source Code and License 6 votes vote down vote up
private void throw_compilation(ASTJumpExpr node) throws CompileException {
  TContextFunc func_context = getClosestFunContext();
  MethodVisitor mv = func_context.getMethodVisitor();

  switch (node.jjtGetNumChildren()) {
  case 1:
    Reduction reduce = this.popReduction();
    Debug.assertion(reduce != null, "Invalid Popped Reduction");
    Debug.assertion(reduce.isContainer(), "Invalid Popped Reduction " + reduce);
    Container throw_cont = (Container) reduce;
    Debug.assertion(throw_cont.isTypeInitialized(), "Throw Type is not initialized in the function signature");

    LOG.debug("CONT TYPE:" + throw_cont.getType());
    Debug.assertion(!throw_cont.isForm(Container.FORM_TYPE), "throw_cont should not be type container");

    LOG.debug("ATHROW");
    mv.visitInsn(Opcodes.ATHROW);
    break;

  default:
    throw new CompileException("Invalid Throw Expression child");
  }

  pushReduction(new Control(Control.FORM_THROW));
}
 
Example 4
Project: MeziLang   File: OpInt.java   Source Code and License 6 votes vote down vote up
@Override
public Container smaller(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {

  Label greater_equal_label = new Label();
  Label end_label = new Label();

  opinfo.mv.visitJumpInsn(Opcodes.IF_ICMPGE, greater_equal_label);
  opinfo.mv.visitInsn(Opcodes.ICONST_1);
  opinfo.mv.visitJumpInsn(Opcodes.GOTO, end_label);
  opinfo.mv.visitLabel(greater_equal_label);
  opinfo.mv.visitInsn(Opcodes.ICONST_0);
  opinfo.mv.visitLabel(end_label);

  Container anony_bool = new Container("anonymous", Container.FORM_OPSTACK_VAR, true, false);
  anony_bool.initializeType((AbsType) cpLoader.findClassFull(TPrimitiveClass.NAME_BOOL));
  anony_bool.setAssigned(true);

  return anony_bool;
}
 
Example 5
Project: GraphiteMappings   File: WorldMappings.java   Source Code and License 6 votes vote down vote up
@Override
protected void remap() {
    findNode(getObfType().getJvmStandard()).ifPresent((classNode -> classNode.methods.forEach((methodNode -> {
        if (methodNode.name.equals("<init>")) {
            methodNode.instructions.iterator().forEachRemaining((insnNode) -> {
                if (insnNode.getOpcode() == Opcodes.ANEWARRAY) {
                    if (insnNode instanceof TypeInsnNode) {
                        TypeInsnNode typeInsnNode = (TypeInsnNode) insnNode;
                        Type type = Type.getType(typeInsnNode.desc);
                        getMappings().putClass(type.getInternalName(), "net.minecraft.world" +
                                ".IWorldEventListener");
                    }
                }
            });
        }
    }))));
}
 
Example 6
Project: Rubus   File: MethodImporter.java   Source Code and License 6 votes vote down vote up
/**
 * Imports field instructions (put and get), both for static and instance
 * fields.
 *
 * @param opcode Opcode.
 * @param owner  Class containing the field.
 * @param name   Name of field.
 * @param desc   Type descriptor of field.
 */
@Override
public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) {
  Field f = ClassNode.getClass(owner).getField(name, desc);

  if(((opcode == Opcodes.GETSTATIC) || (opcode == Opcodes.PUTSTATIC)) !=
          f.getModifiers().contains(Modifier.STATIC)) {
    throw new RuntimeException("Field staticness conflicts with instruction");
  }

  switch(opcode) {
    // Loads
    case Opcodes.GETSTATIC:
    case Opcodes.GETFIELD:  createFieldRead(f);  break;
    // Stores
    case Opcodes.PUTSTATIC:
    case Opcodes.PUTFIELD:  createFieldWrite(f); break;
  }
}
 
Example 7
Project: shrinker   File: PredicateClassVisitor.java   Source Code and License 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
                                 String signature, String[] exceptions) {
    if (attemptToVisitR) return null;
    return new MethodVisitor(Opcodes.ASM5, null) {

        @Override
        public void visitFieldInsn(int opcode, String owner, String fieldName,
                                   String fieldDesc) {

            if (attemptToVisitR
                    || opcode != Opcodes.GETSTATIC
                    || owner.startsWith("java/lang/")) {
                return;
            }

            attemptToVisitR = isRClass(owner);
        }
    };
}
 
Example 8
Project: Simple-JAR-Watermark   File: FrameNode.java   Source Code and License 6 votes vote down vote up
/**
 * Makes the given visitor visit this stack map frame.
 * 
 * @param mv
 *            a method visitor.
 */
@Override
public void accept(final MethodVisitor mv) {
    switch (type) {
    case Opcodes.F_NEW:
    case Opcodes.F_FULL:
        mv.visitFrame(type, local.size(), asArray(local), stack.size(),
                asArray(stack));
        break;
    case Opcodes.F_APPEND:
        mv.visitFrame(type, local.size(), asArray(local), 0, null);
        break;
    case Opcodes.F_CHOP:
        mv.visitFrame(type, local.size(), null, 0, null);
        break;
    case Opcodes.F_SAME:
        mv.visitFrame(type, 0, null, 0, null);
        break;
    case Opcodes.F_SAME1:
        mv.visitFrame(type, 0, null, 1, asArray(stack));
        break;
    }
}
 
Example 9
Project: MeziLang   File: OpFloat.java   Source Code and License 5 votes vote down vote up
@Override
public Container minus_assign(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {
  Container anonyInt = lval.getOpStackClone("anonymous");
  //// Compiled Instruction
  LOG.info("FSUB");
  opinfo.mv.visitInsn(Opcodes.FSUB);

  do_assign_common(lval, anonyInt, opinfo);

  //// End
  return anonyInt;
}
 
Example 10
Project: Spigot-Attribute-Remover   File: AnalyzerAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitMethodInsn(final int opcode, final String owner,
        final String name, final String desc, final boolean itf) {
    if (api < Opcodes.ASM5) {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    doVisitMethodInsn(opcode, owner, name, desc, itf);
}
 
Example 11
Project: DirectLeaks-AntiReleak-Remover   File: RemappingMethodAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitMethodInsn(final int opcode, final String owner,
        final String name, final String desc, final boolean itf) {
    if (api < Opcodes.ASM5) {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    doVisitMethodInsn(opcode, owner, name, desc, itf);
}
 
Example 12
Project: Spigot-Attribute-Remover   File: RemappingMethodAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitMethodInsn(final int opcode, final String owner,
        final String name, final String desc, final boolean itf) {
    if (api < Opcodes.ASM5) {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    doVisitMethodInsn(opcode, owner, name, desc, itf);
}
 
Example 13
Project: Rubus   File: InstructionExporter.java   Source Code and License 5 votes vote down vote up
/**
 * Output instructions for allocating arrays, both for primitive and
 * reference types.
 *
 * @param instruction Array allocation instruction.
 * @return            <code>null</code>
 */
@Override
public Void visit(NewArray instruction) {
  if(instruction.getElementType().getSort() == Type.Sort.REF) {
    mv.visitTypeInsn(
      Opcodes.ANEWARRAY,
      instruction.getElementType().getInternalName()
    );
  } else {
    int type;

    switch(instruction.getElementType().getSort()) {
      case BOOL:   type = Opcodes.T_BOOLEAN; break;
      case CHAR:   type = Opcodes.T_CHAR;    break;
      case FLOAT:  type = Opcodes.T_FLOAT;   break;
      case DOUBLE: type = Opcodes.T_DOUBLE;  break;
      case BYTE:   type = Opcodes.T_BYTE;    break;
      case SHORT:  type = Opcodes.T_SHORT;   break;
      case INT:    type = Opcodes.T_INT;     break;
      case LONG:   type = Opcodes.T_LONG;    break;
      default: throw new RuntimeException("Unknown array element type");
    }

    mv.visitIntInsn(Opcodes.NEWARRAY, type);
  }

  return null;
}
 
Example 14
Project: anvil   File: XmasCalendarTransformer.java   Source Code and License 5 votes vote down vote up
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
	method.instructions.clear();
	method.localVariables.clear();
	method.tryCatchBlocks.clear();

	method.instructions.add(new InsnNode(Opcodes.ICONST_0));
	method.instructions.add(new InsnNode(Opcodes.IRETURN));

	// TODO adjust maxLocals and maxStack?
}
 
Example 15
Project: DirectLeaks-AntiReleak-Remover   File: InstructionAdapter.java   Source Code and License 5 votes vote down vote up
@Deprecated
public void invokevirtual(final String owner, final String name,
        final String desc) {
    if (api >= Opcodes.ASM5) {
        invokevirtual(owner, name, desc, false);
        return;
    }
    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, name, desc);
}
 
Example 16
Project: openrasp   File: JettyRequestHook.java   Source Code and License 5 votes vote down vote up
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("extractParameters".equals(name) || "extractContentParameters".equals(name)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onParseParameters", "()V"));
            }

        };
    }
    return mv;
}
 
Example 17
Project: MeziLang   File: OpInt.java   Source Code and License 5 votes vote down vote up
@Override
public Container minus(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {

  Container anonyInt = lval.getOpStackClone("anonymous");

  //// Compiled Instruction
  opinfo.mv.visitInsn(Opcodes.ISUB);
  LOG.info("ISUB");
  // subed result will be on the operand stack
  //// End

  return anonyInt;
}
 
Example 18
Project: MeziLang   File: OpBool.java   Source Code and License 5 votes vote down vote up
@Override
public void return_dummy_variable(OpInfo opinfo) throws CompileException {

  opinfo.mv.visitInsn(Opcodes.ICONST_1);
  LOG.info("ICONST_1 for boolean");

  opinfo.mv.visitInsn(Opcodes.IRETURN);
  LOG.info("IRETURN" + " for Boolean");
}
 
Example 19
Project: DirectLeaks-AntiReleak-Remover   File: GeneratorAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Generates the instruction to push the given value on the stack.
 * 
 * @param value
 *            the value to be pushed on the stack.
 */
public void push(final double value) {
    long bits = Double.doubleToLongBits(value);
    if (bits == 0L || bits == 0x3ff0000000000000L) { // +0.0d and 1.0d
        mv.visitInsn(Opcodes.DCONST_0 + (int) value);
    } else {
        mv.visitLdcInsn(value);
    }
}
 
Example 20
Project: elasticsearch_my   File: ESLoggerUsageChecker.java   Source Code and License 5 votes vote down vote up
@Override
public BasicValue ternaryOperation(AbstractInsnNode insnNode, BasicValue value1, BasicValue value2, BasicValue value3)
    throws AnalyzerException {
    if (insnNode.getOpcode() == Opcodes.AASTORE && value1 instanceof ArraySizeBasicValue) {
        return value1;
    }
    return super.ternaryOperation(insnNode, value1, value2, value3);
}
 
Example 21
Project: elasticsearch_my   File: SSubEachArray.java   Source Code and License 5 votes vote down vote up
@Override
void write(MethodWriter writer, Globals globals) {
    writer.writeStatementOffset(location);

    expression.write(writer, globals);
    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ISTORE), array.getSlot());
    writer.push(-1);
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ISTORE), index.getSlot());

    Label begin = new Label();
    Label end = new Label();

    writer.mark(begin);

    writer.visitIincInsn(index.getSlot(), 1);
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot());
    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot());
    writer.arrayLength();
    writer.ifICmp(MethodWriter.GE, end);

    writer.visitVarInsn(array.type.type.getOpcode(Opcodes.ILOAD), array.getSlot());
    writer.visitVarInsn(index.type.type.getOpcode(Opcodes.ILOAD), index.getSlot());
    writer.arrayLoad(indexed.type);
    writer.writeCast(cast);
    writer.visitVarInsn(variable.type.type.getOpcode(Opcodes.ISTORE), variable.getSlot());

    if (loopCounter != null) {
        writer.writeLoopCounter(loopCounter.getSlot(), statementCount, location);
    }

    block.continu = begin;
    block.brake = end;
    block.write(writer, globals);

    writer.goTo(begin);
    writer.mark(end);
}
 
Example 22
Project: Reer   File: AsmBackedClassGenerator.java   Source Code and License 5 votes vote down vote up
private void addGetter(String methodName, String methodDescriptor, MethodCodeBody body) throws Exception {
    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, methodName, methodDescriptor, null, EMPTY_STRINGS);
    methodVisitor.visitCode();
    body.add(methodVisitor);
    methodVisitor.visitInsn(Opcodes.ARETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
Example 23
Project: DirectLeaks-AntiReleak-Remover   File: AnalyzerAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitMethodInsn(final int opcode, final String owner,
        final String name, final String desc, final boolean itf) {
    if (api < Opcodes.ASM5) {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    doVisitMethodInsn(opcode, owner, name, desc, itf);
}
 
Example 24
Project: MeziLang   File: OpInt.java   Source Code and License 5 votes vote down vote up
@Override
public Container shfit_right(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {
  Container anonyInt = lval.getOpStackClone("anonymous");
  //// Compiled Instruction
  LOG.info("ISHR");
  opinfo.mv.visitInsn(Opcodes.ISHR);
  // subed result will be on the operand stack
  //// End
  return anonyInt;
}
 
Example 25
Project: fastAOP   File: SAXCodeAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitFrame(final int type, final int nLocal,
        final Object[] local, final int nStack, final Object[] stack) {
    AttributesImpl attrs = new AttributesImpl();
    switch (type) {
    case Opcodes.F_NEW:
    case Opcodes.F_FULL:
        if (type == Opcodes.F_NEW) {
            attrs.addAttribute("", "type", "type", "", "NEW");
        } else {
            attrs.addAttribute("", "type", "type", "", "FULL");
        }
        sa.addStart("frame", attrs);
        appendFrameTypes(true, nLocal, local);
        appendFrameTypes(false, nStack, stack);
        break;
    case Opcodes.F_APPEND:
        attrs.addAttribute("", "type", "type", "", "APPEND");
        sa.addStart("frame", attrs);
        appendFrameTypes(true, nLocal, local);
        break;
    case Opcodes.F_CHOP:
        attrs.addAttribute("", "type", "type", "", "CHOP");
        attrs.addAttribute("", "count", "count", "",
                Integer.toString(nLocal));
        sa.addStart("frame", attrs);
        break;
    case Opcodes.F_SAME:
        attrs.addAttribute("", "type", "type", "", "SAME");
        sa.addStart("frame", attrs);
        break;
    case Opcodes.F_SAME1:
        attrs.addAttribute("", "type", "type", "", "SAME1");
        sa.addStart("frame", attrs);
        appendFrameTypes(false, 1, stack);
        break;
    }
    sa.addEnd("frame");
}
 
Example 26
Project: MeziLang   File: OpInt.java   Source Code and License 5 votes vote down vote up
@Override
public Container multiply_assign(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {
  Container anonyInt = lval.getOpStackClone("anonymous");
  //// Compiled Instruction
  LOG.info("IMUL");
  opinfo.mv.visitInsn(Opcodes.IMUL);

  do_assign_common(lval, anonyInt, opinfo);

  //// End
  return anonyInt;
}
 
Example 27
Project: Aceso   File: IntSwitch.java   Source Code and License 5 votes vote down vote up
void writeMissingMessageWithHash(GeneratorAdapter mv, String visitedClassName) {
    mv.newInstance(INSTANT_RELOAD_EXCEPTION_TYPE);
    mv.dup();
    mv.push("int switch could not find %d in %s");
    mv.push(3);
    mv.newArray(OBJECT_TYPE);
    mv.dup();
    mv.push(0);
    visitInt();
    mv.visitMethodInsn(
            Opcodes.INVOKESTATIC,
            "java/lang/Integer",
            "valueOf",
            "(I)Ljava/lang/Integer;", false);
    mv.arrayStore(OBJECT_TYPE);
    mv.dup();
    mv.push(2);
    mv.push(visitedClassName);
    mv.arrayStore(OBJECT_TYPE);
    mv.visitMethodInsn(
            Opcodes.INVOKESTATIC,
            "java/lang/String",
            "format",
            "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);
    mv.invokeConstructor(INSTANT_RELOAD_EXCEPTION_TYPE,
            Method.getMethod("void <init> (String)"));
    mv.throwException();
}
 
Example 28
Project: EvoMaster   File: HeuristicsForJumpsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test_IFLE(){
    //val <= 0  implies !(-val < 0)

    int[] values = new int[]{-2345, -6, 0, 2, 7888};
    for(int val: values){

        Truthness le = getForSingleValueJump(val, Opcodes.IFLE);
        Truthness x = getForSingleValueJump(-val, Opcodes.IFLT).invert();

        //their values should be the same, as equivalent
        assertEquals(le.getOfTrue(), x.getOfTrue(), 0.001);
        assertEquals(le.getOfFalse(), x.getOfFalse(), 0.001);
    }
}
 
Example 29
Project: MeziLang   File: OpInt.java   Source Code and License 5 votes vote down vote up
@Override
public Container inclusive_or_assign(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {
  Container anonyInt = lval.getOpStackClone("anonymous");
  //// Compiled Instruction
  LOG.info("IOR");
  opinfo.mv.visitInsn(Opcodes.IOR);

  do_assign_common(lval, anonyInt, opinfo);

  //// End
  return anonyInt;
}
 
Example 30
Project: Spigot-Nonce-ID-Finder   File: MethodNode.java   Source Code and License 5 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name,
        String desc, boolean itf) {
    if (api < Opcodes.ASM5) {
        super.visitMethodInsn(opcode, owner, name, desc, itf);
        return;
    }
    instructions.add(new MethodInsnNode(opcode, owner, name, desc, itf));
}
 
Example 31
Project: MeziLang   File: OpLong.java   Source Code and License 5 votes vote down vote up
@Override
public void return_dummy_variable(OpInfo opinfo) throws CompileException {

  opinfo.mv.visitInsn(Opcodes.LCONST_1);
  LOG.info("LCONST_1 for Long");

  opinfo.mv.visitInsn(Opcodes.LRETURN);
  LOG.info("LRETURN" + " for Long");
}
 
Example 32
Project: elasticsearch_my   File: AStoreable.java   Source Code and License 5 votes vote down vote up
/**
 * Writes the opcodes to flip a negative array index (meaning slots from the end of the array) into a 0-based one (meaning slots from
 * the start of the array).
 */
static void writeIndexFlip(MethodWriter writer, Consumer<MethodWriter> writeGetLength) {
    Label noFlip = new Label();
    // Everywhere when it says 'array' below that could also be a list
    // The stack after each instruction:       array, unnormalized_index
    writer.dup();                           // array, unnormalized_index, unnormalized_index
    writer.ifZCmp(Opcodes.IFGE, noFlip);    // array, unnormalized_index
    writer.swap();                          // negative_index, array
    writer.dupX1();                         // array, negative_index, array
    writeGetLength.accept(writer);          // array, negative_index, length
    writer.visitInsn(Opcodes.IADD);         // array, noralized_index
    writer.mark(noFlip);                    // array, noralized_index
}
 
Example 33
Project: fastAOP   File: GeneratorAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Generates the instruction to push the given value on the stack.
 * 
 * @param value
 *            the value to be pushed on the stack.
 */
public void push(final double value) {
    long bits = Double.doubleToLongBits(value);
    if (bits == 0L || bits == 0x3ff0000000000000L) { // +0.0d and 1.0d
        mv.visitInsn(Opcodes.DCONST_0 + (int) value);
    } else {
        mv.visitLdcInsn(value);
    }
}
 
Example 34
Project: Aceso   File: IncrementalTool.java   Source Code and License 5 votes vote down vote up
public static int transformAccessForInstantRun(int access) {
    IncrementalVisitor.AccessRight accessRight = IncrementalVisitor.AccessRight.fromNodeAccess(access);
    if (accessRight != IncrementalVisitor.AccessRight.PRIVATE) {
        access &= ~Opcodes.ACC_PROTECTED;
        access &= ~Opcodes.ACC_PRIVATE;
        return access | Opcodes.ACC_PUBLIC;
    }
    return access;
}
 
Example 35
Project: Spigot-Attribute-Remover   File: AnalyzerAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public void visitInsn(final int opcode) {
    if (mv != null) {
        mv.visitInsn(opcode);
    }
    execute(opcode, 0, null);
    if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN)
            || opcode == Opcodes.ATHROW) {
        this.locals = null;
        this.stack = null;
    }
}
 
Example 36
Project: DirectLeaks-AntiReleak-Remover   File: GeneratorAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Generates the instruction to push the given value on the stack.
 * 
 * @param value
 *            the value to be pushed on the stack.
 */
public void push(final long value) {
    if (value == 0L || value == 1L) {
        mv.visitInsn(Opcodes.LCONST_0 + (int) value);
    } else {
        mv.visitLdcInsn(value);
    }
}
 
Example 37
Project: EvoMaster   File: HeuristicsForJumpsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test_IF_ICMPLT_pos_false(){
    // x < y
    int code = Opcodes.IF_ICMPLT;

    Truthness a = getForValueComparison(10, 6, code);
    assertFalse(a.isTrue());

    Truthness b = getForValueComparison(222, 5, code);
    assertFalse(b.isTrue());

    assertTrue(a.getOfTrue() > b.getOfTrue());
}
 
Example 38
Project: Spigot-Attribute-Remover   File: GeneratorAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Generates the instruction to create a new array.
 * 
 * @param type
 *            the type of the array elements.
 */
public void newArray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        typeInsn(Opcodes.ANEWARRAY, type);
        return;
    }
    mv.visitIntInsn(Opcodes.NEWARRAY, typ);
}
 
Example 39
Project: EvoMaster   File: HeuristicsForJumpsTest.java   Source Code and License 5 votes vote down vote up
@Test
public void test_IF_ICMPEQ_pos(){
    // x == y
    int code = Opcodes.IF_ICMPEQ;

    Truthness t = getForValueComparison(5, 5, code);
    assertTrue(t.isTrue());
    assertFalse(t.isFalse());
}
 
Example 40
Project: Spigot-Attribute-Remover   File: InstructionAdapter.java   Source Code and License 5 votes vote down vote up
public void lconst(final long cst) {
    if (cst == 0L || cst == 1L) {
        mv.visitInsn(Opcodes.LCONST_0 + (int) cst);
    } else {
        mv.visitLdcInsn(cst);
    }
}
 
Example 41
Project: dacapobench   File: AllocateInstrument.java   Source Code and License 5 votes vote down vote up
private boolean instrument() {
	if ((access & Opcodes.ACC_INTERFACE) != 0)
		return false;

	for (String k : excludePackages) {
		if (name.startsWith(k))
			return false;
	}

	return true;
}
 
Example 42
Project: MeziLang   File: OpLong.java   Source Code and License 5 votes vote down vote up
@Override
public Container plus_assign(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {
  Container anonyInt = lval.getOpStackClone("anonymous");

  //// Compiled Instruction
  LOG.info("LADD");
  opinfo.mv.visitInsn(Opcodes.LADD);

  do_assign_common(lval, anonyInt, opinfo);
  //// End
  return anonyInt;
}
 
Example 43
Project: fastAOP   File: FieldNode.java   Source Code and License 5 votes vote down vote up
/**
 * Checks that this field node is compatible with the given ASM API version.
 * This methods checks that this node, and all its nodes recursively, do not
 * contain elements that were introduced in more recent versions of the ASM
 * API than the given version.
 * 
 * @param api
 *            an ASM API version. Must be one of {@link Opcodes#ASM4} or
 *            {@link Opcodes#ASM5}.
 */
public void check(final int api) {
    if (api == Opcodes.ASM4) {
        if (visibleTypeAnnotations != null
                && visibleTypeAnnotations.size() > 0) {
            throw new RuntimeException();
        }
        if (invisibleTypeAnnotations != null
                && invisibleTypeAnnotations.size() > 0) {
            throw new RuntimeException();
        }
    }
}
 
Example 44
Project: dacapobench   File: AllocateInstrument.java   Source Code and License 5 votes vote down vote up
private void addInc() {
	if (constructor) {
		super.visitMethodInsn(Opcodes.INVOKESTATIC, name,
				LOG_INTERNAL_ALLOC_INC, VOID_SIGNATURE);
		methodStartLabel = super.mark();
	}
	firstInstruction = false;
}
 
Example 45
Project: MeziLang   File: OpDouble.java   Source Code and License 5 votes vote down vote up
@Override
public void return_dummy_variable(OpInfo opinfo) throws CompileException {

  opinfo.mv.visitInsn(Opcodes.DCONST_1);
  LOG.info("DCONST_1 for Double");

  opinfo.mv.visitInsn(Opcodes.DRETURN);
  LOG.info("DRETURN" + " for Double");
}
 
Example 46
Project: byte-cobweb   File: TreeInsn.java   Source Code and License 5 votes vote down vote up
static VarInsnNode getLoadInsn(Type type, int position) {
    int opCode;
    switch (type.getDescriptor().charAt(0)) {
        case 'B':
            opCode = Opcodes.ILOAD;
            break;
        case 'C':
            opCode = Opcodes.ILOAD;
            break;
        case 'D':
            opCode = Opcodes.DLOAD;
            break;
        case 'F':
            opCode = Opcodes.FLOAD;
            break;
        case 'I':
            opCode = Opcodes.ILOAD;
            break;
        case 'J':
            opCode = Opcodes.LLOAD;
            break;
        case 'L':
            opCode = Opcodes.ALOAD;
            break;
        case '[':
            opCode = Opcodes.ALOAD;
            break;
        case 'Z':
            opCode = Opcodes.ILOAD;
            break;
        case 'S':
            opCode = Opcodes.ILOAD;
            break;
        default:
            throw new ClassFormatError("Invalid method signature: "
                    + type.getDescriptor());
    }
    return new VarInsnNode(opCode, position);
}
 
Example 47
Project: Rubus   File: InstructionExporter.java   Source Code and License 5 votes vote down vote up
/**
 * Outputs exception <code>throw</code>ing instructions.
 *
 * @param instruction <code>throw</code> instruction.
 * @return            <code>null</code>.
 */
@Override
public Void visit(Throw instruction) {
  mv.visitInsn(Opcodes.ATHROW);

  return null;
}
 
Example 48
Project: Spigot-Attribute-Remover   File: InstructionAdapter.java   Source Code and License 5 votes vote down vote up
public void invokespecial(final String owner, final String name,
        final String desc, final boolean itf) {
    if (api < Opcodes.ASM5) {
        if (itf) {
            throw new IllegalArgumentException(
                    "INVOKESPECIAL on interfaces require ASM 5");
        }
        invokespecial(owner, name, desc);
        return;
    }
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, owner, name, desc, itf);
}
 
Example 49
Project: Spigot-Attribute-Remover   File: GeneratorAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * Generates the instruction to push the given value on the stack.
 * 
 * @param value
 *            the value to be pushed on the stack.
 */
public void push(final long value) {
    if (value == 0L || value == 1L) {
        mv.visitInsn(Opcodes.LCONST_0 + (int) value);
    } else {
        mv.visitLdcInsn(value);
    }
}
 
Example 50
Project: byte-cobweb   File: MethodModifier.java   Source Code and License 5 votes vote down vote up
/**
 * 组装被拦截方法在方法内throw时的拦截动作
 */
@SuppressWarnings("unchecked")
private static void asmMethodThrow(MethodModifierContext context) {
    InsnList il = context.mn.instructions;
    Iterator<AbstractInsnNode> it = il.iterator();
    while (it.hasNext()) {
        AbstractInsnNode abstractInsnNode = it.next();
        switch (abstractInsnNode.getOpcode()) {
            case Opcodes.ATHROW:
                il.insertBefore(abstractInsnNode, createThrowInstructions(context));
                break;
        }
    }

}
 
Example 51
Project: customstuff4   File: Mixin.java   Source Code and License 5 votes vote down vote up
private static boolean canMixinField(ClassNode node, FieldNode field)
{
    if (hasField(node, field.name))
        return false;
    if ((field.access & Opcodes.ACC_STATIC) != 0)
        return false;

    return true;
}
 
Example 52
Project: openjdk-jdk10   File: UntrustedInterfaces.java   Source Code and License 4 votes vote down vote up
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
    if (name.equals(POISON_IMPL_NAME)) {
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);

        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, POISON_IMPL_NAME.replace('.', '/'), null, Type.getInternalName(Pill.class), null);
        // constructor
        MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
        constructor.visitCode();
        constructor.visitVarInsn(Opcodes.ALOAD, 0);
        constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Pill.class), "<init>", "()V", false);
        constructor.visitInsn(Opcodes.RETURN);
        constructor.visitMaxs(0, 0);
        constructor.visitEnd();

        MethodVisitor setList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setField", "()V", null, null);
        setList.visitCode();
        setList.visitVarInsn(Opcodes.ALOAD, 0);
        setList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        setList.visitInsn(Opcodes.DUP);
        setList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        setList.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(Pill.class), "field", Type.getDescriptor(TestInterface.class));
        setList.visitInsn(Opcodes.RETURN);
        setList.visitMaxs(0, 0);
        setList.visitEnd();

        MethodVisitor setStaticList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setStaticField", "()V", null, null);
        setStaticList.visitCode();
        setStaticList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        setStaticList.visitInsn(Opcodes.DUP);
        setStaticList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        setStaticList.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(Pill.class), "staticField", Type.getDescriptor(TestInterface.class));
        setStaticList.visitInsn(Opcodes.RETURN);
        setStaticList.visitMaxs(0, 0);
        setStaticList.visitEnd();

        MethodVisitor callMe = cw.visitMethod(Opcodes.ACC_PUBLIC, "callMe", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(CallBack.class)), null, null);
        callMe.visitCode();
        callMe.visitVarInsn(Opcodes.ALOAD, 1);
        callMe.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        callMe.visitInsn(Opcodes.DUP);
        callMe.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        callMe.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(CallBack.class), "callBack", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(TestInterface.class)), true);
        callMe.visitInsn(Opcodes.IRETURN);
        callMe.visitMaxs(0, 0);
        callMe.visitEnd();

        MethodVisitor getList = cw.visitMethod(Opcodes.ACC_PUBLIC, "get", Type.getMethodDescriptor(Type.getType(TestInterface.class)), null, null);
        getList.visitCode();
        getList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
        getList.visitInsn(Opcodes.DUP);
        getList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
        getList.visitInsn(Opcodes.ARETURN);
        getList.visitMaxs(0, 0);
        getList.visitEnd();

        cw.visitEnd();

        byte[] bytes = cw.toByteArray();
        return defineClass(name, bytes, 0, bytes.length);
    }
    return super.findClass(name);
}
 
Example 53
Project: Spigot-Attribute-Remover   File: FieldRemapper.java   Source Code and License 4 votes vote down vote up
public FieldRemapper(final FieldVisitor fv, final Remapper remapper) {
    this(Opcodes.ASM5, fv, remapper);
}
 
Example 54
Project: MeziLang   File: ASTCompileVisitor.java   Source Code and License 4 votes vote down vote up
private void generateClosureContextCopyInst(TContext closure_ctx, OpInfo opinfo) throws CompileException {
  LOG.debug("generateClosureContextCopyInst");

  Debug.assertion(closure_ctx instanceof TContextClosure, "closure_ctx should be closure ctx");

  TContext parent_ctx = (TContext) closure_ctx.getOwnerType();
  Debug.assertion(parent_ctx != null, "parent_ctx should be valid");

  TContext owner_func_ctx = parent_ctx.getClosestAncestor(AbsType.FORM_FUNC);
  Debug.assertion(owner_func_ctx != null, "owner func_ctx should be valid");

  Container var_cont = null;
  AbsType var_type = null;

  LinkedList<Container> var_list = closure_ctx.get_childvar_list();
  int var_size = var_list.size();
  Container closure_member_var = null;

  this.dump_reduction_stack();

  for (int i = 0; i < var_size; i++) {
    closure_member_var = var_list.get(i);
    var_cont = closure_member_var.getClosureOrgFuncvarContainer();

    Debug.assertion(var_cont != null, "var_cont should be valid");
    Debug.assertion(var_cont.isTypeInitialized(), "var_cont type should be initialized");

    if (var_cont.isForm(Container.FORM_FUNSTACK_VAR)) {
      if (var_cont.isAssigned()) {
        LOG.debug(" Add Copy Instruction (" + var_cont.getContextVarIdx() + ") " + var_cont);

        var_type = var_cont.getType();
        opinfo.mv.visitInsn(DUP); // duplicate closure class instances
                                  // (category 1)
        var_cont.op().load_funcstack_variable(var_cont, opinfo, var_cont.getContextVarIdx());
        closure_member_var.op().assign(closure_member_var, var_cont, opinfo);
      }
    } else if (var_cont.isForm(Container.FORM_OBJMEMBER_VAR)) { // for nested
                                                                // closure
                                                                // case

      LOG.debug(" Add Copy Instruction (" + var_cont.getContextVarIdx() + ") " + var_cont);

      var_type = var_cont.getType();

      opinfo.mv.visitInsn(DUP); // duplicate closure class instances (category
                                // 1)

      Container owner_cont = var_cont.getOwnerContainer();
      Debug.assertion(owner_cont != null, "owner_cont should be valid");
      Debug.assertion(owner_cont.isTypeInitialized(), "owner_cont should be type initialized");
      AbsType owner_type = owner_cont.getType();

      opinfo.mv.visitVarInsn(Opcodes.ALOAD, 0); // load closure variable(for
                                                // loading closure member var)

      LOG.info("GETFIELD {}:{}({})", owner_type.getName(), var_cont.getName(), var_type.getMthdDscStr());
      opinfo.mv.visitFieldInsn(Opcodes.GETFIELD, owner_type.getName(), var_cont.getName(), var_type.getMthdDscStr());

      closure_member_var.op().assign(closure_member_var, var_cont, opinfo);

    } else {
      throw new CompileException("Invalid var_cont form(" + var_cont + ")");
    }

  }

}
 
Example 55
Project: MeziLang   File: TContextFunc.java   Source Code and License 4 votes vote down vote up
@Override
public int get_access() throws CompileException {
  return Opcodes.ACC_PUBLIC;
}
 
Example 56
Project: Spigot-Attribute-Remover   File: AnnotationRemapper.java   Source Code and License 4 votes vote down vote up
public AnnotationRemapper(final AnnotationVisitor av,
        final Remapper remapper) {
    this(Opcodes.ASM5, av, remapper);
}
 
Example 57
Project: Spigot-Attribute-Remover   File: GeneratorAdapter.java   Source Code and License 4 votes vote down vote up
/**
 * Generates the instructions to jump to a label based on the comparison of
 * the top two stack values.
 * 
 * @param type
 *            the type of the top two stack values.
 * @param mode
 *            how these values must be compared. One of EQ, NE, LT, GE, GT,
 *            LE.
 * @param label
 *            where to jump if the comparison result is <tt>true</tt>.
 */
public void ifCmp(final Type type, final int mode, final Label label) {
    switch (type.getSort()) {
    case Type.LONG:
        mv.visitInsn(Opcodes.LCMP);
        break;
    case Type.DOUBLE:
        mv.visitInsn(mode == GE || mode == GT ? Opcodes.DCMPL
                : Opcodes.DCMPG);
        break;
    case Type.FLOAT:
        mv.visitInsn(mode == GE || mode == GT ? Opcodes.FCMPL
                : Opcodes.FCMPG);
        break;
    case Type.ARRAY:
    case Type.OBJECT:
        switch (mode) {
        case EQ:
            mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label);
            return;
        case NE:
            mv.visitJumpInsn(Opcodes.IF_ACMPNE, label);
            return;
        }
        throw new IllegalArgumentException("Bad comparison for type "
                + type);
    default:
        int intOp = -1;
        switch (mode) {
        case EQ:
            intOp = Opcodes.IF_ICMPEQ;
            break;
        case NE:
            intOp = Opcodes.IF_ICMPNE;
            break;
        case GE:
            intOp = Opcodes.IF_ICMPGE;
            break;
        case LT:
            intOp = Opcodes.IF_ICMPLT;
            break;
        case LE:
            intOp = Opcodes.IF_ICMPLE;
            break;
        case GT:
            intOp = Opcodes.IF_ICMPGT;
            break;
        }
        mv.visitJumpInsn(intOp, label);
        return;
    }
    mv.visitJumpInsn(mode, label);
}
 
Example 58
Project: fastAOP   File: AnnotationRemapper.java   Source Code and License 4 votes vote down vote up
public AnnotationRemapper(final AnnotationVisitor av,
        final Remapper remapper) {
    this(Opcodes.ASM5, av, remapper);
}
 
Example 59
Project: MeziLang   File: OpBool.java   Source Code and License 4 votes vote down vote up
@Override
public Container logical_or(Container lval, Container rvalue, OpInfo opinfo) throws CompileException {

  AbsType booltype = (AbsType) cpLoader.findClassFull(TPrimitiveClass.NAME_BOOL);

  AbsType lval_type = lval.getType();
  AbsType rval_type = lval.getType();

  if (!lval_type.equals(booltype)) {
    throw new CompileException("lvalue should be boolean type, but " + lval);
  }
  if (!rval_type.equals(booltype)) {
    throw new CompileException("rvalue should be boolean type, but " + rvalue);
  }

  LangUnitNode node = opinfo.op_node;
  Debug.assertion(node != null, "node should be valid");

  Label logicalop_br_label = node.getLogicalOpBrLabel();
  Debug.assertion(logicalop_br_label != null, "logicalop_br_label should be valid");
  Label end_label = new Label();

  /*
   * opinfo.mv.visitInsn(Opcodes.IOR); opinfo.mv.visitJumpInsn(Opcodes.IFEQ,
   * zero_label); opinfo.mv.visitInsn(Opcodes.ICONST_1);
   * opinfo.mv.visitJumpInsn(Opcodes.GOTO, end_label);
   * opinfo.mv.visitLabel(zero_label); opinfo.mv.visitInsn(Opcodes.ICONST_0);
   * opinfo.mv.visitLabel(end_label);
   */
  opinfo.mv.visitInsn(Opcodes.ICONST_0);
  opinfo.mv.visitJumpInsn(Opcodes.GOTO, end_label);
  opinfo.mv.visitLabel(logicalop_br_label);
  opinfo.mv.visitInsn(Opcodes.ICONST_1);
  opinfo.mv.visitLabel(end_label);

  Container anony_bool = new Container("anonymous", Container.FORM_OPSTACK_VAR, true, false);
  anony_bool.initializeType(booltype);
  anony_bool.setAssigned(true);

  return anony_bool;
}
 
Example 60
Project: MeziLang   File: OpString.java   Source Code and License 4 votes vote down vote up
@Override
public void store(Container lval, OpInfo opinfo, int index) throws CompileException {
  opinfo.mv.visitVarInsn(Opcodes.ASTORE, index);
  LOG.info("ASTORE_" + index);
}