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

项目: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    文件: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;
}
项目:GraphiteMappings    文件:Mappings.java   
public void putMethod(MethodRef a, MethodRef b) {
    Method descriptor = new Method(b.getMethodName(), b.getMethodDesc());
    TypeNameEnforcer returnType = new TypeNameEnforcer(descriptor.getReturnType()
            .getClassName());
    if (classMappings.containsKey(returnType.getJvmStandard())) {
        returnType = new TypeNameEnforcer(classMappings.get(returnType.getJvmStandard()));
    }
    List<TypeNameEnforcer> parameterTypes = new ArrayList<>();
    for (Type type : descriptor.getArgumentTypes()) {
        if (classMappings.containsKey(new TypeNameEnforcer(type.getClassName()).getJvmStandard())) {
            parameterTypes.add(new TypeNameEnforcer(classMappings.get(new TypeNameEnforcer
                    (type.getClassName()).getJvmStandard())));
        } else {
            parameterTypes.add(new TypeNameEnforcer(type.getClassName()));
        }
    }
    MethodRef newB = new MethodRef(b.getClassName(), b.getMethodName(), createDescriptor
            (returnType, parameterTypes));
    methodMappings.put(a, newB);
}
项目:javametrics    文件:ServletCallBackAdapter.java   
/**
 * Inject a callback to our servlet handler.
 * 
 * @param method
 */
private void injectServletCallback(String method) {
    Label tryStart = new Label();
    Label tryEnd = new Label();
    Label catchStart = new Label();
    Label catchEnd = new Label();

    visitTryCatchBlock(tryStart, tryEnd, catchStart, "java/lang/NoClassDefFoundError");
    mark(tryStart); // try {
    loadArgs();
    invokeStatic(Type.getType(SERVLET_CALLBACK_TYPE), Method.getMethod(method));
    mark(tryEnd); // }
    visitJumpInsn(GOTO, catchEnd);
    mark(catchStart); // catch() {
    pop();
    mark(catchEnd); // }
}
项目:dacapobench    文件:SystemInstrument.java   
public void visitEnd() {
    if (! doneAddField) {
        doneAddField = true;

        super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, CLASS_FIELD, Type.getDescriptor(Agent.class), null, null);
    }

    if (! doneAddMethod) {
        doneAddMethod = true;

        GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(LOG_CLASS_METHOD, LOG_CLASS_SIGNATURE), LOG_CLASS_SIGNATURE, new Type[] {}, this);

        Label target = mg.newLabel();
        mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
        mg.ifNull(target);
        mg.push(LOG_INTERNAL_TYPE);
        mg.putStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
        mg.mark(target);
        mg.getStatic(JAVA_LANG_SYSTEM_TYPE, CLASS_FIELD, JAVA_LANG_CLASS_TYPE);
        mg.returnValue();
    }

    super.visitEnd();
}
项目:dacapobench    文件:CallChainInstrument.java   
@SuppressWarnings("unchecked")
public void visitEnd() {
    if (!done && found) {
        done = true;
        try {
            GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, new Method(LOG_INTERNAL_METHOD, LOG_METHOD_SIGNATURE), LOG_METHOD_SIGNATURE, new Type[] {}, this);

            Label start = mg.mark();
            mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME)));
            mg.returnValue();
            Label end   = mg.mark();
            mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
            mg.returnValue();

            mg.endMethod();
        } catch (NoSuchMethodException nsme) {
            System.err.println("Unable to find Agent.rlogCallChain method");
            System.err.println("M:"+nsme);
            nsme.printStackTrace();
        }
    }

    super.visitEnd();
}
项目:dacapobench    文件:ClinitInstrument.java   
@SuppressWarnings("unchecked")
public void visitEnd() {
    if (!foundClinit && instrument()) {
        // didn't find <clinit> so lets make one
        try {
            GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, new Method(CLINIT_NAME, CLINIT_SIGNATURE), CLINIT_SIGNATURE, new Type[] {}, this);

            Label start = mg.mark();
            mg.push(className);
            mg.invokeStatic(LOG_INTERNAL_TYPE, Method.getMethod(LOG_INTERNAL_CLASS.getMethod(LOG_METHOD_NAME, String.class)));
            Label end   = mg.mark();
            mg.returnValue();

            mg.catchException(start, end, JAVA_LANG_THROWABLE_TYPE);
            mg.returnValue();

            mg.endMethod();
        } catch (NoSuchMethodException nsme) {
            System.out.println("Unable to find Agent.reportClass method");
        }
    }

    super.visitEnd();
}
项目:Aceso    文件:IncrementalChangeVisitor.java   
/**
 * For calls to constructors in the same package, calls are rewritten to use reflection
 * to create the instance (see above, the NEW and DUP instructions are also removed) using
 * the following pseudo code.
 * <p/>
 * before:
 * <code>
 * $value = new $type(arg1, arg2);
 * </code>
 * after:
 * <code>
 * $value = ($type)$package/AndroidInstantRuntime.newForClass(new Object[] {arg1, arg2 },
 * new Class[]{ String.class, Integer.class }, $type.class);
 * </code>
 */
