当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitTypeInsn方法代码示例

本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitTypeInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitTypeInsn方法的具体用法?Java MethodVisitor.visitTypeInsn怎么用?Java MethodVisitor.visitTypeInsn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitTypeInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createObjectRender

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void createObjectRender(ClassWriter cw, String className, String classDesc, Type data) {
    Label start = new Label();
    Label end = new Label();

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "render",
            Type.getMethodDescriptor(BytecodeGenerator.STRING, BytecodeGenerator.OBJECT), null, null);
    mv.visitCode();
    mv.visitLabel(start);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, data.getInternalName());
    mv.visitMethodInsn(INVOKEVIRTUAL, className, "render", Type.getMethodDescriptor(BytecodeGenerator.STRING, data), false);
    mv.visitInsn(ARETURN);
    mv.visitLabel(end);
    mv.visitLocalVariable("this", classDesc, null, start, end, 0);
    //mv.visitLocalVariable("obj", data.getDescriptor(), null, start, end, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:20,代码来源:MustacheCompiler.java

示例2: insertCollectionStart

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void insertCollectionStart(MethodVisitor mv) {
    // collection.iterator()
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;", true);
    mv.visitVarInsn(ASTORE, varArray);

    mv.visitLabel(loopStart);

    // Append a new frame preserving the same locals from the last one
    mv.visitFrame(F_APPEND, 2, new Object[]{BUILDER.getInternalName(), "java/util/Iterator"}, 0, null);

    // if(iterator.hasNext()) break;
    mv.visitVarInsn(ALOAD, varArray);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true);
    mv.visitJumpInsn(IFEQ, loopEnd);

    // (String)iterator.next()
    mv.visitVarInsn(ALOAD, varArray);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
    mv.visitTypeInsn(CHECKCAST, Type.getInternalName(member.component));
    mv.visitVarInsn(ASTORE, varObject);
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:22,代码来源:LoopSection.java

示例3: generateMethodTest9

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke virtual. The target method is a method into a class implementing
 *  an abstract method and that shadows a default method from an interface.
 */
private void generateMethodTest9(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test9", "()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),
      "bsmCreateCallCallingtargetMethodTest10", 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("targetMethodTest10", "(Linvokecustom/InvokeCustom;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEVIRTUAL, Type.getInternalName(InvokeCustom.class),
          "targetMethodTest10", "()V", false));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:23,代码来源:TestGenerator.java

示例4: generateMethodTest12

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get instance. The method handle read an instance field from a class.
 */
