Search in sources :

Example 11 with MethodNode

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

the class DefaultInvocationResolver method resolveVirtualCalls.

@Override
public Set<MethodNode> resolveVirtualCalls(String owner, String name, String desc, boolean strict) {
    /* find concrete receivers and resolve */
    ClassNode cn = app.findClassNode(owner);
    if (!checkNullClass(cn, owner)) {
        return Collections.emptySet();
    }
    Set<MethodNode> result = new HashSet<>();
    for (ClassNode receiver : app.getClassTree().getAllChildren(cn)) {
        if (!Modifier.isAbstract(receiver.node.access)) {
            // use strict mode = false for incomplete analysis
            MethodNode target = resolve(receiver, name, desc, true);
            if (target == null || Modifier.isAbstract(target.node.access)) {
                throw new IllegalStateException(String.format("Could not find vtarget for %s.%s%s", owner, name, desc));
            }
            result.add(target);
        }
    }
    return result;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode)

Example 12 with MethodNode

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

the class HierarchyMethods method getHierarchyMethodChain.

public Set<MethodNode> getHierarchyMethodChain(ClassNode cn, String name, String desc, boolean exact) {
    ClassTree structures = app.getClassTree();
    Set<MethodNode> foundMethods = new HashSet<>();
    Collection<ClassNode> toSearch = structures.getAllBranches(cn);
    for (ClassNode viable : toSearch) {
        foundMethods.addAll(findMethods(viable, name, desc, exact ? EXACT_TYPES : CONGRUENT_TYPES, VIRTUAL_METHOD | Modifier.ABSTRACT | Opcodes.ACC_BRIDGE, 0));
    }
    return foundMethods;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) ClassTree(org.mapleir.app.service.ClassTree) HashSet(java.util.HashSet)

Example 13 with MethodNode

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

the class Boot method main.

public static void main(String[] args) throws Exception {
    sections = new LinkedList<>();
    logging = true;
    // Load input jar
    // File f = locateRevFile(135);
    File f = new File(args[0]);
    section("Preparing to run on " + f.getAbsolutePath());
    SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(f));
    dl.download();
    String appName = f.getName().substring(0, f.getName().length() - 4);
    ApplicationClassSource app = new ApplicationClassSource(appName, dl.getJarContents().getClassContents());
    // 
    // ApplicationClassSource app = new ApplicationClassSource("test", ClassHelper.parseClasses(CGExample.class));
    // app.addLibraries(new InstalledRuntimeClassSource(app));
    File rtjar = new File(System.getProperty("java.home"), "lib/rt.jar");
    // File androidjar = new File("res/android.jar");
    app.addLibraries(rt(app, rtjar));
    section("Initialising context.");
    IRCache irFactory = new IRCache(ControlFlowGraphBuilder::build);
    AnalysisContext cxt = new BasicAnalysisContext.BasicContextBuilder().setApplication(app).setInvocationResolver(new DefaultInvocationResolver(app)).setCache(irFactory).setApplicationContext(new SimpleApplicationContext(app)).setDataFlowAnalysis(new LiveDataFlowAnalysisImpl(irFactory)).build();
    section("Expanding callgraph and generating cfgs.");
    for (ClassNode cn : cxt.getApplication().iterate()) {
        // continue;
        for (MethodNode m : cn.getMethods()) {
            // if (!m.getName().equals("setRccState"))
            // continue;
            cxt.getIRCache().getFor(m);
        }
    }
    section0("...generated " + cxt.getIRCache().size() + " cfgs in %fs.%n", "Preparing to transform.");
    // do passes
    PassGroup masterGroup = new PassGroup("MasterController");
    for (IPass p : getTransformationPasses()) {
        masterGroup.add(p);
    }
    run(cxt, masterGroup);
    section0("...done transforming in %fs.%n", "Preparing to transform.");
    for (Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        ControlFlowGraph cfg = e.getValue();
        try {
            cfg.verify();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    section("Retranslating SSA IR to standard flavour.");
    for (Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        // if (!mn.getName().equals("openFiles"))
        // continue;
        ControlFlowGraph cfg = e.getValue();
        // CFGUtils.easyDumpCFG(cfg, "pre-destruct");
        try {
            cfg.verify();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        BoissinotDestructor.leaveSSA(cfg);
        // CFGUtils.easyDumpCFG(cfg, "pre-reaalloc");
        LocalsReallocator.realloc(cfg);
        // System.out.println(cfg);
        try {
            cfg.verify();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // System.out.println("Rewriting " + mn.getName());
        (new ControlFlowGraphDumper(cfg, mn)).dump();
    // System.out.println(InsnListUtils.insnListToString(mn.instructions));
    }
    section("Rewriting jar.");
    dumpJar(app, dl, masterGroup, "out/rewritten.jar");
    section("Finished.");
}
Also used : ClassNode(org.mapleir.asm.ClassNode) LiveDataFlowAnalysisImpl(org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl) IRCache(org.mapleir.context.IRCache) AnalysisContext(org.mapleir.context.AnalysisContext) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext) SimpleApplicationContext(org.mapleir.app.client.SimpleApplicationContext) IPass(org.mapleir.deob.IPass) ControlFlowGraphDumper(org.mapleir.ir.codegen.ControlFlowGraphDumper) PassGroup(org.mapleir.deob.PassGroup) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) MethodNode(org.mapleir.asm.MethodNode) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) ControlFlowGraphBuilder(org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader)

