final public boolean castNeverFails(Type src, Type dst) { if (fh == null) { return true; } else if (dst == null) { return true; } else if (dst == src) { return true; } else if (src == null) { return false; } else if (src instanceof NullType) { return true; } else if (src instanceof AnySubType) { return true; } else if (dst instanceof NullType) { return false; } else if (dst instanceof AnySubType) { throw new RuntimeException("oops src=" + src + " dst=" + dst); } else { return getFastHierarchy().canStoreType(src, dst); } }
if (fh.canStoreType(paramType, rType)) { return true;
public static boolean ancestor_(Type ancestor, Type child) { if (TypeResolver.typesEqual(ancestor, child)) { return true; } else if (child instanceof BottomType) { return true; } else if (ancestor instanceof BottomType) { return false; } else if (ancestor instanceof IntegerType && child instanceof IntegerType) { return true; } else if (ancestor instanceof PrimType || child instanceof PrimType) { return false; } else if (child instanceof NullType) { return true; } else if (ancestor instanceof NullType) { return false; } else { return Scene.v().getOrMakeFastHierarchy().canStoreType(child, ancestor); } }
/** Adds to the set all pairs (l,type) where type is any supertype of t. */ public void localMustBeSubtypeOf(Local l, RefType t) { FastHierarchy fh = Scene.v().getFastHierarchy(); for (Type type : types) { RefType supertype = (RefType) type; if (fh.canStoreType(t, supertype)) { set(indexOf(l, supertype)); } } }
protected void checkNode(Node container, Node n, Node upstream) { if (container.getReplacement() != container) { throw new RuntimeException("container " + container + " is illegal"); } if (upstream.getReplacement() != upstream) { throw new RuntimeException("upstream " + upstream + " is illegal"); } PointsToSetInternal p2set = container.getP2Set(); FastHierarchy fh = pag.getTypeManager().getFastHierarchy(); if (!p2set.contains(n) && (fh == null || container.getType() == null || fh.canStoreType(n.getType(), container.getType()))) { logger.debug("Check failure: " + container + " does not have " + n + "; upstream is " + upstream); } }
protected void checkNode(Node container, Node n, Node upstream) { if (container.getReplacement() != container) { throw new RuntimeException("container " + container + " is illegal"); } if (upstream.getReplacement() != upstream) { throw new RuntimeException("upstream " + upstream + " is illegal"); } PointsToSetInternal p2set = container.getP2Set(); FastHierarchy fh = pag.getTypeManager().getFastHierarchy(); if (!p2set.contains(n) && (fh == null || container.getType() == null || fh.canStoreType(n.getType(), container.getType()))) { logger.debug("Check failure: " + container + " does not have " + n + "; upstream is " + upstream); } }
private static soot.Local getLocalOfType(soot.Body body, soot.Type type) { soot.FastHierarchy fh = InitialResolver.v().hierarchy(); Iterator stmtsIt = body.getUnits().iterator(); soot.Local correctLocal = null; while (stmtsIt.hasNext()) { soot.jimple.Stmt s = (soot.jimple.Stmt) stmtsIt.next(); if (s instanceof soot.jimple.IdentityStmt && (s.hasTag("EnclosingTag") || s.hasTag("QualifyingTag"))) { Iterator it = s.getDefBoxes().iterator(); while (it.hasNext()) { soot.ValueBox vb = (soot.ValueBox) it.next(); if ((vb.getValue() instanceof soot.Local) && (fh.canStoreType(type, vb.getValue().getType()))) { // (vb.getValue().getType().equals(type))){ correctLocal = (soot.Local) vb.getValue(); } } } } return correctLocal; }
private static boolean bodyHasLocal(soot.Body body, soot.Type type) { soot.FastHierarchy fh = InitialResolver.v().hierarchy(); Iterator stmtsIt = body.getUnits().iterator(); while (stmtsIt.hasNext()) { soot.jimple.Stmt s = (soot.jimple.Stmt) stmtsIt.next(); if (s instanceof soot.jimple.IdentityStmt && (s.hasTag("EnclosingTag") || s.hasTag("QualifyingTag"))) { Iterator it = s.getDefBoxes().iterator(); while (it.hasNext()) { soot.ValueBox vb = (soot.ValueBox) it.next(); if ((vb.getValue() instanceof soot.Local) && (fh.canStoreType(type, vb.getValue().getType()))) { // (vb.getValue().getType().equals(type))){ return true; } } } } return false; /* * soot.FastHierarchy fh = InitialResolver.v().hierarchy(); Iterator it = body.getDefBoxes().iterator(); while * (it.hasNext()){ soot.ValueBox vb = (soot.ValueBox)it.next(); if ((vb.getValue() instanceof soot.Local) && * (fh.canStoreType(type, vb.getValue().getType()))){//(vb.getValue().getType().equals(type))){ return true; } } return * false; */ }
protected Set<SootMethod> getCallTargetsForType(Type type, NumberedString methodStr, Type receiverType, Set<SootMethod> possibleTargets) { if (!pag.getTypeManager().castNeverFails(type, receiverType)) { return Collections.<SootMethod>emptySet(); } if (type instanceof AnySubType) { AnySubType any = (AnySubType) type; RefType refType = any.getBase(); if (pag.getTypeManager().getFastHierarchy().canStoreType(receiverType, refType) || pag.getTypeManager().getFastHierarchy().canStoreType(refType, receiverType)) { return possibleTargets; } else { return Collections.<SootMethod>emptySet(); } } if (type instanceof ArrayType) { // we'll invoke the java.lang.Object method in this // case // Assert.chk(varNodeType.toString().equals("java.lang.Object")); type = Scene.v().getSootClass("java.lang.Object").getType(); } RefType refType = (RefType) type; SootMethod targetMethod = null; targetMethod = VirtualCalls.v().resolveNonSpecial(refType, methodStr); return Collections.<SootMethod>singleton(targetMethod); }
return false; } else { return canStoreType(achild.baseType, aparent.baseType);
AnySubType any = (AnySubType) type; RefType refType = any.getBase(); if (pag.getTypeManager().getFastHierarchy().canStoreType(receiverType, refType) || pag.getTypeManager().getFastHierarchy().canStoreType(refType, receiverType)) { return true;
public boolean addAllocEdge(AllocNode from, VarNode to) { FastHierarchy fh = typeManager.getFastHierarchy(); if (fh == null || to.getType() == null || fh.canStoreType(from.getType(), to.getType())) { if (doAddAllocEdge(from, to)) { edgeQueue.add(from); edgeQueue.add(to); return true; } } return false; }
if (declaredType != null && !fastHierachy.canStoreType(t, declaredType)) { return; if (sigType != null && !fastHierachy.canStoreType(t, sigType)) { return;
public SootMethod resolveSpecial(SpecialInvokeExpr iie, NumberedString subSig, SootMethod container, boolean appOnly) { SootMethod target = iie.getMethod(); /* cf. JVM spec, invokespecial instruction */ if (Scene.v().getOrMakeFastHierarchy().canStoreType(container.getDeclaringClass().getType(), target.getDeclaringClass().getType()) && container.getDeclaringClass().getType() != target.getDeclaringClass().getType() && !target.getName().equals("<init>") && subSig != sigClinit) { return resolveNonSpecial(container.getDeclaringClass().getSuperclass().getType(), subSig, appOnly); } else { return target; } }
public static soot.Local getThisGivenOuter(soot.Type sootType, HashMap getThisMap, soot.Body body, LocalGenerator lg, soot.Local t2) { if (InitialResolver.v().hierarchy() == null) { InitialResolver.v().hierarchy(new soot.FastHierarchy()); } soot.FastHierarchy fh = InitialResolver.v().hierarchy(); while (!fh.canStoreType(t2.getType(), sootType)) { soot.SootClass classToInvoke = ((soot.RefType) t2.getType()).getSootClass(); // make an access method and add it to that class for accessing // its private this$0 field soot.SootMethod methToInvoke = makeOuterThisAccessMethod(classToInvoke); // generate a local that corresponds to the invoke of that meth soot.Local t3 = lg.generateLocal(methToInvoke.getReturnType()); ArrayList methParams = new ArrayList(); methParams.add(t2); soot.Local res = getPrivateAccessFieldInvoke(methToInvoke.makeRef(), methParams, body, lg); soot.jimple.AssignStmt assign = soot.jimple.Jimple.v().newAssignStmt(t3, res); body.getUnits().add(assign); t2 = t3; } getThisMap.put(sootType, t2); return t2; }
public void caseCastExpr(CastExpr expr) { result = result.add(mgr.RESOLVE_CLASS_ERRORS); Type fromType = expr.getOp().getType(); Type toType = expr.getCastType(); if (toType instanceof RefLikeType) { // fromType might still be unknown when we are called, // but toType will have a value. FastHierarchy h = Scene.v().getOrMakeFastHierarchy(); if (fromType == null || fromType instanceof UnknownType || ((!(fromType instanceof NullType)) && (!h.canStoreType(fromType, toType)))) { result = result.add(mgr.CLASS_CAST_EXCEPTION); } } result = result.add(mightThrow(expr.getOp())); }
for (Iterator<VirtualCallSite> siteIt = receiverToSites.get(receiver).iterator(); siteIt.hasNext();) { final VirtualCallSite site = siteIt.next(); if (site.kind() == Kind.THREAD && !fh.canStoreType(type, clRunnable)) { continue; if (site.kind() == Kind.EXECUTOR && !fh.canStoreType(type, clRunnable)) { continue; if (site.kind() == Kind.ASYNCTASK && !fh.canStoreType(type, clAsyncTask)) { continue; if (site.kind() == Kind.HANDLER && !fh.canStoreType(type, clHandler)) { continue;
@Override public void caseCastExpr(CastExpr expr) { if (expr.getCastType() instanceof PrimType) { // No exception are thrown for primitive casts return; } Type fromType = expr.getOp().getType(); Type toType = expr.getCastType(); result = result.add(mgr.RESOLVE_CLASS_ERRORS); if (toType instanceof RefLikeType) { // fromType might still be unknown when we are called, // but toType will have a value. FastHierarchy h = Scene.v().getOrMakeFastHierarchy(); if (fromType == null || fromType instanceof UnknownType || ((!(fromType instanceof NullType)) && (!h.canStoreType(fromType, toType)))) { result = result.add(mgr.CLASS_CAST_EXCEPTION); } } result = result.add(mightThrow(expr.getOp())); } };
body.getUnits().add(fieldAssignStmt); if (fh.canStoreType(t1.getType(), sootType)) { getThisMap.put(sootType, t1); return t1;
addToClass = body.getMethod().getDeclaringClass().getOuterClass(); while (!InitialResolver.v().hierarchy().canStoreType(containingClass.getType(), addToClass.getType())) { if (addToClass.hasOuterClass()) { addToClass = addToClass.getOuterClass();