Search in sources :

Example 36 with ClassNode

use of org.mapleir.asm.ClassNode 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 37 with ClassNode

use of org.mapleir.asm.ClassNode 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 38 with ClassNode

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

the class ExceptionFixerPass method accept.

@Override
public PassResult accept(PassContext cxt) {
    final AtomicInteger counter = new AtomicInteger();
    for (ControlFlowGraph value : cxt.getAnalysis().getIRCache().values()) {
        for (ExceptionRange<BasicBlock> range : value.getRanges()) {
            if (range.getTypes().size() <= 1)
                continue;
            ClassNode superType = null;
            for (Type type : range.getTypes()) {
                ClassNode classNode = cxt.getAnalysis().getApplication().findClassNode(type.getClassName());
                if (classNode == null) {
                    try {
                        classNode = ClassHelper.create(type.getClassName());
                    } catch (IOException e) {
                        continue;
                    }
                }
                if (superType == null) {
                    superType = classNode;
                } else {
                    superType = cxt.getAnalysis().getApplication().getClassTree().getCommonSuperType(superType.getName(), classNode.getName());
                }
            }
            final Set<Type> types = new HashSet<>(Collections.singleton(superType == null ? TypeUtils.OBJECT_TYPE : Type.getObjectType(superType.getName())));
            range.setTypes(types);
            counter.incrementAndGet();
        }
    }
    logger.info("[*] Successfully fixed" + counter.get() + " exception ranges!");
    return PassResult.with(cxt, this).finished().make();
}
Also used : ClassNode(org.mapleir.asm.ClassNode) Type(org.objectweb.asm.Type) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) BasicBlock(org.mapleir.ir.cfg.BasicBlock) IOException(java.io.IOException)

Example 39 with ClassNode

use of org.mapleir.asm.ClassNode 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)

Example 40 with ClassNode

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

the class Boot method rt.

private static LibraryClassSource rt(ApplicationClassSource app, File rtjar) throws IOException {
    section("Loading " + rtjar.getName() + " from " + rtjar.getAbsolutePath());
    SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(rtjar));
    dl.download();
    return new LibraryClassSource(app, dl.getJarContents().getClassContents());
}
Also used : ClassNode(org.mapleir.asm.ClassNode) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) LibraryClassSource(org.mapleir.app.service.LibraryClassSource) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader)

Aggregations

ClassNode (org.mapleir.asm.ClassNode)45 MethodNode (org.mapleir.asm.MethodNode)24 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)16 AnalysisContext (org.mapleir.context.AnalysisContext)13 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)11 JarInfo (org.topdank.byteengineer.commons.data.JarInfo)11 SingleJarDownloader (org.topdank.byteio.in.SingleJarDownloader)11 IRCache (org.mapleir.context.IRCache)8 ControlFlowGraphBuilder (org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder)8 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)7 LibraryClassSource (org.mapleir.app.service.LibraryClassSource)7 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)7 IPass (org.mapleir.deob.IPass)7 PassGroup (org.mapleir.deob.PassGroup)7 LiveDataFlowAnalysisImpl (org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl)7 ControlFlowGraphDumper (org.mapleir.ir.codegen.ControlFlowGraphDumper)7 BasicBlock (org.mapleir.ir.cfg.BasicBlock)6 JarOutputStream (java.util.jar.JarOutputStream)5 Expr (org.mapleir.ir.code.Expr)5 Stmt (org.mapleir.ir.code.Stmt)5