Search in sources :

Example 71 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class BadFields method handleMethod.

private void handleMethod(SootMethod m) {
    if (!m.isConcrete())
        return;
    for (Iterator<ValueBox> bIt = m.retrieveActiveBody().getUseAndDefBoxes().iterator(); bIt.hasNext(); ) {
        final ValueBox b = bIt.next();
        Value v = b.getValue();
        if (!(v instanceof StaticFieldRef))
            continue;
        StaticFieldRef sfr = (StaticFieldRef) v;
        SootField f = sfr.getField();
        if (!f.getDeclaringClass().getName().equals("java.lang.System"))
            continue;
        if (f.getName().equals("err")) {
            logger.debug("" + "Use of System.err in " + m);
        }
        if (f.getName().equals("out")) {
            logger.debug("" + "Use of System.out in " + m);
        }
    }
    for (Iterator<Unit> sIt = m.getActiveBody().getUnits().iterator(); sIt.hasNext(); ) {
        final Stmt s = (Stmt) sIt.next();
        if (!s.containsInvokeExpr())
            continue;
        InvokeExpr ie = s.getInvokeExpr();
        SootMethod target = ie.getMethod();
        if (target.getDeclaringClass().getName().equals("java.lang.System") && target.getName().equals("exit")) {
            warn("" + m + " calls System.exit");
        }
    }
    if (m.getName().equals("<clinit>")) {
        for (Iterator<Unit> sIt = m.getActiveBody().getUnits().iterator(); sIt.hasNext(); ) {
            final Stmt s = (Stmt) sIt.next();
            for (Iterator<ValueBox> bIt = s.getUseBoxes().iterator(); bIt.hasNext(); ) {
                final ValueBox b = bIt.next();
                Value v = b.getValue();
                if (v instanceof FieldRef) {
                    warn(m.getName() + " reads field " + v);
                }
            }
            if (!s.containsInvokeExpr())
                continue;
            InvokeExpr ie = s.getInvokeExpr();
            SootMethod target = ie.getMethod();
            calls(target);
        }
    }
}
Also used : InvokeExpr(soot.jimple.InvokeExpr) StaticFieldRef(soot.jimple.StaticFieldRef) FieldRef(soot.jimple.FieldRef) ValueBox(soot.ValueBox) Value(soot.Value) SootMethod(soot.SootMethod) SootField(soot.SootField) Unit(soot.Unit) StaticFieldRef(soot.jimple.StaticFieldRef) Stmt(soot.jimple.Stmt)

Example 72 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class BadFields method internalTransform.

protected void internalTransform(String phaseName, Map<String, String> options) {
    lastClass = null;
    for (Iterator<SootClass> clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext(); ) {
        final SootClass cl = clIt.next();
        currentClass = cl;
        handleClass(cl);
        for (Iterator<SootMethod> it = cl.methodIterator(); it.hasNext(); ) {
            handleMethod(it.next());
        }
    }
    Scene.v().setCallGraph(Scene.v().internalMakeCallGraph());
}
Also used : SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 73 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class CFGViewer method internalTransform.

// particular
// methods to print, this is a map
// from method name to the class
// name declaring the method.
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
    initialize(options);
    SootMethod meth = b.getMethod();
    if ((methodsToPrint == null) || (meth.getDeclaringClass().getName() == methodsToPrint.get(meth.getName()))) {
        Body body = ir.getBody((JimpleBody) b);
        print_cfg(body);
    }
}
Also used : SootMethod(soot.SootMethod) Body(soot.Body) JimpleBody(soot.jimple.JimpleBody)

Example 74 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class JavaTranslator method getTargetsOf.

public List<SootMethod> getTargetsOf(Value v, SootMethod m) {
    SootClass rc;
    Type t = v.getType();
    if (t instanceof ArrayType) {
        rc = Scene.v().getSootClass("java.lang.Object");
    } else {
        rc = ((RefType) v.getType()).getSootClass();
    }
    List<SootMethod> targets = h.resolveAbstractDispatch(rc, m);
    return targets;
}
Also used : ArrayType(soot.ArrayType) RefType(soot.RefType) ArrayType(soot.ArrayType) Type(soot.Type) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 75 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class JavaTranslator method makeMethods.

void makeMethods() {
    Collection<SootClass> app = Scene.v().getApplicationClasses();
    for (SootClass ac : app) {
        List<SootMethod> sootMethods = ac.getMethods();
        for (SootMethod sm : sootMethods) {
            List<Variable> vars = new LinkedList<Variable>();
            List<Type> params = sm.getParameterTypes();
            for (Type pt : params) {
                Variable v = makeVariable(pt);
                vars.add(v);
            }
            Variable[] var_array = (Variable[]) vars.toArray(new Variable[0]);
            Method m = new Method(sm.getName(), var_array);
            methods.add(m);
            methodsignaturToMethod.put(sm.getSignature(), m);
        }
    }
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType) Type(soot.Type) Variable(dk.brics.soot.intermediate.representation.Variable) SootMethod(soot.SootMethod) Method(dk.brics.soot.intermediate.representation.Method) SootMethod(soot.SootMethod) SootClass(soot.SootClass) LinkedList(java.util.LinkedList)

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