private boolean handleConstructor(String owner, String name, String desc) {

    AccessRight accessRight = getMethodAccessRight(owner, name, desc);
    if (accessRight != AccessRight.PUBLIC) {
        Type expectedType = Type.getType("L" + owner + ";");
        pushMethodRedirectArgumentsOnStack(name, desc);

        // pop the name, we don't need it.
        pop();
        visitLdcInsn(expectedType);

        invokeStatic(RUNTIME_TYPE, Method.getMethod(
                "Object newForClass(Object[], Class[], Class)"));

        checkCast(expectedType);
        ByteCodeUtils.unbox(this, expectedType);
        return true;
    } else {
        return false;
    }


}
项目:Aceso    文件:IntSwitch.java   
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (String string : strings) {
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
项目:Aceso    文件:IncrementalSupportVisitor.java   
@Override
public void visitCode() {
    if (!disableRedirection) {
        // Labels cannot be used directly as they are volatile between different visits,
        // so we must use LabelNode and resolve before visiting for better performance.
        for (Redirection redirection : redirections) {
            resolvedRedirections.put(redirection.getPosition().getLabel(), redirection);
        }

        super.visitLabel(start);
        change = newLocal(MTD_MAP_TYPE);

        push(new Integer(AcesoProguardMap.instance().getClassIndex(visitedClassName)));
        push(new Integer(AcesoProguardMap.instance().getMtdIndex(visitedClassName, IncrementalTool.getMtdSig(name, desc))));
        invokeStatic(IncrementalVisitor.MTD_MAP_TYPE, Method.getMethod("com.android.tools.fd.runtime.IncrementalChange get(int,int)"));

        storeLocal(change);

        redirectAt(start);
    }
    super.visitCode();
}
项目:fastAOP    文件:ExceptionHookMethodAdapter.java   
@Override
public void visitLabel(Label label) {
    //这个super.xx必须放到第一行
    super.visitLabel(label);
    ArrayList<String> exceptions = matchHandle.get(label);
    if(label != null && exceptions != null){
        logger.log(Level.INFO,"instrument "+exceptions);
        Label matched = new Label();
        Label end = new Label();
        //捕获的是目标exception的实例才进行处理
        final int N = exceptions.size() - 1;
        if (N >= 1) {
            for (int i = 0; i < N; i++) {
                compareInstance(IFNE, exceptions.get(i), matched);
            }
        }
        compareInstance(IFEQ, exceptions.get(N), end);
        visitLabel(matched);
        dup();
        invokeStatic(Type.getObjectType("test/github/monitor/Monitor")
                , new Method("pushException", "(Ljava/lang/Throwable;)V"));
        visitLabel(end);
    }
}
项目:BytecodeCallHierarchyScanner    文件:JavaScanner.java   
/**
 * Find call hierarchy of <b>methodSignature</b> of the class <b>className</b> or any subclass
 * @param className the full class name. ex: "java/lang/Integer"
 * @param methodSignature method signature. ex: "java.lang.Integer methodName(java.lang.Integer)"
 * @return a CallHierarchy starting with the parameter method
 * @throws IOException if an I/O error has occurred
 */
public CallHierarchy findCallHierarchy( String className, String methodSignature ) throws IOException {
    String methodName = "";
    String methodDesc = "";
    if( methodSignature != null ){
        Method method = Method.getMethod(methodSignature);
        methodName = method.getName();
        methodDesc = method.getDescriptor();
    }

    CallHierarchy callHierarchy = new CallHierarchy(null, className, methodName, methodDesc);

    findCallHierarchy( callHierarchy );

    return callHierarchy;
}
项目:agent-callback    文件:CallFactory.java   
public static void establishCallback(ClassNode cn, MethodNode mn) {
    if (!mn.desc.startsWith("()")) {
        MethodNode blank = new MethodNode();
        Method method = new Method(mn.name, mn.desc);
        GeneratorAdapter adapter = new GeneratorAdapter(mn.access, method, blank);
        adapter.visitCode();
        adapter.push(cn.name + "." + mn.name + "  " + mn.desc);
        adapter.loadArgArray();
        adapter.invokeStatic(Type.getType(CallFactory.class), new Method("testInvoke",
                "(Ljava/lang/String;[Ljava/lang/Object;)V"));
        for (AbstractInsnNode ain : mn.instructions.toArray()) {
            if (ain instanceof VarInsnNode) {
                mn.instructions.insertBefore(ain, blank.instructions);
                return;
            }
        }
    }
}
项目:AnoleFix    文件:IncrementalChangeVisitor.java   
/**
 * For calls to constructors in the same package, calls are rewritten to use reflection
 * to create the instance (see above, the NEW & DUP instructions are also removed) using
 * the following pseudo code.
 * <p/>
 * before:
 * <code>
 * $value = new $type(arg1, arg2);
 * </code>
 * after:
 * <code>
 * $value = ($type)$package/AndroidInstantRuntime.newForClass(new Object[] {arg1, arg2 },
 * new Class[]{ String.class, Integer.class }, $type.class);
 * </code>
 */
private boolean handleConstructor(String owner, String name, String desc) {

    if (isInSamePackage(owner)) {

        Type expectedType = Type.getType("L" + owner + ";");
        pushMethodRedirectArgumentsOnStack(name, desc);

        // pop the name, we don't need it.
        pop();
        visitLdcInsn(expectedType);

        invokeStatic(RUNTIME_TYPE, Method.getMethod(
                "Object newForClass(Object[], Class[], Class)"));

        checkCast(expectedType);
        ByteCodeUtils.unbox(this, expectedType);
        return true;
    } else {
        return false;
    }
}
项目:AnoleFix    文件:InstantRunMethodVerifier.java   
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc,
                            boolean itf) {

    Type receiver = Type.getType(owner);
    if (!incompatibleChange.isPresent()) {
        if (opcode == Opcodes.INVOKEVIRTUAL && blackListedMethods.containsKey(receiver)) {
            for (Method method : blackListedMethods.get(receiver)) {
                if (method.getName().equals(name) && method.getDescriptor().equals(desc)) {
                    incompatibleChange = Optional.of(InstantRunVerifierStatus.REFLECTION_USED);
                }
            }
        }
    }

    super.visitMethodInsn(opcode, owner, name, desc, itf);
}
项目:AnoleFix    文件:StringSwitch.java   
/**
 * Emit code for a string if-else block.
 *
 *     if (s.equals("collided_method1")) {
 *         visit(s);
 *     } else if (s.equals("collided_method2")) {
 *         visit(s);
 *     }
 *
 * In the most common case of just one string, this degenerates to:
 *
 *      visit(s)
 *
 */
