Java 类org.objectweb.asm.MethodVisitor 实例源码

项目:MeziLang    文件:ASTCompileVisitor.java   
@Override
public Object visit(ASTStreamBlockElementHdr node, Object data) throws CompileException {

  // function or stream is in here
  TContext func_context = getTopContext().getClosestAncestor(AbsType.FORM_FUNC);
  if (func_context != null) {
    MethodVisitor mv = ((TContextFunc) func_context).getMethodVisitor();
    Debug.assertion(mv != null, "mv should be valid");

    /*
     * Label linelabel = new Label();
     *
     * // line label for debugging mv.visitLabel(linelabel);
     * mv.visitLineNumber(node.jjtGetFirstToken().beginLine, linelabel);
     */

    addLineLable(mv, node.jjtGetFirstToken().beginLine);
  }

  return null;
}
项目:openrasp    文件:JspCompilationContextHook.java   
/**
 * (none-javadoc)
 *
 * @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
public MethodVisitor hookMethod(int access, String name, String desc,
                                String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("compile") && desc.startsWith("()V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("preShieldHook", "()V"));
            }

            @Override
            protected void onMethodExit(int i) {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("postShieldHook", "()V"));
            }
        };
    }
    return mv;
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get static. The method handle read a static field from a class.
 */
private void generateMethodTest10(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test10", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitInvokeDynamicInsn("staticField1", "()Ljava/lang/String;", bootstrap,
      new Handle(Opcodes.H_GETSTATIC, Type.getInternalName(InvokeCustom.class),
          "staticField1", "Ljava/lang/String;", false));
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:Reer    文件:MethodStubbingApiMemberAdapter.java   
/**
 * Generates an exception which is going to be thrown in each method.
 * The reason it is in a separate method is because it reduces the bytecode size.
 */
private void generateUnsupportedOperationExceptionMethod() {
    MethodVisitor mv = cv.visitMethod(
        ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC, UOE_METHOD,
        "()Ljava/lang/UnsupportedOperationException;", null, null);
    mv.visitCode();
    mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(
        "You tried to call a method on an API class. Is the API jar on the classpath instead of the runtime jar?");
    mv.visitMethodInsn(
        INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ARETURN);
    mv.visitMaxs(3, 0);
    mv.visitEnd();
}
项目:javametrics    文件:ClassAdapter.java   
/**
 * Instrument HTTP request methods
 * 
 * @param mv
 *            original MethodVisitor
 * @param access
 * @param name
 * @param desc
 * @param signature
 * @param exceptions
 * @return original MethodVisitor or new MethodVisitor chained to original
 */
private MethodVisitor visitHttpMethod(MethodVisitor mv, int access, String name, String desc, String signature,
        String[] exceptions) {

    MethodVisitor httpMv = mv;

    /*
     * Instrument _jspService method for JSP. Instrument doGet, doPost and
     * service methods for servlets.
     */
    if ((httpInstrumentJsp && name.equals("_jspService")) || (httpInstrumentServlet
            && (name.equals("doGet") || name.equals("doPost") || name.equals("service")))) {

        // Only instrument if method has the correct signature
        if (HTTP_REQUEST_METHOD_DESC.equals(desc)) {
            httpMv = new ServletCallBackAdapter(className, mv, access, name, desc);
        }
    }

    return httpMv;
}
项目:r8    文件:TestGenerator.java   
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that is at the end of a chain of interfaces.
 */
