Search in sources :

Example 1 with JavaClassCompiler

use of org.mapleir.stdlib.util.JavaClassCompiler 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)

Aggregations

ClassNode (org.mapleir.asm.ClassNode)1 MethodNode (org.mapleir.asm.MethodNode)1 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)1 ControlFlowGraphBuilder (org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder)1 JavaClassCompiler (org.mapleir.stdlib.util.JavaClassCompiler)1 ASMFactory (org.topdank.byteengineer.commons.asm.ASMFactory)1 DefaultASMFactory (org.topdank.byteengineer.commons.asm.DefaultASMFactory)1