Search in sources :

Example 1 with IPropertyDictionary

use of org.mapleir.propertyframework.api.IPropertyDictionary in project maple-ir by LLVM-but-worse.

the class Boot method main.

public static void main(String[] args) throws Exception {
    sections = new LinkedList<>();
    logging = true;
    File rtjar = new File("res/rt.jar");
    // Load input jar
    File f = locateRevFile(135);
    // File f = new File("res/allatori6.1san.jar");
    section("Preparing to run on " + f.getAbsolutePath());
    SingleJarDownloader<ClassNode> dl = new SingleJarDownloader<>(new JarInfo(f));
    dl.download();
    String name = f.getName().substring(0, f.getName().length() - 4);
    // ApplicationClassSource app = new ApplicationClassSource(name, dl.getJarContents().getClassContents());
    // 
    ApplicationClassSource app = new ApplicationClassSource("test", ClassHelper.parseClasses(CGExample.class));
    // app.addLibraries(new InstalledRuntimeClassSource(app));
    app.addLibraries(rt(app, rtjar), new InstalledRuntimeClassSource(app));
    section("Initialising context.");
    AnalysisContext cxt = new BasicAnalysisContext.BasicContextBuilder().setApplication(app).setInvocationResolver(new DefaultInvocationResolver(app)).setCache(new IRCache(ControlFlowGraphBuilder::build)).setApplicationContext(new SimpleApplicationContext(app)).build();
    section("Expanding callgraph and generating cfgs.");
    IRCallTracer tracer = new IRCallTracer(cxt);
    for (MethodNode m : cxt.getApplicationContext().getEntryPoints()) {
        // System.out.println(m);
        tracer.trace(m);
        if (m.instructions.size() > 500 && m.instructions.size() < 100) {
            System.out.println(m);
            System.out.println(cxt.getIRCache().get(m));
        }
    }
    for (ClassNode cn : app.iterate()) {
        TabbedStringWriter sw = new TabbedStringWriter();
        sw.setTabString("  ");
        IPropertyDictionary settings = PropertyHelper.createDictionary();
        // settings.put(new BooleanProperty(ASMPrinter.PROP_ACCESS_FLAG_SAFE, true));
        ClassPrinter cp = new ClassPrinter(sw, settings, new FieldNodePrinter(sw, settings), new MethodNodePrinter(sw, settings) {

            @Override
            protected ControlFlowGraph getCfg(MethodNode mn) {
                return cxt.getIRCache().getFor(mn);
            }
        });
        cp.print(cn);
        System.out.println(sw.toString());
    }
    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);
    // for(MethodNode m : cxt.getIRCache().getActiveMethods()) {
    // if(m.instructions.size() > 100 && m.instructions.size() < 500) {
    // System.out.println(cxt.getIRCache().get(m));
    // }
    // }
    section("Retranslating SSA IR to standard flavour.");
    for (Entry<MethodNode, ControlFlowGraph> e : cxt.getIRCache().entrySet()) {
        MethodNode mn = e.getKey();
        ControlFlowGraph cfg = e.getValue();
        BoissinotDestructor.leaveSSA(cfg);
        cfg.getLocals().realloc(cfg);
        (new ControlFlowGraphDumper(cfg, mn)).dump();
    }
    section("Rewriting jar.");
    // dumpJar(app, dl, masterGroup, "out/osb5.jar");
    section("Finished.");
}
Also used : IPropertyDictionary(org.mapleir.propertyframework.api.IPropertyDictionary) ClassPrinter(org.mapleir.ir.printer.ClassPrinter) AnalysisContext(org.mapleir.context.AnalysisContext) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext) IPass(org.mapleir.deob.IPass) InstalledRuntimeClassSource(org.mapleir.app.service.InstalledRuntimeClassSource) ApplicationClassSource(org.mapleir.app.service.ApplicationClassSource) MethodNode(org.objectweb.asm.tree.MethodNode) MethodNodePrinter(org.mapleir.ir.printer.MethodNodePrinter) SingleJarDownloader(org.topdank.byteio.in.SingleJarDownloader) TabbedStringWriter(org.mapleir.stdlib.util.TabbedStringWriter) ClassNode(org.objectweb.asm.tree.ClassNode) FieldNodePrinter(org.mapleir.ir.printer.FieldNodePrinter) IRCache(org.mapleir.context.IRCache) IRCallTracer(org.mapleir.deob.interproc.IRCallTracer) SimpleApplicationContext(org.mapleir.app.client.SimpleApplicationContext) ControlFlowGraphDumper(org.mapleir.ir.algorithms.ControlFlowGraphDumper) PassGroup(org.mapleir.deob.PassGroup) JarInfo(org.topdank.byteengineer.commons.data.JarInfo) ControlFlowGraph(org.mapleir.ir.cfg.ControlFlowGraph) BasicAnalysisContext(org.mapleir.context.BasicAnalysisContext)

