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());
}
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");
}
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));
}
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);
}
}
}
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;
}
}
Aggregations