Search in sources :

Example 1 with SparkLibraryHelper

use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.

the class MethodNodeFactory method handleStmt.

/**
 * Adds the edges required for this statement to the graph.
 */
public final void handleStmt(Stmt s) {
    // We only consider reflective class creation when it is enabled
    if (s.containsInvokeExpr()) {
        if (!pag.getCGOpts().types_for_invoke())
            return;
        InvokeExpr iexpr = s.getInvokeExpr();
        if (iexpr instanceof VirtualInvokeExpr) {
            if (!isReflectionNewInstance(iexpr))
                return;
        } else if (!(iexpr instanceof StaticInvokeExpr))
            return;
    }
    s.apply(new AbstractStmtSwitch() {

        @Override
        public final void caseAssignStmt(AssignStmt as) {
            Value l = as.getLeftOp();
            Value r = as.getRightOp();
            if (!(l.getType() instanceof RefLikeType))
                return;
            assert r.getType() instanceof RefLikeType : "Type mismatch in assignment " + as + " in method " + method.getSignature();
            l.apply(MethodNodeFactory.this);
            Node dest = getNode();
            r.apply(MethodNodeFactory.this);
            Node src = getNode();
            if (l instanceof InstanceFieldRef) {
                ((InstanceFieldRef) l).getBase().apply(MethodNodeFactory.this);
                pag.addDereference((VarNode) getNode());
            }
            if (r instanceof InstanceFieldRef) {
                ((InstanceFieldRef) r).getBase().apply(MethodNodeFactory.this);
                pag.addDereference((VarNode) getNode());
            } else if (r instanceof StaticFieldRef) {
                StaticFieldRef sfr = (StaticFieldRef) r;
                SootFieldRef s = sfr.getFieldRef();
                if (pag.getOpts().empties_as_allocs()) {
                    if (s.declaringClass().getName().equals("java.util.Collections")) {
                        if (s.name().equals("EMPTY_SET")) {
                            src = pag.makeAllocNode(RefType.v("java.util.HashSet"), RefType.v("java.util.HashSet"), method);
                        } else if (s.name().equals("EMPTY_MAP")) {
                            src = pag.makeAllocNode(RefType.v("java.util.HashMap"), RefType.v("java.util.HashMap"), method);
                        } else if (s.name().equals("EMPTY_LIST")) {
                            src = pag.makeAllocNode(RefType.v("java.util.LinkedList"), RefType.v("java.util.LinkedList"), method);
                        }
                    } else if (s.declaringClass().getName().equals("java.util.Hashtable")) {
                        if (s.name().equals("emptyIterator")) {
                            src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyIterator"), RefType.v("java.util.Hashtable$EmptyIterator"), method);
                        } else if (s.name().equals("emptyEnumerator")) {
                            src = pag.makeAllocNode(RefType.v("java.util.Hashtable$EmptyEnumerator"), RefType.v("java.util.Hashtable$EmptyEnumerator"), method);
                        }
                    }
                }
            }
            mpag.addInternalEdge(src, dest);
        }

        @Override
        public final void caseReturnStmt(ReturnStmt rs) {
            if (!(rs.getOp().getType() instanceof RefLikeType))
                return;
            rs.getOp().apply(MethodNodeFactory.this);
            Node retNode = getNode();
            mpag.addInternalEdge(retNode, caseRet());
        }

        @Override
        public final void caseIdentityStmt(IdentityStmt is) {
            if (!(is.getLeftOp().getType() instanceof RefLikeType))
                return;
            Value leftOp = is.getLeftOp();
            Value rightOp = is.getRightOp();
            leftOp.apply(MethodNodeFactory.this);
            Node dest = getNode();
            rightOp.apply(MethodNodeFactory.this);
            Node src = getNode();
            mpag.addInternalEdge(src, dest);
            // in case library mode is activated add allocations to any
            // possible type of this local and
            // parameters of accessible methods
            int libOption = pag.getCGOpts().library();
            if (libOption != CGOptions.library_disabled && (accessibilityOracle.isAccessible(method))) {
                if (rightOp instanceof IdentityRef) {
                    Type rt = rightOp.getType();
                    rt.apply(new SparkLibraryHelper(pag, src, method));
                }
            }
        }

        @Override
        public final void caseThrowStmt(ThrowStmt ts) {
            ts.getOp().apply(MethodNodeFactory.this);
            mpag.addOutEdge(getNode(), pag.nodeFactory().caseThrow());
        }
    });
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) AssignStmt(soot.jimple.AssignStmt) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) SootFieldRef(soot.SootFieldRef) StaticFieldRef(soot.jimple.StaticFieldRef) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) RefLikeType(soot.RefLikeType) RefType(soot.RefType) Type(soot.Type) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) IdentityRef(soot.jimple.IdentityRef) AbstractStmtSwitch(soot.jimple.AbstractStmtSwitch) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) ReturnStmt(soot.jimple.ReturnStmt) ThrowStmt(soot.jimple.ThrowStmt) IdentityStmt(soot.jimple.IdentityStmt) SparkLibraryHelper(soot.jimple.spark.internal.SparkLibraryHelper)