private void generateMethodTest12(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test12", "()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.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("instanceField1", "(Linvokecustom/InvokeCustom;)Ljava/lang/String;",
      bootstrap, new Handle(Opcodes.H_GETFIELD, Type.getInternalName(InvokeCustom.class),
          "instanceField1", "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);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:30,代码来源:TestGenerator.java

示例5: generateDefaultTraceAfter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateDefaultTraceAfter(InterceptedCall call, MethodVisitor mv, int mcvar, Type retType, MethodInfo minfo) {
    if (retType.getSort() == Type.VOID) {
        // Do nothing
    } else if (retType.getSort() == Type.ARRAY || retType.getSort() == Type.OBJECT) {
        mv.visitVarInsn(ALOAD, mcvar);
        mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValue", "(Ljava/lang/Object;" + MethodCall_Desc + ")Ljava/lang/Object;", false);
        if (!"java/lang/Object".equals(retType.getInternalName()))
            mv.visitTypeInsn(CHECKCAST, retType.getInternalName());
    } else {
        mv.visitVarInsn(ALOAD, mcvar);
        String returnNativeType = minfo.returnNativeType;
        if ("GLenum".equals(returnNativeType) || "GLboolean".equals(returnNativeType)) {
            loadGLenumReturn(call.glName, "glEnumReturn", mv);
        } else if ("GLFWwindow *".equals(returnNativeType)) {
            mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValueGlfwWindow", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
        } else if ("GLFWmonitor *".equals(returnNativeType)) {
            mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValueGlfwMonitor", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
        } else {
            mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "returnValue", "(" + retType.getDescriptor() + MethodCall_Desc + ")" + retType.getDescriptor(), false);
        }
    }
    mv.visitVarInsn(ALOAD, mcvar);
    mv.visitMethodInsn(INVOKESTATIC, RT_InternalName, "methodCall", "(Lorg/lwjglx/debug/MethodCall;)V", false);
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:25,代码来源:InterceptClassGenerator.java

示例6: generateMethodTest5

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 *  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 shadows another default method from a super interface.
 */
private void generateMethodTest5(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test5", "()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),
      "bsmCreateCallCallingtargetMethodTest6", 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("targetMethodTest6", "(Linvokecustom/I;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(I.class),
          "targetMethodTest6", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
开发者ID:inferjay,项目名称:r8,代码行数:23,代码来源:TestGenerator.java

示例7: generateUpdaterMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdaterMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String updaterClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;

    mv = cw.visitMethod(ACC_PUBLIC, "updater", "()Lio/primeval/reflex/arguments/ArgumentsUpdater;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, updaterClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, updaterClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:27,代码来源:MethodArgumentsGenerator.java

示例8: writeGroovyMethods

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeGroovyMethods(ClassVisitor visitor, Class<?> viewClass) {
    // Object propertyMissing(String name)
    MethodVisitor methodVisitor = declareMethod(visitor, "propertyMissing", GET_PROPERTY_MISSING_METHOD_DESCRIPTOR, CONCRETE_SIGNATURE);

    // throw new MissingPropertyException(name, <view-type>.class)
    methodVisitor.visitTypeInsn(NEW, MISSING_PROPERTY_EXCEPTION_TYPE);
    methodVisitor.visitInsn(DUP);
    putFirstMethodArgumentOnStack(methodVisitor);
    putClassOnStack(methodVisitor, viewClass);
    methodVisitor.visitMethodInsn(INVOKESPECIAL, MISSING_PROPERTY_EXCEPTION_TYPE, "<init>", MISSING_PROPERTY_CONSTRUCTOR_DESCRIPTOR, false);
    finishVisitingMethod(methodVisitor, ATHROW);

    // Object propertyMissing(String name, Object value)

    methodVisitor = declareMethod(visitor, "propertyMissing", SET_PROPERTY_MISSING_METHOD_DESCRIPTOR, CONCRETE_SIGNATURE);

    // throw new MissingPropertyException(name, <view-type>.class)
    methodVisitor.visitTypeInsn(NEW, MISSING_PROPERTY_EXCEPTION_TYPE);
    methodVisitor.visitInsn(DUP);
    putFirstMethodArgumentOnStack(methodVisitor);
    putClassOnStack(methodVisitor, viewClass);
    methodVisitor.visitMethodInsn(INVOKESPECIAL, MISSING_PROPERTY_EXCEPTION_TYPE, "<init>", MISSING_PROPERTY_CONSTRUCTOR_DESCRIPTOR, false);
    finishVisitingMethod(methodVisitor, ATHROW);

    // Object methodMissing(String name, Object args)
    methodVisitor = declareMethod(visitor, "methodMissing", METHOD_MISSING_METHOD_DESCRIPTOR, CONCRETE_SIGNATURE);

    // throw new MissingMethodException(name, <view-type>.class, args)
    methodVisitor.visitTypeInsn(NEW, MISSING_METHOD_EXCEPTION_TYPE);
    methodVisitor.visitInsn(DUP);
    putMethodArgumentOnStack(methodVisitor, 1);
    putClassOnStack(methodVisitor, viewClass);
    putMethodArgumentOnStack(methodVisitor, 2);
    methodVisitor.visitTypeInsn(CHECKCAST, OBJECT_ARRAY_TYPE);
    methodVisitor.visitMethodInsn(INVOKESPECIAL, MISSING_METHOD_EXCEPTION_TYPE, "<init>", MISSING_METHOD_EXCEPTION_CONSTRUCTOR_DESCRIPTOR, false);
    finishVisitingMethod(methodVisitor, ATHROW);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:38,代码来源:ManagedProxyClassGenerator.java

示例9: createCharObj

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createCharObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Character");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ILOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Character", "<init>", "(C)V");
    mv.visitInsn(Opcodes.AASTORE);
}
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:8,代码来源:RobustAsmUtils.java

示例10: writeEqualsMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeEqualsMethod(ClassVisitor cw, Type generatedType) {
    MethodVisitor methodVisitor = cw.visitMethod(Opcodes.ACC_PUBLIC, "equals", EQUALS_METHOD_DESCRIPTOR, null, null);
    methodVisitor.visitCode();

    // if (arg == this) { return true; }
    methodVisitor.visitVarInsn(ALOAD, 0);
    methodVisitor.visitVarInsn(ALOAD, 1);
    Label notSameLabel = new Label();
    methodVisitor.visitJumpInsn(IF_ACMPNE, notSameLabel);
    methodVisitor.visitInsn(ICONST_1);
    methodVisitor.visitInsn(IRETURN);

    // if (!(age instanceof GeneratedView)) { return false; }
    methodVisitor.visitLabel(notSameLabel);
    methodVisitor.visitVarInsn(ALOAD, 1);
    methodVisitor.visitTypeInsn(INSTANCEOF, GENERATED_VIEW_TYPE.getInternalName());
    Label generatedViewLabel = new Label();
    methodVisitor.visitJumpInsn(IFNE, generatedViewLabel);
    methodVisitor.visitInsn(ICONST_0);
    methodVisitor.visitInsn(IRETURN);

    // return state.equals(((GeneratedView)arg).__view_state());
    methodVisitor.visitLabel(generatedViewLabel);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    methodVisitor.visitVarInsn(ALOAD, 1);
    methodVisitor.visitTypeInsn(CHECKCAST, GENERATED_VIEW_TYPE.getInternalName());
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, GENERATED_VIEW_TYPE.getInternalName(), "__view_state__", GET_VIEW_STATE_METHOD_DESCRIPTOR, true);
    methodVisitor.visitMethodInsn(INVOKEINTERFACE, GENERATED_VIEW_STATE_TYPE_NAME, "equals", EQUALS_METHOD_DESCRIPTOR, true);
    finishVisitingMethod(methodVisitor, Opcodes.IRETURN);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:31,代码来源:ManagedProxyClassGenerator.java

示例11: insertNewInstanceInner

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static void insertNewInstanceInner(ClassWriter cw, String classNameInternal, String enclosingClassNameInternal) {
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newInstance", "(Ljava/lang/Object;)Ljava/lang/Object;", null,
			null);
	mv.visitCode();
	if (enclosingClassNameInternal != null) {
		mv.visitTypeInsn(NEW, classNameInternal);
		mv.visitInsn(DUP);
		mv.visitVarInsn(ALOAD, 1);
		mv.visitTypeInsn(CHECKCAST, enclosingClassNameInternal);
		mv.visitInsn(DUP);
		mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;");
		mv.visitInsn(POP);
		mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "(L" + enclosingClassNameInternal + ";)V");
		mv.visitInsn(ARETURN);
		mv.visitMaxs(4, 2);
	} else {
		mv.visitTypeInsn(NEW, "java/lang/UnsupportedOperationException");
		mv.visitInsn(DUP);
		mv.visitLdcInsn("Not an inner class.");
		mv.visitMethodInsn(INVOKESPECIAL, "java/lang/UnsupportedOperationException", "<init>",
				"(Ljava/lang/String;)V");
		mv.visitInsn(ATHROW);
		mv.visitMaxs(3, 2);
	}
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:28,代码来源:ConstructorAccess.java

示例12: generateToStringMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateToStringMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
    mv.visitInsn(DUP);
    mv.visitLdcInsn(Type.getType(selfClassDescriptor));
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getSimpleName", "()Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    mv.visitLdcInsn(" [");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);

    for (int i = 0; i < parameters.length; i++) {
        Parameter param = parameters[i];
        mv.visitLdcInsn(param.getName() + "=");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
                false);
        mv.visitVarInsn(ALOAD, 0); // this
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), Type.getDescriptor(param.getType()));
        Class<?> paramType = param.getType();
        if (paramType.isPrimitive()) {
            // special case with StringBuilder, no specific method we default to append(int)
            if (paramType == short.class || paramType == byte.class) {
                paramType = int.class;
            }
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                    Type.getMethodDescriptor(Type.getType(StringBuilder.class), Type.getType(paramType)), false);
        } else {
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
                    "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
        }
        if (i + 1 < parameters.length) {
            mv.visitLdcInsn(", ");
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;",
                    false);
        }
    }
    mv.visitLdcInsn("]");
    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.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:52,代码来源:MethodArgumentssUpdaterGenerator.java

示例13: createIntegerObj

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void createIntegerObj(MethodVisitor mv, int argsPostion) {
    mv.visitTypeInsn(Opcodes.NEW, "java/lang/Integer");
    mv.visitInsn(Opcodes.DUP);
    mv.visitVarInsn(Opcodes.ILOAD, argsPostion);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Integer", "<init>", "(I)V");
    mv.visitInsn(Opcodes.AASTORE);
}
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:8,代码来源:RobustAsmUtils.java

示例14: hookMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
/**
 * (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;
}
 
开发者ID:baidu,项目名称:openrasp,代码行数:44,代码来源:FileOutputStream2Hook.java

示例15: accept

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor mv) {
    mv.visitTypeInsn(opcode, desc);
    acceptAnnotations(mv);
}
 
开发者ID:acmerli,项目名称:fastAOP,代码行数:6,代码来源:TypeInsnNode.java


注:本文中的org.objectweb.asm.MethodVisitor.visitTypeInsn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。