private void visitx(GeneratorAdapter mv, List<String> strings) {
    if (strings.size() == 1) {
        visitCase(strings.get(0));
        return;
    }
    for (int i = 0; i < strings.size(); ++i) {
        String string = strings.get(i);
        Label label = new Label();
        visitString();
        mv.visitLdcInsn(string);
        mv.invokeVirtual(STRING_TYPE, Method.getMethod("boolean equals(Object)"));
        mv.visitJumpInsn(Opcodes.IFEQ, label);
        visitCase(string);
        mv.visitLabel(label);
    }

    visitDefault();
}
项目:fsharpadvent2016    文件:Compiler.java   
public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){
    Method ms = new Method("invokeStatic", getReturnType(), paramtypes);
    if(variadic)
        {
        for(int i = 0; i < paramclasses.length - 1; i++)
            {
            Expr e = (Expr) args.nth(i);
            if(maybePrimitiveType(e) == paramclasses[i])
                {
                ((MaybePrimitiveExpr) e).emitUnboxed(C.EXPRESSION, objx, gen);
                }
            else
                {
                e.emit(C.EXPRESSION, objx, gen);
                HostExpr.emitUnboxArg(objx, gen, paramclasses[i]);
                }
            }
        IPersistentVector restArgs = RT.subvec(args,paramclasses.length - 1,args.count());
        MethodExpr.emitArgsAsArray(restArgs,objx,gen);
        gen.invokeStatic(Type.getType(ArraySeq.class), Method.getMethod("clojure.lang.ArraySeq create(Object[])"));
        }
    else
        MethodExpr.emitTypedArgs(objx, gen, paramclasses, args);

    gen.invokeStatic(target, ms);
}
项目:fsharpadvent2016    文件:Compiler.java   
void emitArgsAndCall(int firstArgToEmit, C context, ObjExpr objx, GeneratorAdapter gen){
    for(int i = firstArgToEmit; i < Math.min(MAX_POSITIONAL_ARITY, args.count()); i++)
        {
        Expr e = (Expr) args.nth(i);
        e.emit(C.EXPRESSION, objx, gen);
        }
    if(args.count() > MAX_POSITIONAL_ARITY)
        {
        PersistentVector restArgs = PersistentVector.EMPTY;
        for(int i = MAX_POSITIONAL_ARITY; i < args.count(); i++)
            {
            restArgs = restArgs.cons(args.nth(i));
            }
        MethodExpr.emitArgsAsArray(restArgs, objx, gen);
        }
    gen.visitLineNumber(line, gen.mark());

    if(context == C.RETURN)
        {
        ObjMethod method = (ObjMethod) METHOD.deref();
        method.emitClearLocals(gen);
        }

    gen.invokeInterface(IFN_TYPE, new Method("invoke", OBJECT_TYPE, ARG_TYPES[Math.min(MAX_POSITIONAL_ARITY + 1,
                                                                                       args.count())]));
}
项目:fsharpadvent2016    文件:Compiler.java   
protected void emitMethods(ClassVisitor cv){
    //override of invoke/doInvoke for each method
    for(ISeq s = RT.seq(methods); s != null; s = s.next())
        {
        ObjMethod method = (ObjMethod) s.first();
        method.emit(this, cv);
        }

    if(isVariadic())
        {
        GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
                                                    Method.getMethod("int getRequiredArity()"),
                                                    null,
                                                    null,
                                                    cv);
        gen.visitCode();
        gen.push(variadicMethod.reqParms.count());
        gen.returnValue();
        gen.endMethod();
        }
}
项目:eclojure    文件:Compiler.java   
public void emitUnboxed(C context, ObjExpr objx, GeneratorAdapter gen){
    Method ms = new Method("invokeStatic", getReturnType(), paramtypes);
    if(variadic)
        {
        for(int i = 0; i < paramclasses.length - 1; i++)
            {
            Expr e = (Expr) args.nth(i);
            if(maybePrimitiveType(e) == paramclasses[i])
                {
                ((MaybePrimitiveExpr) e).emitUnboxed(C.EXPRESSION, objx, gen);
                }
            else
                {
                e.emit(C.EXPRESSION, objx, gen);
                HostExpr.emitUnboxArg(objx, gen, paramclasses[i]);
                }
            }
        IPersistentVector restArgs = RT.subvec(args,paramclasses.length - 1,args.count());
        MethodExpr.emitArgsAsArray(restArgs,objx,gen);
        gen.invokeStatic(Type.getType(ArraySeq.class), Method.getMethod("clojure.lang.ArraySeq create(Object[])"));
        }
    else
        MethodExpr.emitTypedArgs(objx, gen, paramclasses, args);

    gen.invokeStatic(target, ms);
}
项目:eclojure    文件:Compiler.java   
void emitArgsAndCall(int firstArgToEmit, C context, ObjExpr objx, GeneratorAdapter gen){
    for(int i = firstArgToEmit; i < Math.min(MAX_POSITIONAL_ARITY, args.count()); i++)
        {
        Expr e = (Expr) args.nth(i);
        e.emit(C.EXPRESSION, objx, gen);
        }
    if(args.count() > MAX_POSITIONAL_ARITY)
        {
        PersistentVector restArgs = PersistentVector.EMPTY;
        for(int i = MAX_POSITIONAL_ARITY; i < args.count(); i++)
            {
            restArgs = restArgs.cons(args.nth(i));
            }
        MethodExpr.emitArgsAsArray(restArgs, objx, gen);
        }
    gen.visitLineNumber(line, gen.mark());

    if(context == C.RETURN)
        {
        ObjMethod method = (ObjMethod) METHOD.deref();
        method.emitClearLocals(gen);
        }

    gen.invokeInterface(IFN_TYPE, new Method("invoke", OBJECT_TYPE, ARG_TYPES[Math.min(MAX_POSITIONAL_ARITY + 1,
                                                                                       args.count())]));
}
项目:eclojure    文件:Compiler.java   
protected void emitMethods(ClassVisitor cv){
    //override of invoke/doInvoke for each method
    for(ISeq s = RT.seq(methods); s != null; s = s.next())
        {
        ObjMethod method = (ObjMethod) s.first();
        method.emit(this, cv);
        }

    if(isVariadic())
        {
        GeneratorAdapter gen = new GeneratorAdapter(ACC_PUBLIC,
                                                    Method.getMethod("int getRequiredArity()"),
                                                    null,
                                                    null,
                                                    cv);
        gen.visitCode();
        gen.push(variadicMethod.reqParms.count());
        gen.returnValue();
        gen.endMethod();
        }
}
项目:salta    文件:FixedConstructorRecipeInstantiator.java   
private Class<?> compileDirect(GeneratorAdapter mv, MethodCompilationContext compilationContext) {

        mv.newInstance(Type.getType(constructor.getDeclaringClass()));
        mv.dup();

        // push dependencies

        for (int i = 0; i < argumentDependencies.size(); i++) {
            SupplierRecipe dependency = argumentDependencies.get(i);
            Class<?> tosType = dependency.compile(compilationContext);
            Class<?> argType = constructor.getParameterTypes()[i];
            if (!argType.isAssignableFrom(tosType)) {
                if (argType.isPrimitive())
                    mv.unbox(Type.getType(argType));
                else
                    mv.checkCast(Type.getType(argType));
            }
        }

        // call constructor
        mv.invokeConstructor(Type.getType(constructor.getDeclaringClass()), Method.getMethod(constructor));

        return constructor.getDeclaringClass();
    }
