Search in sources :

Example 26 with ClassNode

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

the class Boot2 method rt.

private static LibraryClassSource rt(ApplicationClassSource app, File rtjar) throws IOException {
    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 27 with ClassNode

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

Example 28 with ClassNode

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

the class CleanBoot method main.

public static void main(String[] args) throws Exception {
    ClassNode cn = ClassHelper.create(new FileInputStream(new File("MemeIn.class")));
    IRCache irFactory = new IRCache();
    for (MethodNode mn : cn.getMethods()) {
        // if (!mn.getName().equals("merge"))
        // continue;
        // if (mn.getName().equals("merge"))
        // System.out.println(InsnListUtils.insnListToString(mn.node.instructions));
        ControlFlowGraph cfg = irFactory.getNonNull(mn);
        // if (mn.getName().equals("merge"))
        // System.out.println(cfg);
        // if (mn.getName().equals("merge"))
        // CFGUtils.easyDumpCFG(cfg, "pre-destruct");
        cfg.verify();
        BoissinotDestructor.leaveSSA(cfg);
        // if (mn.getName().equals("merge"))
        // CFGUtils.easyDumpCFG(cfg, "pre-reaalloc");
        LocalsReallocator.realloc(cfg);
        // if (mn.getName().equals("merge"))
        // 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.node.instructions));
    }
    new FileOutputStream(new File("Meme.class")).write(ClassHelper.toByteArray(cn, ClassWriter.COMPUTE_FRAMES));
}
Also used : ClassNode(org.mapleir.asm.ClassNode) ControlFlowGraphDumper(org.mapleir.ir.codegen.ControlFlowGraphDumper) MethodNode(org.mapleir.asm.MethodNode) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) FileOutputStream(java.io.FileOutputStream) IRCache(org.mapleir.context.IRCache) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 29 with ClassNode

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

the class CompilationDemo method main.

public static void main(String[] args) throws IOException {
    // File f = new File("res/Bad.jar");
    // SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(f));
    // dl.download();
    // for (ClassNode cn : dl.getJarContents().getClassContents().namedMap().values()) {
    String className = "HelloWorld";
    JavaClassCompiler compiler = new JavaClassCompiler();
    byte[] bytes = compiler.compile(className, "public class " + className + " { public static void main(String[] args) { System.out.println(\"Hello world\"); } }");
    if (bytes == null) {
        System.out.println("Compilation failed!");
    } else {
        ASMFactory cnFactory = new DefaultASMFactory();
        ClassNode cn = cnFactory.create(bytes, className);
        for (MethodNode mn : cn.getMethods()) {
            System.out.println(mn.getJavaDesc());
            ControlFlowGraphBuilder builder = new ControlFlowGraphBuilder(mn, false);
            ControlFlowGraph cfg = builder.buildImpl();
            System.out.println(cfg);
            BoissinotDestructor.leaveSSA(cfg);
            LocalsReallocator.realloc(cfg);
            System.out.println(cfg);
        }
    }
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode) ControlFlowGraphBuilder(org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) DefaultASMFactory(org.topdank.byteengineer.commons.asm.DefaultASMFactory) JavaClassCompiler(org.mapleir.stdlib.util.JavaClassCompiler) DefaultASMFactory(org.topdank.byteengineer.commons.asm.DefaultASMFactory) ASMFactory(org.topdank.byteengineer.commons.asm.ASMFactory)

Example 30 with ClassNode

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

the class DefaultInvocationResolver method resolveVirtualInitCall.

@Override
public MethodNode resolveVirtualInitCall(String owner, String desc) {
    ClassNode cn = app.findClassNode(owner);
    if (!checkNullClass(cn, owner)) {
        return null;
    }
    MethodNode mn = resolve(cn, "<init>", desc, true);
    if (mn == null) {
        return null;
    } else if (!mn.owner.getName().equals(owner)) {
        throw new UnsupportedOperationException(mn.toString());
    } else {
        return mn;
    }
}
Also used : ClassNode(org.mapleir.asm.ClassNode) MethodNode(org.mapleir.asm.MethodNode)

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