Search in sources :

Example 26 with MethodNode

use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.

the class ReflectiveFunctorFactory method compare.

@Override
public EvaluationFunctor<Number> compare(Type lt, Type rt, ComparisonExpr.ValueComparisonType type) {
    String name = lt.getClassName() + type.name() + rt.getClassName() + "RETint";
    if (cache.containsKey(name)) {
        return _get(name);
    }
    String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")I";
    MethodNode m = makeBase(name, desc);
    {
        Type opType = TypeUtils.resolveBinOpType(lt, rt);
        InsnList insns = new InsnList();
        insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(lt), 0));
        cast(insns, lt, opType);
        insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(rt), lt.getSize()));
        cast(insns, rt, opType);
        int op;
        if (opType == Type.DOUBLE_TYPE) {
            op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.DCMPG : Opcodes.DCMPL;
        } else if (opType == Type.FLOAT_TYPE) {
            op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.FCMPG : Opcodes.FCMPL;
        } else if (opType == Type.LONG_TYPE) {
            op = Opcodes.LCMP;
        } else {
            throw new IllegalArgumentException();
        }
        insns.add(new InsnNode(op));
        insns.add(new InsnNode(Opcodes.IRETURN));
        m.node.instructions = insns;
    }
    return buildBridge(m);
}
Also used : VarInsnNode(org.objectweb.asm.tree.VarInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) Type(org.objectweb.asm.Type) MethodNode(org.mapleir.asm.MethodNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 27 with MethodNode

use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.

the class ConcreteStaticInvocationPass method accept.

@Override
public PassResult accept(PassContext pcxt) {
    AnalysisContext cxt = pcxt.getAnalysis();
    int fixed = 0;
    InvocationResolver resolver = cxt.getInvocationResolver();
    for (ClassNode cn : cxt.getApplication().iterate()) {
        for (MethodNode mn : cn.getMethods()) {
            ControlFlowGraph cfg = cxt.getIRCache().getFor(mn);
            for (BasicBlock b : cfg.vertices()) {
                for (Stmt stmt : b) {
                    for (Expr e : stmt.enumerateOnlyChildren()) {
                        if (e.getOpcode() == Opcode.INVOKE) {
                            InvocationExpr invoke = (InvocationExpr) e;
                            if (invoke.getCallType() == InvocationExpr.CallType.STATIC) {
                                MethodNode invoked = resolver.resolveStaticCall(invoke.getOwner(), invoke.getName(), invoke.getDesc());
                                if (invoked != null) {
                                    if (!invoked.getOwner().equals(invoke.getOwner())) {
                                        invoke.setOwner(invoked.getOwner());
                                        fixed++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    System.out.printf("  corrected %d dodgy static calls.%n", fixed);
    return PassResult.with(pcxt, this).finished().make();
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Expr(org.mapleir.ir.code.Expr) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) InvocationResolver(org.mapleir.app.service.InvocationResolver) BasicBlock(org.mapleir.ir.cfg.BasicBlock) AnalysisContext(org.mapleir.context.AnalysisContext) InvocationExpr(org.mapleir.ir.code.expr.invoke.InvocationExpr) Stmt(org.mapleir.ir.code.Stmt)

Example 28 with MethodNode

use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.

the class DeadCodeEliminationPass method accept.

@Override
public PassResult accept(PassContext pcxt) {
    AnalysisContext cxt = pcxt.getAnalysis();
    deadBlocks = 0;
    immediateJumps = 0;
    deadLocals = 0;
    for (ClassNode cn : cxt.getApplication().iterate()) {
        for (MethodNode m : cn.getMethods()) {
            ControlFlowGraph cfg = cxt.getIRCache().getFor(m);
            /* dead blocks */
            process(cfg);
        }
    }
    System.out.printf("  removed %d dead blocks.%n", deadBlocks);
    System.out.printf("  converted %d immediate jumps.%n", immediateJumps);
    System.out.printf("  eliminated %d dead locals.%n", deadLocals);
    return PassResult.with(pcxt, this).finished(deadBlocks + immediateJumps).make();
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) AnalysisContext(org.mapleir.context.AnalysisContext)

Example 29 with MethodNode

use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.

the class IRCallTracer method traceInvocation.

private void traceInvocation(MethodNode m, Invocation invoke) {
    Set<MethodNode> targets;
    try {
        targets = invoke.resolveTargets(resolver);
    } catch (Throwable e) {
        LOGGER.warn(String.format("can't resolve call to %s.%s %s%s%s", invoke.getOwner(), invoke.getName(), invoke.getDesc(), invoke.isStatic() ? "(static)" : "", invoke.isDynamic() ? "(dynamic)" : ""));
        LOGGER.warn(String.format("   call from %s", m));
        return;
    }
    if (targets.size() != 0) {
        for (MethodNode vtarg : targets) {
            trace(vtarg);
            processedInvocation(m, vtarg, invoke);
        }
    } else {
        LOGGER.error(String.format("can't resolve call to %s.%s %s%s%s", invoke.getOwner(), invoke.getName(), invoke.getDesc(), invoke.isStatic() ? "(static)" : "", invoke.isDynamic() ? "(dynamic)" : ""));
        LOGGER.error(String.format("   call from %s", m));
    }
}
Also used : MethodNode(org.mapleir.asm.MethodNode)

Example 30 with MethodNode

use of org.mapleir.asm.MethodNode in project maple-ir by LLVM-but-worse.

the class CallgraphPruningPass method accept.

@Override
public PassResult accept(PassContext cxt) {
    int delta = 0;
    Set<MethodNode> active = cxt.getAnalysis().getIRCache().getActiveMethods();
    for (ClassNode cn : cxt.getAnalysis().getApplication().iterate()) {
        ListIterator<MethodNode> lit = cn.getMethods().listIterator();
        while (lit.hasNext()) {
            MethodNode m = lit.next();
            if (!active.contains(m)) {
                lit.remove();
                delta++;
            }
        }
    }
    System.out.println("Removed " + delta + " dead methods.");
    return PassResult.with(cxt, this).finished().make();
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode)

Aggregations

MethodNode (org.mapleir.asm.MethodNode)36 ClassNode (org.mapleir.asm.ClassNode)21 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)17 AnalysisContext (org.mapleir.context.AnalysisContext)13 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)8 Expr (org.mapleir.ir.code.Expr)8 Stmt (org.mapleir.ir.code.Stmt)7 BasicBlock (org.mapleir.ir.cfg.BasicBlock)6 Type (org.objectweb.asm.Type)6 InvocationResolver (org.mapleir.app.service.InvocationResolver)5 IRCache (org.mapleir.context.IRCache)5 ControlFlowGraphBuilder (org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder)5 InsnList (org.objectweb.asm.tree.InsnList)5 InsnNode (org.objectweb.asm.tree.InsnNode)5 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)5 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)5 HashSet (java.util.HashSet)4 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)4 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)4 IPass (org.mapleir.deob.IPass)4