Search in sources :

Example 1 with Transform

use of soot.Transform in project soot by Sable.

the class PluginLoader method handlePhasePlugin.

/**
 * Loads the phase plugin and adds it to PackManager.
 * @param pluginDescription the plugin description instance read from configuration file.
 */
private static void handlePhasePlugin(final PhasePluginDescription pluginDescription) {
    try {
        final Object instance = PluginLoader.loadStrategy.create(pluginDescription.getClassName());
        if (!(instance instanceof SootPhasePlugin)) {
            throw new RuntimeException("The plugin class '" + pluginDescription.getClassName() + "' does not implement SootPhasePlugin.");
        }
        final SootPhasePlugin phasePlugin = (SootPhasePlugin) instance;
        phasePlugin.setDescription(pluginDescription);
        final String packName = getPackName(pluginDescription.getPhaseName());
        Transform transform = new Transform(pluginDescription.getPhaseName(), phasePlugin.getTransformer());
        transform.setDeclaredOptions(concat(appendEnabled(phasePlugin.getDeclaredOptions())));
        transform.setDefaultOptions(concat(phasePlugin.getDefaultOptions()));
        PackManager.v().getPack(packName).add(transform);
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException("Failed to load plugin class for " + pluginDescription + ".", e);
    } catch (final InstantiationException e) {
        throw new RuntimeException("Failed to instanciate plugin class for " + pluginDescription + ".", e);
    }
}
Also used : SootPhasePlugin(soot.plugins.SootPhasePlugin) Transform(soot.Transform)

Example 2 with Transform

use of soot.Transform in project soot by Sable.

the class CFGViewer method main.

public static void main(String[] args) {
    CFGViewer viewer = new CFGViewer();
    Transform printTransform = new Transform(phaseFullname, viewer);
    printTransform.setDeclaredOptions("enabled " + altClassPathOptionName + ' ' + graphTypeOptionName + ' ' + irOptionName + ' ' + multipageOptionName + ' ' + briefLabelOptionName + ' ');
    printTransform.setDefaultOptions("enabled " + altClassPathOptionName + ": " + graphTypeOptionName + ':' + defaultGraph + ' ' + irOptionName + ':' + defaultIR + ' ' + multipageOptionName + ":false " + ' ' + briefLabelOptionName + ":false ");
    PackManager.v().getPack("jtp").add(printTransform);
    args = viewer.parse_options(args);
    if (args.length == 0) {
        usage();
    } else {
        soot.Main.main(args);
    }
}
Also used : Transform(soot.Transform)

Example 3 with Transform

use of soot.Transform in project soot by Sable.

the class CallGraphExample method main.

public static void main(String[] args) {
    List<String> argsList = new ArrayList<String>(Arrays.asList(args));
    argsList.addAll(Arrays.asList(new String[] { "-w", "-main-class", // main-class
    "testers.CallGraphs", // argument classes
    "testers.CallGraphs", // 
    "testers.A" }));
    PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {

        @Override
        protected void internalTransform(String phaseName, Map options) {
            CHATransformer.v().transform();
            SootClass a = Scene.v().getSootClass("testers.A");
            SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
            CallGraph cg = Scene.v().getCallGraph();
            Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
            while (targets.hasNext()) {
                SootMethod tgt = (SootMethod) targets.next();
                System.out.println(src + " may call " + tgt);
            }
        }
    }));
    args = argsList.toArray(new String[0]);
    soot.Main.main(args);
}
Also used : CallGraph(soot.jimple.toolkits.callgraph.CallGraph) ArrayList(java.util.ArrayList) SootMethod(soot.SootMethod) Targets(soot.jimple.toolkits.callgraph.Targets) Transform(soot.Transform) SootClass(soot.SootClass) MethodOrMethodContext(soot.MethodOrMethodContext) Map(java.util.Map) SceneTransformer(soot.SceneTransformer)

Example 4 with Transform

use of soot.Transform in project soot by Sable.

the class Main method main.

/**
 * @param args
 */
