use of org.mapleir.DefaultInvocationResolver 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;
}
Aggregations