Example 2 with SparkLibraryHelper

use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.

the class PAG method makeGlobalVarNode.

/**
 * Finds or creates the GlobalVarNode for the variable value, of type type.
 */
public GlobalVarNode makeGlobalVarNode(Object value, Type type) {
    if (opts.rta()) {
        value = null;
        type = RefType.v("java.lang.Object");
    }
    GlobalVarNode ret = valToGlobalVarNode.get(value);
    if (ret == null) {
        valToGlobalVarNode.put(value, ret = new GlobalVarNode(this, value, type));
        // type to accessible fields
        if (cgOpts.library() != CGOptions.library_disabled) {
            if (value instanceof SootField) {
                SootField sf = (SootField) value;
                if (accessibilityOracle.isAccessible(sf)) {
                    type.apply(new SparkLibraryHelper(this, ret, null));
                }
            }
        }
        addNodeTag(ret, null);
    } else if (!(ret.getType().equals(type))) {
        throw new RuntimeException("Value " + value + " of type " + type + " previously had type " + ret.getType());
    }
    return ret;
}
Also used : SootField(soot.SootField) SparkLibraryHelper(soot.jimple.spark.internal.SparkLibraryHelper)

Example 3 with SparkLibraryHelper

use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.

the class PAG method makeLocalFieldRefNode.

/**
 * Finds or creates the FieldRefNode for base variable baseValue and field
 * field, of type type.
 */
public FieldRefNode makeLocalFieldRefNode(Object baseValue, Type baseType, SparkField field, SootMethod method) {
    VarNode base = makeLocalVarNode(baseValue, baseType, method);
    FieldRefNode ret = makeFieldRefNode(base, field);
    // to accessible fields
    if (cgOpts.library() != CGOptions.library_disabled) {
        if (field instanceof SootField) {
            SootField sf = (SootField) field;
            Type type = sf.getType();
            if (accessibilityOracle.isAccessible(sf)) {
                type.apply(new SparkLibraryHelper(this, ret, method));
            }
        }
    }
    return ret;
}
Also used : RefType(soot.RefType) Type(soot.Type) RefLikeType(soot.RefLikeType) SootField(soot.SootField) SparkLibraryHelper(soot.jimple.spark.internal.SparkLibraryHelper)

Example 4 with SparkLibraryHelper

use of soot.jimple.spark.internal.SparkLibraryHelper in project soot by Sable.

the class MethodPAG method buildNative.

protected void buildNative() {
    ValNode thisNode = null;
    ValNode retNode = null;
    if (!method.isStatic()) {
        thisNode = (ValNode) nodeFactory.caseThis();
    }
    if (method.getReturnType() instanceof RefLikeType) {
        retNode = (ValNode) nodeFactory.caseRet();
        // be anything matching to the declared type.
        if (pag.getCGOpts().library() != CGOptions.library_disabled) {
            Type retType = method.getReturnType();
            retType.apply(new SparkLibraryHelper(pag, retNode, method));
        }
    }
    ValNode[] args = new ValNode[method.getParameterCount()];
    for (int i = 0; i < method.getParameterCount(); i++) {
        if (!(method.getParameterType(i) instanceof RefLikeType))
            continue;
        args[i] = (ValNode) nodeFactory.caseParm(i);
    }
    pag.nativeMethodDriver.process(method, thisNode, retNode, args);
}
Also used : RefLikeType(soot.RefLikeType) RefLikeType(soot.RefLikeType) RefType(soot.RefType) ArrayType(soot.ArrayType) Type(soot.Type) VoidType(soot.VoidType) SparkLibraryHelper(soot.jimple.spark.internal.SparkLibraryHelper)

Aggregations

SparkLibraryHelper (soot.jimple.spark.internal.SparkLibraryHelper)4 RefLikeType (soot.RefLikeType)3 RefType (soot.RefType)3 Type (soot.Type)3 ArrayType (soot.ArrayType)2 SootField (soot.SootField)2 SootFieldRef (soot.SootFieldRef)1 Value (soot.Value)1 VoidType (soot.VoidType)1 AbstractStmtSwitch (soot.jimple.AbstractStmtSwitch)1 AssignStmt (soot.jimple.AssignStmt)1 IdentityRef (soot.jimple.IdentityRef)1 IdentityStmt (soot.jimple.IdentityStmt)1 InstanceFieldRef (soot.jimple.InstanceFieldRef)1 InvokeExpr (soot.jimple.InvokeExpr)1 ReturnStmt (soot.jimple.ReturnStmt)1 StaticFieldRef (soot.jimple.StaticFieldRef)1 StaticInvokeExpr (soot.jimple.StaticInvokeExpr)1 ThrowStmt (soot.jimple.ThrowStmt)1 VirtualInvokeExpr (soot.jimple.VirtualInvokeExpr)1