private void generateMethodTest6(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test6", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest7", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest7", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest7", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
项目:fastAOP    文件:ASMContentHandler.java   
@Override
public void begin(final String name, final Attributes attrs) {
    String desc = attrs.getValue("desc");
    boolean visible = Boolean.valueOf(attrs.getValue("visible"))
            .booleanValue();
    int typeRef = Integer.parseInt(attrs.getValue("typeRef"));
    TypePath typePath = TypePath.fromString(attrs.getValue("typePath"));

    Object v = peek();
    if (v instanceof ClassVisitor) {
        push(((ClassVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof FieldVisitor) {
        push(((FieldVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    } else if (v instanceof MethodVisitor) {
        push(((MethodVisitor) v).visitTypeAnnotation(typeRef, typePath,
                desc, visible));
    }
}
项目:DirectLeaks-AntiReleak-Remover    文件:StaticInitMerger.java   
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    MethodVisitor mv;
    if ("<clinit>".equals(name)) {
        int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
        String n = prefix + counter++;
        mv = cv.visitMethod(a, n, desc, signature, exceptions);

        if (clinit == null) {
            clinit = cv.visitMethod(a, name, desc, null, null);
        }
        clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc,
                false);
    } else {
        mv = cv.visitMethod(access, name, desc, signature, exceptions);
    }
    return mv;
}
项目:Reer    文件:ManagedProxyClassGenerator.java   
private void writeSetter(ClassVisitor visitor, Type generatedType, String propertyName, Class<?> propertyClass, WeaklyTypeReferencingMethod<?, ?> weakSetter) {
    Type propertyType = Type.getType(propertyClass);
    Label calledOutsideOfConstructor = new Label();

    Method setter = weakSetter.getMethod();

    // the regular typed setter
    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, propertyType);
    MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), methodDescriptor, AsmClassGeneratorUtils.signature(setter));

    putCanCallSettersFieldValueOnStack(methodVisitor, generatedType);
    jumpToLabelIfStackEvaluatesToTrue(methodVisitor, calledOutsideOfConstructor);
    throwExceptionBecauseCalledOnItself(methodVisitor);

    methodVisitor.visitLabel(calledOutsideOfConstructor);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    putConstantOnStack(methodVisitor, propertyName);
    putFirstMethodArgumentOnStack(methodVisitor, propertyType);
    if (propertyClass.isPrimitive()) {
        boxType(methodVisitor, propertyClass);
    }
    invokeStateSetMethod(methodVisitor);

    finishVisitingMethod(methodVisitor);
}
项目:fastAOP    文件:ClassConstantsCollector.java   
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        cp.newUTF8("Synthetic");
    }
    if ((access & Opcodes.ACC_DEPRECATED) != 0) {
        cp.newUTF8("Deprecated");
    }
    cp.newUTF8(name);
    cp.newUTF8(desc);
    if (signature != null) {
        cp.newUTF8("Signature");
        cp.newUTF8(signature);
    }
    if (exceptions != null) {
        cp.newUTF8("Exceptions");
        for (int i = 0; i < exceptions.length; ++i) {
            cp.newClass(exceptions[i]);
        }
    }
    return new MethodConstantsCollector(cv.visitMethod(access, name, desc,
            signature, exceptions), cp);
}
项目:Spigot-Nonce-ID-Finder    文件:FrameNode.java   
/**
 * 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;
    }
}
项目:openrasp    文件:ProxyDirContextHook.java   
/**
 * (none-javadoc)
 *
 * @see AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("lookup".equals(name) && desc.startsWith("(Ljava/lang/String;)")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodExit(int opcode) {
                if (opcode == Opcodes.ARETURN) {
                    mv.visitVarInsn(ALOAD, 2);
                    mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/ProxyDirContextHook", "checkResourceCacheEntry",
                            "(Ljava/lang/Object;)V", false);
                }
                super.onMethodExit(opcode);
            }

        };
    }
    return mv;
}
项目:debug    文件:InterceptClassGenerator.java   
private static void callUserMethodOrDirect(ClassLoader classLoader, InterceptedCall call, MethodVisitor mv) {
    /* Check if we have a user-provided validation method */
    String validationMethodOwnerName = getClassForMethod(classLoader, call.desc, call);
    if (validationMethodOwnerName != null) {
        /* we have, so call it... */
        mv.visitMethodInsn(INVOKESTATIC, validationMethodOwnerName, call.name, call.desc, false);
    } else {
        /* we don't have a user-defined validation method yet, so just call the target method directly */
        mv.visitMethodInsn(INVOKESTATIC, call.receiverInternalName, call.name, call.desc, false);
    }
    /* Check GL error if it was a GL call */
    if (VALIDATE.enabled && call.glName != null && !call.glName.equals("glGetError")) {
        mv.visitLdcInsn(call.name);
        mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "checkError", "(Ljava/lang/String;)V", false);
    }
}
项目:FastMustache    文件:ClassDataManager.java   
@Override
public void insertBooleanGetter(MethodVisitor mv, int var, String key) throws CompilerException {
    Class<?> type = insertGetter(mv, var, key, true).clazz;

    if(type == boolean.class) {
        // The correct type. We don't need to adapt it :D
        return;
    }

    if(type == Boolean.class) {
        // b.booleanValue()
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
    } else if(type.isPrimitive()) {
        throw new CompilerException("Can't parse a primitive into a boolean: " + type);
    } else {
        // Boolean.parseBoolean(object.toString())
        mv.visitMethodInsn(INVOKEVIRTUAL, OBJECT.getInternalName(), "toString", Type.getMethodDescriptor(STRING), false);
        mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "parseBoolean", Type.getMethodDescriptor(STRING, Type.BOOLEAN_TYPE), false);
    }
}
项目:fastAOP    文件:ASMContentHandler.java   
@Override
public void begin(final String name, final Attributes attrs) {
    String desc = attrs.getValue("desc");
    boolean visible = Boolean.valueOf(attrs.getValue("visible"))
            .booleanValue();
    int typeRef = Integer.parseInt(attrs.getValue("typeRef"));
    TypePath typePath = TypePath.fromString(attrs.getValue("typePath"));
    push(((MethodVisitor) peek()).visitTryCatchAnnotation(typeRef,
            typePath, desc, visible));
}
项目:businessworks    文件:LineNumbers.java   
public MethodVisitor visitMethod(int access, String name, String desc,
    String signature, String[] exceptions) {
  if ((access & Opcodes.ACC_PRIVATE) != 0) {
    return null;
  }
  pendingMethod = name + desc;
  line = -1;
  return new LineNumberMethodVisitor();
}
项目:openrasp    文件:ThreadHookClassVisitor.java   
/**
 * hook线程子类
 *
 * @see ClassVisitor#visitMethod(int, String, String, String, String[])
 */
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    if (isRunnable && name.equals("run") && desc.equals("()V")) {
        return new CommonMethodVisitor(mv, this.className, access, name, desc);
    }
    if (isCallable && name.equals("call") && desc.equals("()V")) {
        return new CommonMethodVisitor(mv, this.className, access, name, desc);
    }
    return mv;
}
项目:Robust    文件:RobustAsmUtils.java   
private static void createBooleanObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Byte");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ILOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Byte", "<init>", "(B)V");
    mv.visitInsn(Opcodes.AASTORE);
}
项目:BukkitPlugin-Message-Injector    文件:InsnList.java   
/**
 * Makes the given visitor visit all of the instructions in this list.
 * 
 * @param mv
 *            the method visitor that must visit the instructions.
 */