public static void main(String[] args) {
    PackManager.v().getPack("wjtp").add(new Transform("wjtp.ifds", new SceneTransformer() {

        protected void internalTransform(String phaseName, @SuppressWarnings("rawtypes") Map options) {
            IFDSTabulationProblem<Unit, ?, SootMethod, InterproceduralCFG<Unit, SootMethod>> problem = new IFDSPossibleTypes(new JimpleBasedInterproceduralCFG());
            @SuppressWarnings({ "rawtypes", "unchecked" }) JimpleIFDSSolver<?, InterproceduralCFG<Unit, SootMethod>> solver = new JimpleIFDSSolver(problem);
            solver.solve();
        }
    }));
    soot.Main.main(args);
}
Also used : JimpleBasedInterproceduralCFG(soot.jimple.toolkits.ide.icfg.JimpleBasedInterproceduralCFG) InterproceduralCFG(heros.InterproceduralCFG) JimpleBasedInterproceduralCFG(soot.jimple.toolkits.ide.icfg.JimpleBasedInterproceduralCFG) Unit(soot.Unit) SceneTransformer(soot.SceneTransformer) IFDSPossibleTypes(soot.jimple.toolkits.ide.exampleproblems.IFDSPossibleTypes) SootMethod(soot.SootMethod) Transform(soot.Transform) Map(java.util.Map)

Example 5 with Transform

use of soot.Transform in project soot by Sable.

the class OnTheFlyJimpleBasedICFG method main.

public static void main(String[] args) {
    PackManager.v().getPack("wjtp").add(new Transform("wjtp.onflyicfg", new SceneTransformer() {

        @Override
        protected void internalTransform(String phaseName, Map<String, String> options) {
            if (Scene.v().hasCallGraph())
                throw new RuntimeException("call graph present!");
            loadAllClassesOnClassPathToSignatures();
            SootMethod mainMethod = Scene.v().getMainMethod();
            OnTheFlyJimpleBasedICFG icfg = new OnTheFlyJimpleBasedICFG(mainMethod);
            Set<SootMethod> worklist = new LinkedHashSet<SootMethod>();
            Set<SootMethod> visited = new HashSet<SootMethod>();
            worklist.add(mainMethod);
            int monomorphic = 0, polymorphic = 0;
            while (!worklist.isEmpty()) {
                Iterator<SootMethod> iter = worklist.iterator();
                SootMethod currMethod = iter.next();
                iter.remove();
                visited.add(currMethod);
                System.err.println(currMethod);
                // MUST call this method to initialize ICFG for every method
                Body body = currMethod.getActiveBody();
                if (body == null)
                    continue;
                for (Unit u : body.getUnits()) {
                    Stmt s = (Stmt) u;
                    if (s.containsInvokeExpr()) {
                        Set<SootMethod> calleesOfCallAt = icfg.getCalleesOfCallAt(s);
                        if (s.getInvokeExpr() instanceof VirtualInvokeExpr || s.getInvokeExpr() instanceof InterfaceInvokeExpr) {
                            if (calleesOfCallAt.size() <= 1)
                                monomorphic++;
                            else
                                polymorphic++;
                            System.err.println("mono: " + monomorphic + "   poly: " + polymorphic);
                        }
                        for (SootMethod callee : calleesOfCallAt) {
                            if (!visited.contains(callee)) {
                                System.err.println(callee);
                            // worklist.add(callee);
                            }
                        }
                    }
                }
            }
        }
    }));
    Options.v().set_on_the_fly(true);
    soot.Main.main(args);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) Unit(soot.Unit) SceneTransformer(soot.SceneTransformer) Stmt(soot.jimple.Stmt) SootMethod(soot.SootMethod) Transform(soot.Transform) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) HashMap(java.util.HashMap) Map(java.util.Map) Body(soot.Body) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Transform (soot.Transform)13 Map (java.util.Map)5 Body (soot.Body)3 SceneTransformer (soot.SceneTransformer)3 SootMethod (soot.SootMethod)3 Unit (soot.Unit)3 ArrayList (java.util.ArrayList)2 BodyTransformer (soot.BodyTransformer)2 Pack (soot.Pack)2 Stmt (soot.jimple.Stmt)2 InterproceduralCFG (heros.InterproceduralCFG)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 CompilationDeathException (soot.CompilationDeathException)1 HasPhaseOptions (soot.HasPhaseOptions)1 MethodOrMethodContext (soot.MethodOrMethodContext)1 SootClass (soot.SootClass)1 InterfaceInvokeExpr (soot.jimple.InterfaceInvokeExpr)1 InvokeExpr (soot.jimple.InvokeExpr)1