Example 14 with MethodNode

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

the class ConstantExpressionReorderPass method accept.

@Override
public PassResult accept(PassContext pcxt) {
    AnalysisContext cxt = pcxt.getAnalysis();
    int delta = 0;
    for (MethodNode m : cxt.getIRCache().getActiveMethods()) {
        ControlFlowGraph ir = cxt.getIRCache().getFor(m);
        delta += transform(ir);
    }
    System.out.println("  swapped " + delta + " constant expression orders.");
    return PassResult.with(pcxt, this).finished(delta).make();
}
Also used : MethodNode(org.mapleir.asm.MethodNode) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) AnalysisContext(org.mapleir.context.AnalysisContext)

Example 15 with MethodNode

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

the class Boot2 method main.

public static void main(String[] args) throws Exception {
    logging = true;
    // Load input jar
    // File f = locateRevFile(135);
    // Load input jar
    // File f = locateRevFile(135);
    File f = new File(args[0]);
    SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(f));
    dl.download();
    String appName = f.getName().substring(0, f.getName().length() - 4);
    ApplicationClassSource app = new ApplicationClassSource(appName, dl.getJarContents().getClassContents());
    // 
    // ApplicationClassSource app = new ApplicationClassSource("test", ClassHelper.parseClasses(CGExample.class));
    // app.addLibraries(new InstalledRuntimeClassSource(app));
    File rtjar = new File(System.getProperty("java.home"), "lib/rt.jar");
    // File androidjar = new File("res/android.jar");
    app.addLibraries(rt(app, rtjar));
    IRCache irFactory = new IRCache(ControlFlowGraphBuilder::build);
    AnalysisContext cxt = new BasicAnalysisContext.BasicContextBuilder().setApplication(app).setInvocationResolver(new DefaultInvocationResolver(app)).setCache(irFactory).setApplicationContext(new SimpleApplicationContext(app)).setDataFlowAnalysis(new LiveDataFlowAnalysisImpl(irFactory)).build();
    for (ClassNode cn : cxt.getApplication().iterate()) {
        // continue;
        for (MethodNode m : cn.getMethods()) {
            // if (!m.name.equals("mapTypes"))
            // continue;
            cxt.getIRCache().getFor(m);
        }
    }
    System.out.println("Generated " + cxt.getIRCache().size() + " cfgs");
    // do passes
    PassGroup masterGroup = new PassGroup("MasterController");
    for (IPass p : getTransformationPasses()) {
        masterGroup.add(p);
    }
    run(cxt, masterGroup);
    for (Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        ControlFlowGraph cfg = e.getValue();
        cfg.verify();
    }
    for (Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        // if (!mn.name.equals("openFiles"))
        // continue;
        ControlFlowGraph cfg = e.getValue();
        // System.out.println(cfg);
        // CFGUtils.easyDumpCFG(cfg, "pre-destruct");
        cfg.verify();
        BoissinotDestructor.leaveSSA(cfg);
        // CFGUtils.easyDumpCFG(cfg, "pre-reaalloc");
        LocalsReallocator.realloc(cfg);
        // CFGUtils.easyDumpCFG(cfg, "post-reaalloc");
        // System.out.println(cfg);
        cfg.verify();
        // System.out.println("Rewriting " + mn.name);
        (new ControlFlowGraphDumper(cfg, mn)).dump();
    // System.out.println(InsnListUtils.insnListToString(mn.instructions));
    }
    dumpJar(app, dl, masterGroup, "out/rewritten.jar");
}
Also used : ClassNode(org.mapleir.asm.ClassNode) LiveDataFlowAnalysisImpl(org.mapleir.deob.dataflow.LiveDataFlowAnalysisImpl) IRCache(org.mapleir.context.IRCache) AnalysisContext(org.mapleir.context.AnalysisContext) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext) SimpleApplicationContext(org.mapleir.app.client.SimpleApplicationContext) IPass(org.mapleir.deob.IPass) ControlFlowGraphDumper(org.mapleir.ir.codegen.ControlFlowGraphDumper) PassGroup(org.mapleir.deob.PassGroup) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) MethodNode(org.mapleir.asm.MethodNode) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) ControlFlowGraphBuilder(org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader)

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