Example 2 with IPropertyDictionary

use of org.mapleir.propertyframework.api.IPropertyDictionary in project maple-ir by LLVM-but-worse.

the class STest method main.

public static void main(String[] args) {
    IServiceRegistry reg = ServiceHelper.getGlobalServiceRegistry();
    IServiceContext cxt = ServiceHelper.getGlobalServiceContext();
    IServiceFactory<Person> personFactory = new IServiceFactory<Person>() {

        @Override
        public Person create(IPropertyDictionary dict) {
            IProperty<String> nameProp = dict.find(String.class, "name");
            IProperty<Boolean> genderProp = dict.find(boolean.class, "ismale");
            String name = nameProp.getValue();
            if (genderProp.getValue()) {
                return new Male(name);
            } else {
                return new Female(name);
            }
        }
    };
    reg.registerServiceFactory(cxt, Person.class, personFactory);
    // some other module that doesnt have impl (male/female/base) classes, only Person
    IServiceReference<Person> ref = reg.getServiceReference(cxt, Person.class);
    IPropertyDictionary settings = PropertyHelper.createDictionary();
    settings.put(new BooleanProperty(PropertyHelper.BASIC_SYNCHRONISED_DICTIONARY_OPT, true));
    {
        IPropertyDictionary dict = PropertyHelper.createDictionary(settings);
        System.out.println(dict);
        dict.put(new StringProperty("name", "", "bilb"));
        dict.put(new BooleanProperty("ismale", true));
        Person p = reg.getService(ref, dict);
        System.out.println(p);
    }
    {
        IPropertyDictionary dict = PropertyHelper.createDictionary();
        System.out.println(dict);
        dict.put(new StringProperty("name", "", "theresa NAY"));
        dict.put(new BooleanProperty("ismale", false));
        Person p = reg.getService(ref, dict);
        System.out.println(p);
    }
    reg.ungetService(ref);
}
Also used : IPropertyDictionary(org.mapleir.propertyframework.api.IPropertyDictionary) BooleanProperty(org.mapleir.propertyframework.impl.BooleanProperty) IServiceRegistry(org.mapleir.serviceframework.api.IServiceRegistry) StringProperty(org.mapleir.propertyframework.impl.StringProperty) IServiceContext(org.mapleir.serviceframework.api.IServiceContext) IServiceFactory(org.mapleir.serviceframework.api.IServiceFactory)

Aggregations

IPropertyDictionary (org.mapleir.propertyframework.api.IPropertyDictionary)2 SimpleApplicationContext (org.mapleir.app.client.SimpleApplicationContext)1 ApplicationClassSource (org.mapleir.app.service.ApplicationClassSource)1 InstalledRuntimeClassSource (org.mapleir.app.service.InstalledRuntimeClassSource)1 AnalysisContext (org.mapleir.context.AnalysisContext)1 BasicAnalysisContext (org.mapleir.context.BasicAnalysisContext)1 IRCache (org.mapleir.context.IRCache)1 IPass (org.mapleir.deob.IPass)1 PassGroup (org.mapleir.deob.PassGroup)1 IRCallTracer (org.mapleir.deob.interproc.IRCallTracer)1 ControlFlowGraphDumper (org.mapleir.ir.algorithms.ControlFlowGraphDumper)1 ControlFlowGraph (org.mapleir.ir.cfg.ControlFlowGraph)1 ClassPrinter (org.mapleir.ir.printer.ClassPrinter)1 FieldNodePrinter (org.mapleir.ir.printer.FieldNodePrinter)1 MethodNodePrinter (org.mapleir.ir.printer.MethodNodePrinter)1 BooleanProperty (org.mapleir.propertyframework.impl.BooleanProperty)1 StringProperty (org.mapleir.propertyframework.impl.StringProperty)1 IServiceContext (org.mapleir.serviceframework.api.IServiceContext)1 IServiceFactory (org.mapleir.serviceframework.api.IServiceFactory)1 IServiceRegistry (org.mapleir.serviceframework.api.IServiceRegistry)1