项目:astava    文件:MethodGenerator.java   
public static void generate(MethodNode methodNode, BiConsumer<MethodNode, GeneratorAdapter> bodyGenerator) {
    methodNode.visitCode();

    Method m = new Method(methodNode.name, methodNode.desc);
    GeneratorAdapter generator;
    try {
        generator = new GeneratorAdapter(methodNode.access, m, methodNode);
    } catch(Exception e) {
        generator = null;
    }

    bodyGenerator.accept(methodNode, generator);

    methodNode.visitEnd();
    methodNode.visitMaxs(0, 0);
    //labelScope.verify();
}
项目:astava    文件:MethodGenerator.java   
private String populateMethodNewInstance(
    MethodNode methodNode, InsnList originalInstructions, GeneratorAdapter generator, GenerateScope scope,
    String type, List<String> parameterTypes, List<ExpressionDom> arguments,
    int codeLevel, Hashtable<Object, Label> astLabelToASMLabelMap) {
    String returnType = type;

    generator.newInstance(Type.getType(type));
    generator.dup();
    arguments.forEach(a ->
        populateMethodExpression(methodNode, originalInstructions, generator, a, null, true, scope, astLabelToASMLabelMap));
    generator.invokeConstructor(Type.getType(type), new Method("<init>", Descriptor.getMethodDescriptor(parameterTypes, Descriptor.VOID)));

    if(codeLevel == CODE_LEVEL_STATEMENT) {
        generator.pop();
        returnType = Descriptor.VOID;
    }

    return returnType;
}
项目:Lucee4    文件:ComponentUtil.java   
/**
 * check if one of the children is changed
 * @param component
 * @param pc
 * @param clazz
 * @return return true if children has changed
 */
