Search in sources :

Example 76 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class PointsToAnalysis method getLocals.

private static Map getLocals(SootClass sc, String methodname, String typename) {
    Map res = new HashMap();
    Iterator mi = sc.getMethods().iterator();
    while (mi.hasNext()) {
        SootMethod sm = (SootMethod) mi.next();
        System.err.println(sm.getName());
        if (true && sm.getName().equals(methodname) && sm.isConcrete()) {
            JimpleBody jb = (JimpleBody) sm.retrieveActiveBody();
            Iterator ui = jb.getUnits().iterator();
            while (ui.hasNext()) {
                Stmt s = (Stmt) ui.next();
                int line = getLineNumber(s);
                // find definitions
                Iterator bi = s.getDefBoxes().iterator();
                while (bi.hasNext()) {
                    Object o = bi.next();
                    if (o instanceof ValueBox) {
                        Value v = ((ValueBox) o).getValue();
                        if (v.getType().toString().equals(typename) && v instanceof Local)
                            res.put(new Integer(line), v);
                    }
                }
            }
        }
    }
    return res;
}
Also used : HashMap(java.util.HashMap) ValueBox(soot.ValueBox) Iterator(java.util.Iterator) Value(soot.Value) SootMethod(soot.SootMethod) Local(soot.Local) HashMap(java.util.HashMap) Map(java.util.Map) JimpleBody(soot.jimple.JimpleBody) Stmt(soot.jimple.Stmt)

Example 77 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class ExprTranslator method handleSpecialCall.

// any type
boolean handleSpecialCall(InstanceInvokeExpr expr, SootMethod target) {
    String mn = target.getName();
    int np = target.getParameterCount();
    SootClass dc = target.getDeclaringClass();
    // Is it a method in a Foo object?
    if (isFoo(dc)) {
        if (mn.equals("foo") && np == 1) {
            Variable lvar = new Variable(Variable.Type.FOO);
            Method foo = new Method("foo", new Variable[0]);
            FooMethodCall fmc = new FooMethodCall(foo);
            fmc.setAssignmentTarget(lvar);
            st.addStatement(fmc);
            return true;
        }
        // Unknown Foo method
        return false;
    }
    // Not a special call
    return false;
}
Also used : Variable(dk.brics.soot.intermediate.representation.Variable) FooMethodCall(dk.brics.soot.intermediate.representation.FooMethodCall) SootMethod(soot.SootMethod) Method(dk.brics.soot.intermediate.representation.Method) SootClass(soot.SootClass)

Example 78 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class ExprTranslator method caseSpecialInvokeExpr.

public void caseSpecialInvokeExpr(SpecialInvokeExpr expr) {
    // Constructor calls, maybe
    Variable bvar = st.getLocalVariable((Local) expr.getBase());
    SootMethod m = expr.getMethod();
    if (m.getName().equals("<init>")) {
        SootClass dc = m.getDeclaringClass();
        if (isFoo(dc)) {
            FooInit fi = new FooInit();
            fi.setAssignmentTarget(bvar);
            st.addStatement(fi);
            return;
        }
    }
    handleCall(expr, expr.getMethod());
}
Also used : Variable(dk.brics.soot.intermediate.representation.Variable) SootMethod(soot.SootMethod) FooInit(dk.brics.soot.intermediate.representation.FooInit) SootClass(soot.SootClass)

Example 79 with SootMethod

use of soot.SootMethod 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 80 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class Foonalasys method loadClass.

/**
 * Loads the named class into the Soot scene,
 *  marks it as an application class, and generates bodies
 *  for all of its concrete methods.
 *  @param name the fully qualified name of the class to be loaded.
 */
public static void loadClass(String name) {
    SootClass c = Scene.v().loadClassAndSupport(name);
    c.setApplicationClass();
    Iterator mi = c.getMethods().iterator();
    while (mi.hasNext()) {
        SootMethod sm = (SootMethod) mi.next();
        if (sm.isConcrete()) {
            sm.retrieveActiveBody();
        }
    }
}
Also used : Iterator(java.util.Iterator) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Aggregations

SootMethod (soot.SootMethod)237 SootClass (soot.SootClass)95 RefType (soot.RefType)56 ArrayList (java.util.ArrayList)49 Type (soot.Type)47 Unit (soot.Unit)47 Value (soot.Value)36 Stmt (soot.jimple.Stmt)35 Test (org.junit.Test)34 Local (soot.Local)34 Body (soot.Body)32 VoidType (soot.VoidType)31 PrimType (soot.PrimType)28 SootField (soot.SootField)28 BooleanType (soot.BooleanType)26 Iterator (java.util.Iterator)23 DoubleType (soot.DoubleType)23 FloatType (soot.FloatType)23 LongType (soot.LongType)23 InvokeExpr (soot.jimple.InvokeExpr)23