Search in sources :

Example 1 with NumberedString

use of soot.util.NumberedString in project soot by Sable.

the class GeomPointsTo method getCallTargets.

/**
 * Obtain the set of possible call targets at given @param callsite.
 */
private void getCallTargets(IVarAbstraction pn, SootMethod src, Stmt callsite, ChunkedQueue<SootMethod> targetsQueue) {
    InstanceInvokeExpr iie = (InstanceInvokeExpr) callsite.getInvokeExpr();
    Local receiver = (Local) iie.getBase();
    NumberedString subSig = iie.getMethodRef().getSubSignature();
    // We first build the set of possible call targets
    for (AllocNode an : pn.get_all_points_to_objects()) {
        Type type = an.getType();
        if (type == null)
            continue;
        VirtualCalls.v().resolve(type, receiver.getType(), subSig, src, targetsQueue);
    }
}
Also used : NumberedString(soot.util.NumberedString) RefType(soot.RefType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) Local(soot.Local)

Example 2 with NumberedString

use of soot.util.NumberedString in project soot by Sable.

the class SootClass method getMethodUnsafe.

/*
	 * Returns the method of this class with the given subsignature. If no method
	 * with the given subsignature can be found, null is returned.
	 */
public SootMethod getMethodUnsafe(String subsignature) {
    checkLevel(SIGNATURES);
    NumberedString numberedString = Scene.v().getSubSigNumberer().find(subsignature);
    return numberedString == null ? null : getMethodUnsafe(numberedString);
}
Also used : NumberedString(soot.util.NumberedString)

Example 3 with NumberedString

use of soot.util.NumberedString in project soot by Sable.

the class VirtualCalls method resolveLibrarySignature.

protected void resolveLibrarySignature(Type declaredType, Type sigType, NumberedString subSig, SootMethod container, ChunkedQueue<SootMethod> targets, boolean appOnly, RefType base) {
    FastHierarchy fastHierachy = Scene.v().getOrMakeFastHierarchy();
    assert (declaredType instanceof RefType);
    Pair<Type, NumberedString> pair = new Pair<Type, NumberedString>(base, subSig);
    {
        Set<Pair<Type, NumberedString>> types = baseToPossibleSubTypes.get(pair);
        // just retrieve the previous result.
        if (types != null) {
            for (Pair<Type, NumberedString> tuple : types) {
                Type st = tuple.getO1();
                if (!fastHierachy.canStoreType(st, declaredType)) {
                    resolve(st, st, sigType, subSig, container, targets, appOnly);
                } else {
                    resolve(st, declaredType, sigType, subSig, container, targets, appOnly);
                }
            }
            return;
        }
    }
    Set<Pair<Type, NumberedString>> types = new HashSet<Pair<Type, NumberedString>>();
    // get return type; method name; parameter types
    String[] split = subSig.getString().replaceAll("(.*) (.*)\\((.*)\\)", "$1;$2;$3").split(";");
    Type declaredReturnType = Scene.v().getType(split[0]);
    String declaredName = split[1];
    List<Type> declaredParamTypes = new ArrayList<Type>();
    // separate the parameter types
    if (split.length == 3) {
        for (String type : split[2].split(",")) {
            declaredParamTypes.add(Scene.v().getType(type));
        }
    }
    Chain<SootClass> classes = Scene.v().getClasses();
    for (SootClass sc : classes) {
        for (SootMethod sm : sc.getMethods()) {
            if (sm.isConcrete() || sm.isNative()) {
                // method name has to match
                if (!sm.getName().equals(declaredName))
                    continue;
                // type or a sub type of it
                if (!fastHierachy.canStoreType(sm.getReturnType(), declaredReturnType))
                    continue;
                List<Type> paramTypes = sm.getParameterTypes();
                // ones (same type or super type).
                if (declaredParamTypes.size() != paramTypes.size())
                    continue;
                boolean check = true;
                for (int i = 0; i < paramTypes.size(); i++) {
                    if (!fastHierachy.canStoreType(declaredParamTypes.get(i), paramTypes.get(i))) {
                        check = false;
                        break;
                    }
                }
                if (check) {
                    Type st = sc.getType();
                    if (!fastHierachy.canStoreType(st, declaredType)) {
                        // therefore not used in library client
                        if (!sc.isFinal()) {
                            NumberedString newSubSig = sm.getNumberedSubSignature();
                            resolve(st, st, sigType, newSubSig, container, targets, appOnly);
                            types.add(new Pair<Type, NumberedString>(st, newSubSig));
                        }
                    } else {
                        resolve(st, declaredType, sigType, subSig, container, targets, appOnly);
                        types.add(new Pair<Type, NumberedString>(st, subSig));
                    }
                }
            }
        }
    }
    baseToPossibleSubTypes.putAll(pair, types);
}
Also used : NumberedString(soot.util.NumberedString) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) NumberedString(soot.util.NumberedString) SootClass(soot.SootClass) RefType(soot.RefType) FastHierarchy(soot.FastHierarchy) RefType(soot.RefType) AnySubType(soot.AnySubType) NullType(soot.NullType) ArrayType(soot.ArrayType) Type(soot.Type) SootMethod(soot.SootMethod) Pair(soot.toolkits.scalar.Pair) HashSet(java.util.HashSet)

