Search in sources :

Example 1 with ShimpleBody

use of soot.shimple.ShimpleBody in project soot by Sable.

the class PackManager method runBodyPacks.

@SuppressWarnings("fallthrough")
private void runBodyPacks(SootClass c) {
    final int format = Options.v().output_format();
    if (format == Options.output_format_dava) {
        logger.debug("Decompiling {}...", c.getName());
        // January 13th, 2006 SootMethodAddedByDava is set to false for
        // SuperFirstStmtHandler
        G.v().SootMethodAddedByDava = false;
    } else {
        logger.debug("Transforming {}...", c.getName());
    }
    boolean produceBaf = false, produceGrimp = false, produceDava = false, produceJimple = true, produceShimple = false;
    switch(format) {
        case Options.output_format_none:
        case Options.output_format_xml:
        case Options.output_format_jimple:
        case Options.output_format_jimp:
        case Options.output_format_template:
        case Options.output_format_dex:
        case Options.output_format_force_dex:
            break;
        case Options.output_format_shimp:
        case Options.output_format_shimple:
            produceShimple = true;
            // FLIP produceJimple
            produceJimple = false;
            break;
        case Options.output_format_dava:
            produceDava = true;
        // FALL THROUGH
        case Options.output_format_grimp:
        case Options.output_format_grimple:
            produceGrimp = true;
            break;
        case Options.output_format_baf:
        case Options.output_format_b:
            produceBaf = true;
            break;
        case Options.output_format_jasmin:
        case Options.output_format_class:
        case Options.output_format_asm:
            produceGrimp = Options.v().via_grimp();
            produceBaf = !produceGrimp;
            break;
        default:
            throw new RuntimeException();
    }
    soot.xml.TagCollector tc = new soot.xml.TagCollector();
    boolean wholeShimple = Options.v().whole_shimple();
    if (Options.v().via_shimple())
        produceShimple = true;
    // here we create a copy of the methods so that transformers are able
    // to add method bodies during the following iteration;
    // such adding of methods happens in rare occasions: for instance when
    // resolving a method reference to a non-existing method, then this
    // method is created as a phantom method when phantom-refs are enabled
    ArrayList<SootMethod> methodsCopy = new ArrayList<SootMethod>(c.getMethods());
    for (SootMethod m : methodsCopy) {
        if (DEBUG) {
            if (m.getExceptions().size() != 0)
                System.out.println("PackManager printing out jimple body exceptions for method " + m.toString() + " " + m.getExceptions().toString());
        }
        if (!m.isConcrete())
            continue;
        if (produceShimple || wholeShimple) {
            ShimpleBody sBody = null;
            // whole shimple or not?
            {
                Body body = m.retrieveActiveBody();
                if (body instanceof ShimpleBody) {
                    sBody = (ShimpleBody) body;
                    if (!sBody.isSSA())
                        sBody.rebuild();
                } else {
                    sBody = Shimple.v().newBody(body);
                }
            }
            m.setActiveBody(sBody);
            PackManager.v().getPack("stp").apply(sBody);
            PackManager.v().getPack("sop").apply(sBody);
            if (produceJimple || (wholeShimple && !produceShimple))
                m.setActiveBody(sBody.toJimpleBody());
        }
        if (produceJimple) {
            Body body = m.retrieveActiveBody();
            // Change
            CopyPropagator.v().transform(body);
            ConditionalBranchFolder.v().transform(body);
            UnreachableCodeEliminator.v().transform(body);
            DeadAssignmentEliminator.v().transform(body);
            UnusedLocalEliminator.v().transform(body);
            PackManager.v().getPack("jtp").apply(body);
            if (Options.v().validate()) {
                body.validate();
            }
            PackManager.v().getPack("jop").apply(body);
            PackManager.v().getPack("jap").apply(body);
            if (Options.v().xml_attributes() && Options.v().output_format() != Options.output_format_jimple) {
                // System.out.println("collecting body tags");
                tc.collectBodyTags(body);
            }
        }
        if (produceGrimp) {
            m.setActiveBody(Grimp.v().newBody(m.getActiveBody(), "gb"));
            PackManager.v().getPack("gop").apply(m.getActiveBody());
        } else if (produceBaf) {
            m.setActiveBody(convertJimpleBodyToBaf(m));
        }
    }
    if (Options.v().xml_attributes() && Options.v().output_format() != Options.output_format_jimple) {
        processXMLForClass(c, tc);
    // System.out.println("processed xml for class");
    }
    if (produceDava) {
        for (SootMethod m : c.getMethods()) {
            if (!m.isConcrete())
                continue;
            // all the work done in decompilation is done in DavaBody which
            // is invoked from within newBody
            m.setActiveBody(Dava.v().newBody(m.getActiveBody()));
        }
        // could use G to add new method...................
        if (G.v().SootMethodAddedByDava) {
            // System.out.println("PACKMANAGER SAYS:----------------Have to
            // add the new method(s)");
            ArrayList<SootMethod> sootMethodsAdded = G.v().SootMethodsAdded;
            Iterator<SootMethod> it = sootMethodsAdded.iterator();
            while (it.hasNext()) {
                c.addMethod(it.next());
            }
            G.v().SootMethodsAdded = new ArrayList<SootMethod>();
            G.v().SootMethodAddedByDava = false;
        }
    }
// end if produceDava
}
Also used : TagCollector(soot.xml.TagCollector) TagCollector(soot.xml.TagCollector) ArrayList(java.util.ArrayList) ShimpleBody(soot.shimple.ShimpleBody) JimpleBody(soot.jimple.JimpleBody) ShimpleBody(soot.shimple.ShimpleBody) DavaBody(soot.dava.DavaBody) BafBody(soot.baf.BafBody)

Aggregations

ArrayList (java.util.ArrayList)1 BafBody (soot.baf.BafBody)1 DavaBody (soot.dava.DavaBody)1 JimpleBody (soot.jimple.JimpleBody)1 ShimpleBody (soot.shimple.ShimpleBody)1 TagCollector (soot.xml.TagCollector)1