Java 类org.objectweb.asm.commons.AdviceAdapter 实例源码

项目:openrasp    文件:OgnlRuntime.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) {
    if ("invokeMethod".equals(name) && "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitVarInsn(Opcodes.ALOAD, 1);
                mv.visitVarInsn(Opcodes.ALOAD, 2);
                mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/HookHandler",
                        "checkOgnlInvokeMethod", "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)V", false);
            }

            @Override
            protected void onMethodExit(int opcode) {
                mv.visitMethodInsn(INVOKESTATIC, "com/fuxi/javaagent/HookHandler",
                        "onOgnlInvokeMethodExit", "()V", false);
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:HttpServletHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.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("service") && desc.equals("(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(0);
                loadArg(1);
                invokeStatic(Type.getType(ApplicationFilterHook.class),
                        new Method("checkRequest", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"));
            }

            @Override
            protected void onMethodExit(int opcode) {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onServiceExit", "()V"));
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:XXEHook.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) {
    if (name.equals("setValues") && desc.startsWith("(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
            + "Ljava/lang/String;)")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(3);
                invokeStatic(Type.getType(XXEHook.class),
                        new Method("checkXXE", "(Ljava/lang/String;)V"));
            }
        };
    }
    return mv;
}
项目: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;
}
项目:openrasp    文件:ApplicationFilterHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature,
                                   String[] exceptions, MethodVisitor mv) {

    if ("doFilter".equals(name)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(0);
                loadArg(1);
                invokeStatic(Type.getType(ApplicationFilterHook.class),
                        new Method("checkRequest",
                                "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"));
            }

        };
    }
    return mv;
}
项目:openrasp    文件:JstlImportHook.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("targetUrl")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodExit(int opcode) {
                if (opcode != Opcodes.ATHROW) {
                    mv.visitInsn(Opcodes.DUP);
                    invokeStatic(Type.getType(JstlImportHook.class),
                            new Method("checkJstlImport", "(Ljava/lang/String;)V"));
                }
            }
        };
    }
    return mv;
}
项目:openrasp    文件:WebDAVCopyResourceHook.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("copyResource") && desc.startsWith("(Ljavax/naming/directory/DirContext;Ljava/util/Hashtable;Ljava/lang/String;Ljava/lang/String;)Z")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(2);
                loadArg(3);
                invokeStatic(Type.getType(WebDAVCopyResourceHook.class),
                        new Method("checkWebdavCopyResource", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:ProcessBuilderHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.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("start") && desc.equals("()Ljava/lang/Process;")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeVirtual(Type.getType("java/lang/ProcessBuilder"),
                        new Method("command", "()Ljava/util/List;"));
                invokeStatic(Type.getType(ProcessBuilderHook.class),
                        new Method("checkCommand", "(Ljava/util/List;)V"));
            }
        };
    }
    return mv;
}
项目: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;
}
项目:openrasp    文件:DeserializationHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor) (String)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc,
                                   String signature, String[] exceptions, MethodVisitor mv) {
    if ("resolveClass".equals(name) && "(Ljava/io/ObjectStreamClass;)Ljava/lang/Class;".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(0);
                invokeStatic(Type.getType(DeserializationHook.class),
                        new Method("checkDeserializationClass", "(Ljava/io/ObjectStreamClass;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:DiskFileItemHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor) (String)
 */
@Override
public MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("setHeaders")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodExit(int opcode) {
                loadThis();
                invokeInterface(Type.getType("org/apache/commons/fileupload/FileItem"),
                        new Method("getName", "()Ljava/lang/String;"));

                loadThis();
                invokeInterface(Type.getType("org/apache/commons/fileupload/FileItem"),
                        new Method("get", "()[B"));

                invokeStatic(Type.getType(DiskFileItemHook.class),
                        new Method("checkFileUpload", "(Ljava/lang/String;[B)V"));

                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:FileInputStreamHook.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) {
    if ("<init>".equals(name) && "(Ljava/io/File;)V".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            public void onMethodExit(int opcode) {
                if (opcode == Opcodes.RETURN) {
                    loadArg(0);
                    invokeStatic(Type.getType(FileInputStreamHook.class),
                            new Method("checkReadFile", "(Ljava/io/File;)V"));
                }
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:FileOutputStreamHook.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 ("<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) {
                    loadArg(0);
                    invokeStatic(Type.getType(FileOutputStreamHook.class),
                            new Method("checkWriteFile", "(Ljava/io/File;)V"));
                }
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:OgnlHook.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) {
    if ("parseExpression".equals(name) && "(Ljava/lang/String;)Ljava/lang/Object;".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(0);
                invokeStatic(Type.getType(OgnlHook.class),
                        new Method("checkOgnlExpression", "(Ljava/lang/String;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:WeblogicJspBaseHook.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) {
    if (name.equals("service") && desc.equals("(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(0);
                loadArg(1);
                invokeStatic(Type.getType(ApplicationFilterHook.class),
                        new Method("checkRequest", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"));
            }

            @Override
            protected void onMethodExit(int opcode) {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onServiceExit", "()V"));
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:JettyServerHandleHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("handle")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(2);
                loadArg(3);
                invokeStatic(Type.getType(ApplicationFilterHook.class),
                        new Method("checkRequest", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:CommonHttpClientHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("executeMethod") && desc.equals("(Lorg/apache/commons/httpclient/HostConfiguration;" +
            "Lorg/apache/commons/httpclient/HttpMethod;" +
            "Lorg/apache/commons/httpclient/HttpState;)I")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(1);
                invokeStatic(Type.getType(CommonHttpClientHook.class),
                        new Method("checkHttpConnection", "(Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:prometheus-metrics-agent    文件:InjectorFactory.java   
public static List<Injector> createInjectors(Map<MetricType, Metric> metrics, AdviceAdapter adviceAdapter, String className, Type[] argTypes, int access) {
    List<Injector> injectors = new ArrayList<Injector>();

    //handle special case for both exception counter and timer (try catch finally)
    if (metrics.containsKey(ExceptionCounted) && metrics.containsKey(Timed)) {
        injectors.add(new TimedExceptionCountedInjector(
                metrics.get(Timed), 
                metrics.get(ExceptionCounted), 
                adviceAdapter, className, argTypes, access));

        metrics.remove(Timed);
        metrics.remove(ExceptionCounted);
    }

    for (Metric metric : metrics.values()) {
        injectors.add(createInjector(metric, adviceAdapter, className, argTypes, access));
    }

    return injectors;
}
项目:prometheus-metrics-agent    文件:InjectorFactory.java   
public static Injector createInjector(Metric metric, AdviceAdapter adviceAdapter, String className, Type[] argTypes, int access) {
    switch (metric.getType()) {
        case Counted:
            return new CounterInjector(metric, adviceAdapter, className, argTypes, access);

        case Gauged:
            return new GaugeInjector(metric, adviceAdapter, className, argTypes, access);

        case ExceptionCounted:
            return new ExceptionCounterInjector(metric, adviceAdapter, className, argTypes, access);

        case Timed:
            return new TimerInjector(metric, adviceAdapter, className, argTypes, access);

        default:
            throw new IllegalStateException("unknown metric type: " + metric.getType());
    }
}
项目:metrics-agent    文件:InjectorFactory.java   
public static List<Injector> createInjectors(Map<MetricType, Metric> metrics, AdviceAdapter adviceAdapter, Type[] argTypes, int access) {
    List<Injector> injectors = new ArrayList<Injector>();

    //handle special case for both exception counter and timer (try catch finally)
    if (metrics.containsKey(ExceptionCounted) && metrics.containsKey(Timed)) {
        injectors.add(new TimedExceptionCountedInjector(
                metrics.get(Timed), 
                metrics.get(ExceptionCounted), 
                adviceAdapter, argTypes, access));

        metrics.remove(Timed);
        metrics.remove(ExceptionCounted);
    }

    for (Metric metric : metrics.values()) {
        injectors.add(createInjector(metric, adviceAdapter, argTypes, access));
    }

    return injectors;
}
项目:metrics-agent    文件:InjectorFactory.java   
public static Injector createInjector(Metric metric, AdviceAdapter adviceAdapter, Type[] argTypes, int access) {
    switch (metric.getType()) {
        case Counted:
            return new CounterInjector(metric, adviceAdapter, argTypes, access);

        case Gauged:
            return new GaugeInjector(metric, adviceAdapter, argTypes, access);

        case ExceptionCounted:
            return new ExceptionCounterInjector(metric, adviceAdapter, argTypes, access);

        case Timed:
            return new TimerInjector(metric, adviceAdapter, argTypes, access);

        default:
            throw new IllegalStateException("unknown metric type: " + metric.getType());
    }
}
项目:svm-fasttagging    文件:ExtendThread.java   
@Override
public MethodVisitor visitMethod (
    final int access, final String name, final String desc,
    final String signature, final String [] exceptions
) {
    final MethodVisitor mv = super.visitMethod (
        access, name, desc, signature, exceptions
    );

    if ("<init>".equals (name)) {
        // Initialize the field.
        return new AdviceAdapter (Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter () {
                __fd.initialize (__owner, this);
            }
        };
    } else {
        return mv;
    }
}
项目:openrasp    文件:CatalinaRequestHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("parseParameters".equals(name) && "()V".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onParseParameters", "()V"));
            }

        };
    }
    return mv;
}
项目:openrasp    文件:CatalinaOutputBufferHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("close".equals(name) && "()V".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeStatic(Type.getType(AbstractHttpOutputHook.class),
                        new Method("appendResponseData", "(Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:CoyoteAdapterHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.AbstractClassHook#hookMethod(int, String, String, String, String[], MethodVisitor) (String)
 */
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions,
                                   MethodVisitor mv) {
    if ("service".equals(name)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onServiceExit", "()V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:ReflectionHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("invoke".equals(name)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeStatic(Type.getType(ReflectionHook.class),
                        new Method("checkReflection",
                                "(Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:TomcatStartupHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("start")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(TomcatStartupHook.class),
                        new Method("checkTomcatStartup", "()V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:Struts2DispatcherHook.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) {
    if (name.equals("serviceAction") && desc.equals("(Ljavax/servlet/http/HttpServletRequest;"
            + "Ljavax/servlet/http/HttpServletResponse;"
            + "Ljavax/servlet/ServletContext;Lorg/apache/struts2/dispatcher/mapper/ActionMapping;)V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                loadArg(0);
                loadArg(1);
                invokeStatic(Type.getType(ApplicationFilterHook.class),
                        new Method("checkRequest", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"));
            }

            @Override
            protected void onMethodExit(int opcode) {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onServiceExit", "()V"));
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:FileHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.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("listFiles")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeStatic(Type.getType(FileHook.class),
                        new Method("checkListFiles", "(Ljava/io/File;)V"));
            }
        };
    }
    return mv;
}
项目: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;
}
项目:openrasp    文件:SQLDriverManagerHook.java   
/**
 * (none-javadoc)
 *
 * @see com.fuxi.javaagent.hook.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("getConnection") && desc.startsWith("(Ljava/lang/String;Ljava/util/Properties;"
            + "Ljava/lang/Class")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(0);
                loadArg(1);
                invokeStatic(Type.getType(SQLDriverManagerHook.class),
                        new Method("checkSqlConnectionOnEnter", "(Ljava/lang/String;Ljava/util/Properties;)V"));
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("preShieldHook", "()V"));
            }

            @Override
            protected void onMethodExit(int i) {
                if (Opcodes.ATHROW != i) {
                    loadArg(0);
                    loadArg(1);
                    invokeStatic(Type.getType(SQLDriverManagerHook.class),
                            new Method("checkSqlConnectionOnExit", "(Ljava/lang/String;Ljava/util/Properties;)V"));
                }
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("postShieldHook", "()V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:SQLResultSetHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("next") && desc.equals("()Z") && Arrays.equals(exceptions, this.exceptions)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                push(type);
                loadThis();
                invokeStatic(Type.getType(SQLResultSetHook.class),
                        new Method("checkSqlQueryResult", "(Ljava/lang/String;Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:JettyRequestHook.java   
@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;
}
项目:openrasp    文件:JettyServerHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("handle")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                invokeStatic(Type.getType(HookHandler.class),
                        new Method("onServiceExit", "()V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:JettyHttpOutputHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if ("close".equals(name) && "()V".equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeStatic(Type.getType(AbstractHttpOutputHook.class),
                        new Method("appendResponseData", "(Ljava/lang/Object;)V"));
            }
        };
    }
    return mv;
}
项目:openrasp    文件:JettyHttpInputHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, final String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("read")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodExit(int opcode) {
                if (opcode == Opcodes.IRETURN) {
                    if (desc.equals("()I")) {
                        dup();
                        loadThis();
                        invokeStatic(Type.getType(HookHandler.class),
                                new Method("onInputStreamRead", "(ILjava/lang/Object;)V"));
                    } else if (desc.equals("([BII)I")) {
                        dup();
                        loadThis();
                        loadArg(0);
                        loadArg(1);
                        loadArg(2);
                        invokeStatic(Type.getType(HookHandler.class),
                                new Method("onInputStreamRead", "(ILjava/lang/Object;[BII)V"));
                    }
                }
                super.onMethodExit(opcode);
            }
        };
    }
    return mv;
}
项目:openrasp    文件:URLConnectionHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (name.equals("connect") && desc.equals("()V")) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadThis();
                invokeStatic(Type.getType(URLConnectionHook.class),
                        new Method("checkHttpConnection", "(Ljava/net/URLConnection;)V"));
            }
        };
    }
    return mv;
}
项目: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;
}
项目:openrasp    文件:SocketHook.java   
@Override
protected MethodVisitor hookMethod(int access, String name, String desc, String signature, String[] exceptions, MethodVisitor mv) {
    if (("connect").equals(name) && ("(Ljava/net/SocketAddress;I)V").equals(desc)) {
        return new AdviceAdapter(Opcodes.ASM5, mv, access, name, desc) {
            @Override
            protected void onMethodEnter() {
                loadArg(0);
                invokeStatic(Type.getType(SocketHook.class),
                        new Method("checkSocketHost", "(Ljava/net/SocketAddress;)V"));
            }
        };
    }
    return mv;
}
项目:jvm-sandbox    文件:AsmCodeLock.java   
/**
 * 用ASM构建代码锁
 *
 * @param aa             ASM
 * @param beginCodeArray 代码块开始特征数组
 *                       字节码流要求不能破坏执行堆栈
 * @param endCodeArray   代码块结束特征数组
 *                       字节码流要求不能破坏执行堆栈
 */
public AsmCodeLock(AdviceAdapter aa, int[] beginCodeArray, int[] endCodeArray) {
    if (null == beginCodeArray
            || null == endCodeArray
            || beginCodeArray.length != endCodeArray.length) {
        throw new IllegalArgumentException();
    }

    this.aa = aa;
    this.beginCodeArray = beginCodeArray;
    this.endCodeArray = endCodeArray;

}