Example 4 with NumberedString

use of soot.util.NumberedString in project soot by Sable.

the class OnFlyCallGraphBuilder method findReceivers.

private void findReceivers(SootMethod m, Body b) {
    for (final Unit u : b.getUnits()) {
        final Stmt s = (Stmt) u;
        if (s.containsInvokeExpr()) {
            InvokeExpr ie = s.getInvokeExpr();
            if (ie instanceof InstanceInvokeExpr) {
                InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
                Local receiver = (Local) iie.getBase();
                NumberedString subSig = iie.getMethodRef().getSubSignature();
                addVirtualCallSite(s, m, receiver, iie, subSig, Edge.ieToKind(iie));
                if (subSig == sigStart) {
                    addVirtualCallSite(s, m, receiver, iie, sigRun, Kind.THREAD);
                } else if (subSig == sigExecutorExecute || subSig == sigHandlerPost || subSig == sigHandlerPostAtFrontOfQueue || subSig == sigHandlerPostAtTime || subSig == sigHandlerPostAtTimeWithToken || subSig == sigHandlerPostDelayed) {
                    if (iie.getArgCount() > 0) {
                        Value runnable = iie.getArg(0);
                        if (runnable instanceof Local)
                            addVirtualCallSite(s, m, (Local) runnable, iie, sigRun, Kind.EXECUTOR);
                    }
                } else if (subSig == sigHandlerSendEmptyMessage || subSig == sigHandlerSendEmptyMessageAtTime || subSig == sigHandlerSendEmptyMessageDelayed || subSig == sigHandlerSendMessage || subSig == sigHandlerSendMessageAtFrontOfQueue || subSig == sigHandlerSendMessageAtTime || subSig == sigHandlerSendMessageDelayed) {
                    addVirtualCallSite(s, m, receiver, iie, sigHandlerHandleMessage, Kind.HANDLER);
                } else if (subSig == sigExecute) {
                    addVirtualCallSite(s, m, receiver, iie, sigDoInBackground, Kind.ASYNCTASK);
                }
            } else if (ie instanceof DynamicInvokeExpr) {
                if (options.verbose())
                    logger.debug("" + "WARNING: InvokeDynamic to " + ie + " not resolved during call-graph construction.");
            } else {
                SootMethod tgt = ie.getMethod();
                if (tgt != null) {
                    addEdge(m, s, tgt);
                    String signature = tgt.getSignature();
                    if (signature.equals("<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction)>") || signature.equals("<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction)>") || signature.equals("<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)>") || signature.equals("<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)>")) {
                        Local receiver = (Local) ie.getArg(0);
                        addVirtualCallSite(s, m, receiver, null, sigObjRun, Kind.PRIVILEGED);
                    }
                } else {
                    if (!Options.v().ignore_resolution_errors()) {
                        throw new InternalError("Unresolved target " + ie.getMethod() + ". Resolution error should have occured earlier.");
                    }
                }
            }
        }
    }
}
Also used : NumberedString(soot.util.NumberedString) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) Value(soot.Value) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) Local(soot.Local) SootMethod(soot.SootMethod) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) NumberedString(soot.util.NumberedString) Unit(soot.Unit) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) Stmt(soot.jimple.Stmt)

Example 5 with NumberedString

use of soot.util.NumberedString in project soot by Sable.

the class SootClass method declaresMethod.

/**
 * Does this class declare a method with the given subsignature?
 */
public boolean declaresMethod(String subsignature) {
    checkLevel(SIGNATURES);
    NumberedString numberedString = Scene.v().getSubSigNumberer().find(subsignature);
    return numberedString == null ? false : declaresMethod(numberedString);
}
Also used : NumberedString(soot.util.NumberedString)

Aggregations

NumberedString (soot.util.NumberedString)7 RefType (soot.RefType)3 SootMethod (soot.SootMethod)3 Type (soot.Type)3 HashSet (java.util.HashSet)2 AnySubType (soot.AnySubType)2 ArrayType (soot.ArrayType)2 Local (soot.Local)2 InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)2 AllocNode (soot.jimple.spark.pag.AllocNode)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 FastHierarchy (soot.FastHierarchy)1 NullType (soot.NullType)1 SootClass (soot.SootClass)1 Unit (soot.Unit)1 Value (soot.Value)1 AssignStmt (soot.jimple.AssignStmt)1 DynamicInvokeExpr (soot.jimple.DynamicInvokeExpr)1 InvokeExpr (soot.jimple.InvokeExpr)1