public static boolean maybeSameLocation(Value v1, Value v2) { if (!(v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) && !(v1 instanceof ArrayRef && v2 instanceof ArrayRef)) { return v1.equivTo(v2); } if (v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) { InstanceFieldRef ifr1 = (InstanceFieldRef) v1; InstanceFieldRef ifr2 = (InstanceFieldRef) v2; if (!ifr1.getField().getName().equals(ifr2.getField().getName())) return false; Local base1 = (Local) ifr1.getBase(); Local base2 = (Local) ifr2.getBase(); PointsToAnalysis pta = Scene.v().getPointsToAnalysis(); PointsToSet pts1 = pta.reachingObjects(base1); PointsToSet pts2 = pta.reachingObjects(base2); return pts1.hasNonEmptyIntersection(pts2); } else { // v1 instanceof ArrayRef && v2 instanceof ArrayRef ArrayRef ar1 = (ArrayRef) v1; ArrayRef ar2 = (ArrayRef) v2; Local base1 = (Local) ar1.getBase(); Local base2 = (Local) ar2.getBase(); PointsToAnalysis pta = Scene.v().getPointsToAnalysis(); PointsToSet pts1 = pta.reachingObjects(base1); PointsToSet pts2 = pta.reachingObjects(base2); return pts1.hasNonEmptyIntersection(pts2); } }
public boolean instanceFieldRefRedefined(InstanceFieldRef lIFieldRef, List<ValueBox> rUseBoxes) { for (ValueBox rUseBox : rUseBoxes) { Value rBoxValue = rUseBox.getValue(); if (rBoxValue instanceof InstanceFieldRef) { InstanceFieldRef rIFieldRef = (InstanceFieldRef) rBoxValue; if (twoValueEquals(lIFieldRef.getBase(), rIFieldRef.getBase()) && lIFieldRef.getField().equals(rIFieldRef.getField())) { return true; } } } return false; }
public void caseInstanceFieldRef(InstanceFieldRef arg0) { Value base = arg0.getBase(); if (base instanceof Local == false) throw new UnsupportedOperationException("How do I handle base is not a local?"); Local local = (Local) base; Type type = local.getType(); if (type instanceof RefType == false) throw new UnsupportedOperationException("How do I handle type is not a ref type?"); RefType ref = (RefType) type; OpenCLField ocl_field = new OpenCLField(arg0.getField(), ref.getSootClass()); if (isLhs()) { m_output.append(ocl_field.getInstanceSetterInvoke(arg0.getBase())); } else { m_output.append(ocl_field.getInstanceGetterInvoke(arg0.getBase())); } setCheckException(); }
@Override public Set<? extends IAllocNode> getPTSet(Value val, Context context) { // handle case for insensitive run if (k == 0) return getPTSetIns(val); final Set<AllocNode> allocNodes = new LinkedHashSet<AllocNode>(); final Type filteringType = val.getType(); PointsToSetInternal pts = null; try { if (val instanceof InstanceFieldRef) { final InstanceFieldRef ifr = (InstanceFieldRef) val; pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) ifr.getBase(), ifr.getField()); } else if (val instanceof ArrayRef) { ArrayRef arrayRef = (ArrayRef) val; pts = (PointsToSetInternal) ptsProvider.reachingObjectsOfArrayElement( ptsProvider.reachingObjects(context, (Local) arrayRef.getBase())); } else if (val instanceof Local) { pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) val); } else if (val instanceof StaticFieldRef) { SootField field = ((StaticFieldRef) val).getField(); pts = (PointsToSetInternal) ptsProvider.reachingObjects(field); } else if (val instanceof NullConstant) { return allocNodes; } else { logger.error("Unknown reference type for insenstive search: {} {}", val, val.getClass()); droidsafe.main.Main.exit(1); } // visit internal points to set and grab all allocnodes pts.forall( new P2SetVisitor() { public void visit(Node n) { if (typeManager.castNeverFails(n.getType(), filteringType)) allocNodes.add((AllocNode) n); } }); } catch (Exception e) { logger.info("Some sort of error getting context insensitive points to set for {}", val, e); // e.printStackTrace(); } return allocNodes; }
@Override public Type appliesInternal(AndroidMethod method) { SootMethod sm = getSootMethod(method); // We are only interested in getters and setters if (!sm.getName().startsWith("get") && !sm.getName().startsWith("set")) return Type.NOT_SUPPORTED; String baseName = sm.getName().substring(3); String getterName = "get" + baseName; String setterName = "set" + baseName; try { // Find the getter and the setter SootMethod getter = getSootMethod(new AndroidMethod(getterName, "", sm.getDeclaringClass().getName())); SootMethod setter = getSootMethod(new AndroidMethod(setterName, "", sm.getDeclaringClass().getName())); if (getter == null || setter == null) return Type.FALSE; if (!setter.isConcrete() || !getter.isConcrete()) return Type.NOT_SUPPORTED; Body bodyGetter = null; try { bodyGetter = getter.retrieveActiveBody(); } catch (Exception ex) { return Type.NOT_SUPPORTED; } // Find the local that gets returned Local returnLocal = null; for (Unit u : bodyGetter.getUnits()) if (u instanceof ReturnStmt) { ReturnStmt ret = (ReturnStmt) u; if (ret.getOp() instanceof Local) { returnLocal = (Local) ret.getOp(); break; } } if (returnLocal == null) return Type.FALSE; // Find where the local is assigned a value in the code List<FieldRef> accessPath = new ArrayList<FieldRef>(); Local returnBase = returnLocal; while (returnBase != null) for (Unit u : bodyGetter.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp().equals(returnBase)) if (assign.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign.getRightOp(); accessPath.add(0, ref); returnBase = (Local) ref.getBase(); break; } else returnBase = null; } else if (u instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u; if (id.getLeftOp().equals(returnBase)) returnBase = null; } } if (accessPath.isEmpty()) return Type.FALSE; /* // Find the corresponding access path in the setter for (Unit u : bodySetter.getUnits()) if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp() instanceof InstanceFieldRef && assign.getRightOp() instanceof Local) { InstanceFieldRef iref = (InstanceFieldRef) assign.getLeftOp(); if (iref.getFieldRef().toString().equals(accessPath.get(accessPath.size() - 1).getFieldRef().toString())) { // This is a starting point boolean pathFound = false; Local startLocal = (Local) iref.getBase(); int accessPathPos = accessPath.size() - 2; while (startLocal != null) { for (Unit u2 : bodySetter.getUnits()) { if (u2 instanceof AssignStmt) { AssignStmt assign2 = (AssignStmt) u2; if (assign2.getLeftOp().equals(startLocal)) if (assign2.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef ref = (InstanceFieldRef) assign2.getRightOp(); if (accessPath.get(accessPathPos--).getFieldRef().toString().equals(ref.getFieldRef().toString())) { startLocal = (Local) ref.getBase(); break; } else startLocal = null; } else startLocal = null; } else if (u2 instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u2; if (id.getLeftOp().equals(startLocal)) { startLocal = null; pathFound = true; break; } } } } if (pathFound) { if (assign.getRightOp() instanceof Local) { // Find the parameter being set for (Unit u2 : bodySetter.getUnits()) if (u2 instanceof IdentityStmt) { IdentityStmt id = (IdentityStmt) u2; if (id.getLeftOp().equals(assign.getRightOp())) return Type.TRUE; } } break; } } } } return Type.FALSE; */ return Type.TRUE; } catch (Exception ex) { System.err.println("Something went wrong:"); ex.printStackTrace(); return Type.NOT_SUPPORTED; } }