private boolean fieldIsInitiallyLocal(SootField field) { if (field.isStatic()) { // Static fields are always shared return false; } else if (field.isPrivate()) { // Private fields may be local return true; } else { return !externalFields.contains(field); } }
/** * Returns the set of objects pointed to by instance field f of the objects in the PointsToSet s. */ public PointsToSet reachingObjects(PointsToSet s, final SootField f) { if (f.isStatic()) { throw new RuntimeException("The parameter f must be an *instance* field."); } return reachingObjectsInternal(s, f); }
public ArrayList<SootField> findFinalFields() { // first thing is to get a list of all final fields in the class ArrayList<SootField> interestingFinalFields = new ArrayList<SootField>(); Iterator fieldIt = sootClass.getFields().iterator(); while (fieldIt.hasNext()) { SootField tempField = (SootField) fieldIt.next(); if (tempField.isFinal()) { // if its static final and method is static add if (tempField.isStatic() && sootMethod.getName().compareTo("<clinit>") == 0) { interestingFinalFields.add(tempField); } // if its non static and final and method is constructor add if ((!tempField.isStatic()) && sootMethod.getName().compareTo("<init>") == 0) { interestingFinalFields.add(tempField); } } } return interestingFinalFields; }
public SootFieldRef makeRef() { return Scene.v().makeFieldRef(declaringClass, name, type, isStatic()); }
/** Returns the set of objects pointed to by static field f. */ public PointsToSet reachingObjects(SootField f) { if (!f.isStatic()) { throw new RuntimeException("The parameter f must be a *static* field."); } VarNode n = findGlobalVarNode(f); if (n == null) { return EmptyPointsToSet.v(); } return n.getP2Set(); }
public boolean isFieldLocalToParent(SootField sf) // To parent class! { // Handle obvious case if (sf.isStatic()) { return false; } ClassLocalObjectsAnalysis cloa = getClassLocalObjectsAnalysis(sf.getDeclaringClass()); return cloa.isFieldLocal(sf); }
public void fieldRef(SootFieldRef f) { handleIndent(); if (baf || f.resolve().isStatic()) { output.append(f.declaringClass().getName()); literal("."); } output.append(f.name()); }
private void handleClass(SootClass cl) { for (Iterator<SootField> fIt = cl.getFields().iterator(); fIt.hasNext();) { final SootField f = fIt.next(); if (!f.isStatic()) { continue;
Value rightOp = ((DefinitionStmt) next).getRightOp(); if (rightOp instanceof FieldRef) { if (((FieldRef) rightOp).getField().isStatic()) {
if (field == null) { exceptions.add(new UnitValidationException(unit, body, "Resolved field is null: " + fr.toString())); } else if (!field.isStatic() && !field.isPhantom()) { exceptions .add(new UnitValidationException(unit, body, "Trying to get a static field which is non-static: " + v)); if (field == null) { exceptions.add(new UnitValidationException(unit, body, "Resolved field is null: " + fr.toString())); } else if (field.isStatic() && !field.isPhantom()) { exceptions.add(new UnitValidationException(unit, body, "Trying to get an instance field which is static: " + v));
private SootField checkStatic(SootField ret) { if ((Options.v().wrong_staticness() == Options.wrong_staticness_fail || Options.v().wrong_staticness() == Options.wrong_staticness_fixstrict) && ret.isStatic() != isStatic() && !ret.isPhantom()) { throw new ResolutionFailedException("Resolved " + this + " to " + ret + " which has wrong static-ness"); } return ret; }
private static soot.SootMethod makeOuterThisAccessMethod(soot.SootClass classToInvoke) { String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); paramTypes.add(classToInvoke.getType()); soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, classToInvoke.getFieldByName("this$0").getType(), soot.Modifier.STATIC); classToInvoke.addMethod(meth); PrivateFieldAccMethodSource src = new PrivateFieldAccMethodSource(classToInvoke.getFieldByName("this$0").getType(), "this$0", classToInvoke.getFieldByName("this$0").isStatic(), classToInvoke); meth.setActiveBody(src.getBody(meth, null)); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
if (sf.isStatic() || !sm.isStatic()) { EquivalentValue fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, sf); fieldsStaticsParamsAccessed.add(fieldRefEqVal); while (scFieldsIt.hasNext()) { SootField scField = scFieldsIt.next(); if (scField.isStatic() || !sm.isStatic()) { EquivalentValue fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, scField); fieldsStaticsParamsAccessed.add(fieldRefEqVal);
@Override public PointsToSet reachingObjects(SootField f) { if (!hasExecuted) { return super.reachingObjects(f); } if (!f.isStatic()) { throw new RuntimeException("The parameter f must be a *static* field."); } VarNode vn = findGlobalVarNode(f); if (vn == null) { return EmptyPointsToSet.v(); } IVarAbstraction pn = consG.get(vn); if (pn == null) { return vn.getP2Set(); } // Lookup the cache if (hasTransformed || vn.getP2Set() != EmptyPointsToSet.v()) { return vn.getP2Set(); } // We transform and cache the result for the next query pn = pn.getRepresentative(); PointsToSetInternal ptSet = vn.makeP2Set(); for (AllocNode obj : pn.getRepresentative().get_all_points_to_objects()) { ptSet.add(obj); } return ptSet; }
private void printFieldRef(FieldRef v) { String refTypeName = v.getClass().getSimpleName(); p.openBlock(); String oldName = varName; SootField f = v.getField(); ttp.setVariableName("type"); f.getType().apply(ttp); p.print("SootFieldRef fieldRef = "); p.printNoIndent("Scene.v().makeFieldRef("); String className = f.getDeclaringClass().getName(); p.printNoIndent("Scene.v().getSootClass(\"" + className + "\"),"); p.printNoIndent("\"" + f.getName() + "\","); p.printNoIndent("type,"); p.printNoIndent(f.isStatic() + ");"); p.println("Value " + oldName + " = Jimple.v().new" + refTypeName + "(fieldRef);"); varName = oldName; p.closeBlock(); }
for (Iterator baseFieldIt = baseClass.getFields().iterator(); baseFieldIt.hasNext();) { SootField baseField = (SootField) baseFieldIt.next(); if (!baseField.isStatic()) { ret.addFieldRef(base, baseField);
if (((SootField) field).isStatic()) { ref = new DStaticFieldRef(tempFieldRef, true); } else {
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { // Some apps reference static fields as instance fields. We need to fix // this for not breaking the client analysis. for (Iterator<Unit> unitIt = b.getUnits().iterator(); unitIt.hasNext();) { Stmt s = (Stmt) unitIt.next(); if (s.containsFieldRef() && s instanceof AssignStmt) { FieldRef ref = s.getFieldRef(); // Make sure that the target class has already been loaded if (isTypeLoaded(ref.getFieldRef().type())) { try { if (ref instanceof InstanceFieldRef) { SootField fld = ref.getField(); if (fld != null && fld.isStatic()) { AssignStmt assignStmt = (AssignStmt) s; if (assignStmt.getLeftOp() == ref) { assignStmt.setLeftOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } else if (assignStmt.getRightOp() == ref) { assignStmt.setRightOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } } } } catch (ConflictingFieldRefException ex) { // That field is broken, just don't touch it } } } } }
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if (sf.isStatic()) { return new CachedEquivalentValue(Jimple.v().newStaticFieldRef(sf.makeRef())); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if (sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } } }
if (sf.isStatic()) { Stmt initStmt = Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(sf.makeRef()), constant); if (smInit == null) {