private static boolean hasChangesOfChildren(long last,PageContext pc, Class clazz) {

    java.lang.reflect.Method[] methods = clazz.getMethods();
    java.lang.reflect.Method method;
    Class[] params;
    for(int i=0;i<methods.length;i++){
        method=methods[i];
        if(method.getDeclaringClass()==clazz){
            if(_hasChangesOfChildren(pc,   last,method.getReturnType())) return true;
            params = method.getParameterTypes();
            for(int y=0;y<params.length;y++){
                if(_hasChangesOfChildren(pc,  last, params[y])) return true;
            }
        }
    }
    return false;
}
项目:Lucee4    文件:ComponentUtil.java   
private static boolean _hasChangesOfChildren(PageContext pc, long last, Class clazz) {
    clazz=ClassUtil.toComponentType(clazz);
    java.lang.reflect.Method m = getComplexTypeMethod(clazz);
    if(m==null) return false;
    try {
        String path=Caster.toString(m.invoke(null, new Object[0]));
        Resource res = ResourceUtil.toResourceExisting(pc, path);
        if(last<res.lastModified()) {
            return true;
        }
    } 
    catch (Exception e) {
        return true;
    }
    // possible that a child of the Cmplex Object is also a complex object
    return hasChangesOfChildren(last, pc, clazz);
}