public void accept(final MethodVisitor mv) {
    AbstractInsnNode insn = first;
    while (insn != null) {
        insn.accept(mv);
        insn = insn.next;
    }
}
项目:primeval-reflex    文件:MethodArgumentsGenerator.java   
private static void genExceptionThrowForUnknownParam(String paramType, MethodVisitor mv) {
    mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
    mv.visitInsn(DUP);
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitLdcInsn("No " + paramType + " parameter named ");
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
            false);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitInsn(ATHROW);
}
项目:MeziLang    文件:ASTCompileVisitor.java   
@Override
public Object visit(ASTIfCaseExpr node, Object data) throws CompileException {

  MethodVisitor mv = getClosestFunContext().getMethodVisitor();
  Label ifend_label = node.getBrLabel();

  if (node.hasDefinitionRefernce()) {
    Reduction reduce = topReduction();
    Debug.assertion(reduce != null, "Reduction should not be invalid");
    if (reduce.isContainer()) {
      Container cont = (Container) reduce;
      AbsType type = cont.getType();
      Debug.assertion(type != null, "type should be valid");

      if (cont.isForm(Container.FORM_OPSTACK_VAR) && !type.isName(TPrimitiveClass.NAME_VOID)) {
        type.op().pop(cont, new OpInfo(getTopContext()));

        popReduction(); // consume op stack var non void container
        pushReduction(new Control(Control.FORM_BRANCH));
      }
    }
  }

  if (ifend_label != null && node.isAliveCtrlFlow()) {
    mv.visitJumpInsn(GOTO, ifend_label);
  }

  return null;
}
项目:MeziLang    文件:ASTCompileVisitor.java   
@Override
public Object visit(ASTForAction node, Object data) throws CompileException {

  MethodVisitor mv = getClosestFunContext().getMethodVisitor();

  if (node.jjtGetNumChildren() == 0) {
    // do nothing
  } else if (node.jjtGetNumChildren() == 1) {
    Reduction reduce = popReduction();
    Debug.assertion(reduce != null, "Reductin should not be invalid");
    Debug.assertion(reduce.isContainer(), "Reductin should be container");

    Container cont = (Container) reduce;
    Debug.assertion(cont.isTypeInitialized(), "cont should be type initialized");

    cont.getType().op().pop(cont, new OpInfo(getTopContext()));
  } else {
    throw new CompileException("This case is not considered");
  }

  LangUnitNode parent = (LangUnitNode) node.jjtGetParent();
  Debug.assertion(parent != null, "parent should not be invalid");
  Debug.assertion(parent.isNodeId(JJTCSTYLELOOPEXPR), "parent should be c style loop");

  Label loop_cond_label = parent.getLoopCondLabel();
  Debug.assertion(loop_cond_label != null, "loop condition label should not be invalid");

  mv.visitLabel(loop_cond_label);

  return null;
}
项目:openrasp    文件:HttpClientHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("setURI") && desc.equals("(Ljava/net/URI;)V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(0);
                invokeStatic(Type.getType(HttpClientHook.class),
                        new Method("checkHttpUri", "(Ljava/net/URI;)V"));
            }
        };
    }
    return mv;
}
项目:DirectLeaks-AntiReleak-Remover    文件:ASMContentHandler.java   
@Override
public void begin(final String name, final Attributes attrs) {
    int parameter = Integer.parseInt(attrs.getValue("parameter"));
    String desc = attrs.getValue("desc");
    boolean visible = Boolean.valueOf(attrs.getValue("visible"))
            .booleanValue();

    push(((MethodVisitor) peek()).visitParameterAnnotation(parameter,
            desc, visible));
}
项目:openrasp    文件:FileOutputStream2Hook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    // store file info in lockClose Object
    if ("<init>".equals(name) && "(Ljava/io/File;Z)V".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodExit(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    mv.visitVarInsn(ALOAD, 0);
                    mv.visitTypeInsn(NEW, "com/fuxi/javaagent/tool/hook/CustomLockObject");
                    mv.visitInsn(DUP);
                    mv.visitMethodInsn(INVOKESPECIAL, "com/fuxi/javaagent/tool/hook/CustomLockObject",
                            "<init>", "()V", false);
                    mv.visitFieldInsn(PUTFIELD, "java/io/FileOutputStream", "closeLock", "Ljava/lang/Object;");
                    mv.visitVarInsn(ALOAD, 0);
                    mv.visitFieldInsn(GETFIELD, "java/io/FileOutputStream", "closeLock", "Ljava/lang/Object;");
                    mv.visitVarInsn(ALOAD, 3);
                    mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/file/FileOutputStream2Hook", "checkFileOutputStreamInit",
                            "(Ljava/lang/Object;Ljava/lang/String;)V", false);
                }
                super.onMethodExit(opcode);
            }
        };
    }
    if (name.equals("write") && desc.startsWith("([B")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodEnter() {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, "java/io/FileOutputStream", "closeLock", "Ljava/lang/Object;");
                mv.visitVarInsn(ALOAD, 1);
                mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/hook/file/FileOutputStream2Hook", "checkFileOutputStreamWrite",
                        "(Ljava/lang/Object;[B)V", false);
            }
        };
    }
    return mv;
}
项目:BukkitPlugin-Message-Injector    文件:TableSwitchInsnNode.java   
@Override
public void accept(final MethodVisitor mv) {
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitTableSwitchInsn(min, max, dflt.getLabel(), labels);
    acceptAnnotations(mv);
}
项目:fastAOP    文件:SerialVersionUIDAdder.java   
@Override
public MethodVisitor visitMethod(final int access, final String name,
        final String desc, final String signature, final String[] exceptions) {
    if (computeSVUID) {
        if ("<clinit>".equals(name)) {
            hasStaticInitializer = true;
        }
        /*
         * Remembers non private constructors and methods for SVUID
         * computation For constructor and method modifiers, only the
         * ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL,
         * ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT and ACC_STRICT flags
         * are used.
         */
        int mods = access
                & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE
                        | Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC
                        | Opcodes.ACC_FINAL | Opcodes.ACC_SYNCHRONIZED
                        | Opcodes.ACC_NATIVE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_STRICT);

        // all non private methods
        if ((access & Opcodes.ACC_PRIVATE) == 0) {
            if ("<init>".equals(name)) {
                svuidConstructors.add(new Item(name, mods, desc));
            } else if (!"<clinit>".equals(name)) {
                svuidMethods.add(new Item(name, mods, desc));
            }
        }
    }

    return super.visitMethod(access, name, desc, signature, exceptions);
}
项目:primeval-reflex    文件:MethodArgumentsGenerator.java   
private static void generateParametersGetter(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "parameters", "()Ljava/util/List;", "()Ljava/util/List<Ljava/lang/reflect/Parameter;>;", null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
项目:faster-than-reflection    文件:AsmUtils.java   
public static void visitDefaultConstructor(ClassWriter cw, String classTypeDescriptor) {
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(RETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", classTypeDescriptor, null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
项目:MCheatEngine    文件:MethodChangeClassAdapter.java   
@Override  
public MethodVisitor visitMethod(  
    int access,  
    String name,  
    String desc,  
    String signature,  
    String[] exceptions)  
{  


        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);//�ȵõ�ԭʼ�ķ���    
        MethodVisitor newMethod = new AsmMethodVisit(mv,targetMethodname,toName);              
        return newMethod;    
}
项目:Spigot-Nonce-ID-Finder    文件:TableSwitchInsnNode.java   
@Override
public void accept(final MethodVisitor mv) {
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitTableSwitchInsn(min, max, dflt.getLabel(), labels);
    acceptAnnotations(mv);
}
项目:Reer    文件:ManagedProxyClassGenerator.java   
private void writeReadOnlySetter(ClassVisitor visitor, Class<?> viewClass, boolean writable, ModelProperty<?> property) {
    if (!writable) {
        // Adds a void set$PropName(Object value) method that fails
        String setterName = "set" + StringUtils.capitalize(property.getName());
        MethodVisitor methodVisitor = declareMethod(visitor, setterName, SET_OBJECT_PROPERTY_DESCRIPTOR, null, ACC_PUBLIC | ACC_SYNTHETIC);

        // throw new ReadOnlyPropertyException(name, <view-type>.class)
        methodVisitor.visitTypeInsn(NEW, READ_ONLY_PROPERTY_EXCEPTION_TYPE);
        methodVisitor.visitInsn(DUP);
        putConstantOnStack(methodVisitor, property.getName());
        putClassOnStack(methodVisitor, viewClass);
        methodVisitor.visitMethodInsn(INVOKESPECIAL, READ_ONLY_PROPERTY_EXCEPTION_TYPE, "<init>", MISSING_PROPERTY_CONSTRUCTOR_DESCRIPTOR, false);
        finishVisitingMethod(methodVisitor, ATHROW);
    }
}
项目:Robust    文件:RobustAsmUtils.java   
private static void createLongObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Long");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.LLOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Long", "<init>", "(J)V");
    mv.visitInsn(Opcodes.AASTORE);
}
项目:Spigot-Attribute-Remover    文件:RemappingClassAdapter.java   
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
        String signature, String[] exceptions) {
    String newDesc = remapper.mapMethodDesc(desc);
    MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName(
            className, name, desc), newDesc, remapper.mapSignature(
            signature, false),
            exceptions == null ? null : remapper.mapTypes(exceptions));
    return mv == null ? null : createRemappingMethodAdapter(access,
            newDesc, mv);
}
项目:authlib-injector    文件:LdcTransformUnit.java   
@Override
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
    return Optional.of(new ClassVisitor(ASM5, writer) {

        @Override
        public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
            return new MethodVisitor(ASM5, super.visitMethod(access, name, desc, signature, exceptions)) {

                @Override
                public void visitLdcInsn(Object cst) {
                    if (cst instanceof String) {
                        Optional<String> transformed = ldcMapper.apply((String) cst);
                        if (transformed.isPresent() && !transformed.get().equals(cst)) {
                            modifiedCallback.run();
                            log("transform [{0}] to [{1}]", cst, transformed.get());
                            super.visitLdcInsn(transformed.get());
                        } else {
                            super.visitLdcInsn(cst);
                        }
                    } else {
                        super.visitLdcInsn(cst);
                    }
                }
            };
        }
    });
}
项目:primeval-reflex    文件:ProxyClassGenerator.java   
static void visitIntInsn(MethodVisitor mv, int i) {
    switch (i) {
    case -1:
        mv.visitInsn(ICONST_M1);
        break;
    case 0:
        mv.visitInsn(ICONST_0);
        break;
    case 1:
        mv.visitInsn(ICONST_1);
        break;
    case 2:
        mv.visitInsn(ICONST_2);
        break;
    case 3:
        mv.visitInsn(ICONST_3);
        break;
    case 4:
        mv.visitInsn(ICONST_4);
        break;
    case 5:
        mv.visitInsn(ICONST_5);
        break;

    default:
        mv.visitIntInsn(BIPUSH, i);
        break;
    }
}
项目:fastAOP    文件:LookupSwitchInsnNode.java   
@Override
public void accept(final MethodVisitor mv) {
    int[] keys = new int[this.keys.size()];
    for (int i = 0; i < keys.length; ++i) {
        keys[i] = this.keys.get(i).intValue();
    }
    Label[] labels = new Label[this.labels.size()];
    for (int i = 0; i < labels.length; ++i) {
        labels[i] = this.labels.get(i).getLabel();
    }
    mv.visitLookupSwitchInsn(dflt.getLabel(), keys, labels);
    acceptAnnotations(mv);
}
项目:debug    文件:InterceptClassGenerator.java   
private static void generateDefaultTraceBefore(InterceptedCall call, MethodVisitor mv, Type[] paramTypes, MethodInfo minfo) {
    int var = 0;
    int glEnumIndex = 0;
    for (int i = 0; i < paramTypes.length; i++) {
        Type paramType = paramTypes[i];
        String nativeType = minfo.parameterNativeTypes[i];
        if ("GLenum".equals(nativeType) || "GLboolean".equals(nativeType)) {
            glEnumIndex = loadGLenum(call.glName, "glEnumFor", mv, var, glEnumIndex);
        } else if ("GLbitfield".equals(nativeType)) {
            glEnumIndex = loadGLenum(call.glName, "decodeBitField", mv, var, glEnumIndex);
        } else if ("GLFWwindow *".equals(nativeType)) {
            mv.visitVarInsn(paramType.getOpcode(ILOAD), var);
            mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "paramGlfwWindow", "(" + MethodCall_Desc + paramType.getDescriptor() + ")" + MethodCall_Desc, false);
        } else if ("GLFWmonitor *".equals(nativeType)) {
            mv.visitVarInsn(paramType.getOpcode(ILOAD), var);
            mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "paramGlfwMonitor", "(" + MethodCall_Desc + paramType.getDescriptor() + ")" + MethodCall_Desc, false);
        } else {
            mv.visitVarInsn(paramType.getOpcode(ILOAD), var);
            if (paramType.getSort() == Type.ARRAY || paramType.getSort() == Type.OBJECT) {
                mv.visitMethodInsn(INVOKEVIRTUAL, MethodCall_InternalName, "param", "(Ljava/lang/Object;)" + MethodCall_Desc, false);
            } else {
                mv.visitMethodInsn(INVOKEVIRTUAL, MethodCall_InternalName, "param", "(" + paramType.getDescriptor() + ")" + MethodCall_Desc, false);
            }
        }
        var += paramType.getSize();
    }
    mv.visitInsn(POP);
}
项目:Reer    文件:ManagedProxyClassGenerator.java   
private void writeGetter(ClassVisitor visitor, Type generatedType, String propertyName, Class<?> propertyClass, WeaklyTypeReferencingMethod<?, ?> weakGetter) {
    Method getter = weakGetter.getMethod();
    Type propertyType = Type.getType(propertyClass);
    MethodVisitor methodVisitor = declareMethod(
        visitor,
        getter.getName(),
        Type.getMethodDescriptor(propertyType),
        AsmClassGeneratorUtils.signature(getter));

    putStateFieldValueOnStack(methodVisitor, generatedType);
    putConstantOnStack(methodVisitor, propertyName);
    invokeStateGetMethod(methodVisitor);
    castFirstStackElement(methodVisitor, propertyClass);
    finishVisitingMethod(methodVisitor, returnCode(propertyType));
}
项目:Reer    文件:MixInLegacyTypesClassLoader.java   
private void addSetMetaClass() {
    MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "setMetaClass", Type.getMethodDescriptor(Type.VOID_TYPE, META_CLASS_TYPE), null, null);
    methodVisitor.visitCode();

    // this.metaClass = <value>
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(2, 2);
    methodVisitor.visitEnd();
}