Search in sources :

Example 31 with ClassNode

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

the class DefaultInvocationResolver method findStaticField.

// FIXME: these are taken directly from the old resolver
@Override
public FieldNode findStaticField(String owner, String name, String desc) {
    Set<FieldNode> set = new HashSet<>();
    ClassNode cn = app.findClassNode(owner);
    /* we do this because static fields can be in
		 * interfaces. */
    if (cn != null) {
        Set<ClassNode> lvl = new HashSet<>();
        lvl.add(cn);
        for (; ; ) {
            if (lvl.size() == 0) {
                break;
            }
            Set<FieldNode> lvlSites = new HashSet<>();
            for (ClassNode c : lvl) {
                for (FieldNode f : c.getFields()) {
                    if (Modifier.isStatic(f.node.access) && f.getName().equals(name) && f.getDesc().equals(desc)) {
                        lvlSites.add(f);
                    }
                }
            }
            if (lvlSites.size() > 1) {
                LOGGER.info(String.format("(warn) resolved %s.%s %s to %s", owner, name, desc, lvlSites));
            }
            if (lvlSites.size() > 0) {
                set.addAll(lvlSites);
                break;
            }
            Set<ClassNode> newLvl = new HashSet<>();
            for (ClassNode c : lvl) {
                ClassNode sup = app.findClassNode(c.node.superName);
                if (sup != null) {
                    newLvl.add(sup);
                }
                for (String iface : c.node.interfaces) {
                    ClassNode ifaceN = app.findClassNode(iface);
                    if (ifaceN != null) {
                        newLvl.add(ifaceN);
                    }
                }
            }
            lvl.clear();
            lvl = newLvl;
        }
    }
    if (set.size() > 1) {
        throw new UnsupportedOperationException(String.format("multi dispatch?: %s.%s %s results:%s", owner, name, desc, set));
    } else if (set.size() == 1) {
        return set.iterator().next();
    } else {
        return null;
    }
}
Also used : ClassNode(org.mapleir.asm.ClassNode) FieldNode(org.mapleir.asm.FieldNode)

Example 32 with ClassNode

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

the class HierarchyMethods method debugCong.

private void debugCong(String expected, String actual) {
    Type eR = Type.getReturnType(expected);
    Type aR = Type.getReturnType(actual);
    System.err.println("eR: " + eR);
    System.err.println("aR: " + aR);
    System.err.println("eq: " + (eR == aR));
    ClassNode eCn = app.findClassNode(eR.getInternalName());
    ClassNode aCn = app.findClassNode(aR.getInternalName());
    System.err.println("eCn: " + eCn.getName());
    System.err.println("aCn: " + aCn.getName());
    System.err.println(app.getClassTree().getAllParents(aCn));
    System.err.println("eCn parent of aCn?: " + app.getClassTree().getAllParents(aCn).contains(eCn));
    System.err.println("aCn child of eCn?: " + app.getClassTree().getAllChildren(eCn).contains(aCn));
}
Also used : ClassNode(org.mapleir.asm.ClassNode) Type(org.objectweb.asm.Type)

Example 33 with ClassNode

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

the class RunCommand method rt.

private LibraryClassSource rt(ApplicationClassSource app, File rtjar) throws IOException {
    logger.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)

Example 34 with ClassNode

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

the class RunCommand method call.

@Override
public Integer call() throws Exception {
    if (input == null) {
        logger.print("Fatal! Failed to find input jar!");
        return 1;
    }
    // Initialization
    logger.section("Preparing to run on " + input.getAbsolutePath());
    SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(input));
    dl.download();
    String appName = input.getName().substring(0, input.getName().length() - 4);
    ApplicationClassSource app = new ApplicationClassSource(appName, dl.getJarContents().getClassContents());
    if (output == null) {
        output = new File(appName + "-out.jar");
    }
    logger.section("Importing runtime...");
    if (runtime == null) {
        runtime = new File(System.getProperty("java.home"), "lib/rt.jar");
    }
    app.addLibraries(rt(app, runtime));
    logger.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();
    logger.section("Expanding callgraph and generating cfgs.");
    for (ClassNode cn : cxt.getApplication().iterate()) {
        for (MethodNode m : cn.getMethods()) {
            cxt.getIRCache().getFor(m);
        }
    }
    logger.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);
    logger.section0("...done transforming in %fs.%n", "Preparing to transform.");
    for (Map.Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        ControlFlowGraph cfg = e.getValue();
        cfg.verify();
    }
    logger.section("Retranslating SSA IR to standard flavour.");
    for (Map.Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        // if (!mn.getName().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.getName());
        (new ControlFlowGraphDumper(cfg, mn)).dump();
    // System.out.println(InsnListUtils.insnListToString(mn.instructions));
    }
    logger.section("Rewriting jar.");
    dumpJar(app, dl, masterGroup, output.getPath());
    logger.section("Finished.");
    return 0;
}
Also used : ClassNode(org.mapleir.asm.ClassNode) DefaultInvocationResolver(org.mapleir.DefaultInvocationResolver) 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 35 with ClassNode

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

the class DataFlowDemoBoot 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("res/jump.jar");
    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 InstalledcoRuntimeClassSource(app));
    File rtjar = new File("res/rt.jar");
    File androidjar = new File("res/android.jar");
    app.addLibraries(rt(app, rtjar), rt(app, androidjar));
    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.name.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();
        cfg.verify();
    }
}
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) 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) File(java.io.File) 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