public List<SootField> getExtFields(SootClass sc) { if (classToExtFieldAccesses.containsKey(sc)) { List extAccesses = classToExtFieldAccesses.get(sc); List<SootField> extFields = new ArrayList<SootField>(); for (Iterator accessIt = extAccesses.iterator(); accessIt.hasNext();) { Pair access = (Pair) accessIt.next(); SootField accessedField = ((Stmt) access.getO2()).getFieldRef().getField(); if (!extFields.contains(accessedField)) { extFields.add(accessedField); } } return extFields; } throw new RuntimeException("UseFinder does not search non-application classes: " + sc); }
public static String getNodeLabel(Object o) { Value node = ((EquivalentValue) o).getValue(); /* * if(node instanceof InstanceFieldRef) { InstanceFieldRef ifr = (InstanceFieldRef) node; if(ifr.getBase() instanceof * FakeJimpleLocal) return ifr.getField().getDeclaringClass().getShortName() + "." + ifr.getFieldRef().name(); else * return ifr.getField().getDeclaringClass().getShortName() + "." + ifr.getFieldRef().name(); } else */ if (node instanceof FieldRef) { FieldRef fr = (FieldRef) node; return fr.getField().getDeclaringClass().getShortName() + "." + fr.getFieldRef().name(); } return node.toString(); } }
public void inDefinitionStmt(DefinitionStmt s) { Value leftOp = s.getLeftOp(); if (leftOp instanceof FieldRef) { // System.out.println("leftOp is a fieldRef:"+s); SootField field = ((FieldRef) leftOp).getField(); // check if this is a final field if (field.isFinal()) { // System.out.println("the field is a final variable"); finalFieldDefined = true; } } }
@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 void checkConditionalUses(ASTCondition cond, ASTNode node) { List<Value> useList = getUseList(cond); // System.out.println("FOR NODE with condition:"+cond+"USE list is:"+useList); // FOR EACH USE Iterator<Value> it = useList.iterator(); while (it.hasNext()) { Value temp = it.next(); if (temp instanceof Local) { addLocalUse((Local) temp, node); } else if (temp instanceof FieldRef) { FieldRef field = (FieldRef) temp; SootField sootField = field.getField(); addFieldUse(sootField, node); } } // end of going through all locals uses in condition }
soot.util.Chain containerStmts = containerBody.getUnits(); SootClass target = ref.getField().getDeclaringClass(); String name = createAccessorName(ref.getField(), false); accessor = target.getMethodByNameUnsafe(name); if (accessor == null) { Type returnType = ref.getField().getType(); Local thisLocal = lg.generateLocal(target.getType()); if (ref instanceof InstanceFieldRef) { accStmts.addFirst(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newParameterRef(target.getType(), 0))); Local l = lg.generateLocal(ref.getField().getType()); Value v; if (ref instanceof InstanceFieldRef) {
public void checkStatementUses(Stmt s, Object useNodeOrStatement) { List useBoxes = s.getUseBoxes(); // remeber getUsesFromBoxes returns both Locals and FieldRefs List<Value> uses = getUsesFromBoxes(useBoxes); Iterator<Value> it = uses.iterator(); while (it.hasNext()) { Value temp = it.next(); if (temp instanceof Local) { addLocalUse((Local) temp, useNodeOrStatement); } else if (temp instanceof FieldRef) { FieldRef field = (FieldRef) temp; SootField sootField = field.getField(); addFieldUse(sootField, useNodeOrStatement); } } }
while (it.hasNext()) { FieldRef field = (FieldRef) it.next(); SootField sootField = field.getField();
public static boolean isObjectLocal(InfoFlowAnalysis dfa, SootMethod method, CallLocalityContext context, Value local) { SmartMethodInfoFlowAnalysis smdfa = dfa.getMethodInfoFlowAnalysis(method); EquivalentValue localEqVal; if (local instanceof InstanceFieldRef) { localEqVal = InfoFlowAnalysis.getNodeForFieldRef(method, ((FieldRef) local).getField()); } else { localEqVal = new CachedEquivalentValue(local); } List<EquivalentValue> sources = smdfa.sourcesOf(localEqVal); Iterator<EquivalentValue> sourcesIt = sources.iterator(); while (sourcesIt.hasNext()) { EquivalentValue source = sourcesIt.next(); if (source.getValue() instanceof Ref) { if (!context.isFieldLocal(source)) { if (printMessages) { logger.debug(" Requested value " + local + " is LOCAL in " + method + " "); } return false; } } } if (printMessages) { logger.debug(" Requested value " + local + " is SHARED in " + method + " "); } return true; } }
localEqVal = InfoFlowAnalysis.getNodeForFieldRef(method, ((FieldRef) local).getField()); } else { localEqVal = new CachedEquivalentValue(local);
protected void ensureProcessed(SootMethod m) { if (processedMethods.contains(m)) { return; } processedMethods.add(m); if (!m.isConcrete()) { return; } if (m.isPhantom()) { return; } for (Iterator sIt = m.retrieveActiveBody().getUnits().iterator(); sIt.hasNext();) { final Stmt s = (Stmt) sIt.next(); if (s instanceof AssignStmt) { AssignStmt as = (AssignStmt) s; Value l = as.getLeftOp(); if (l instanceof FieldRef) { methodToWrite.put(m, ((FieldRef) l).getField()); } Value r = as.getRightOp(); if (r instanceof FieldRef) { methodToRead.put(m, ((FieldRef) r).getField()); } } } }
if (s.containsFieldRef()) { fr = s.getFieldRef(); sf = fr.getField(); if (sf != null) { hasField = true;
FieldRef useField = (FieldRef) use; SootField usedSootField = useField.getField(); Object value = beforeSet.contains(usedSootField.getDeclaringClass().getName(), usedSootField.getName().toString()); if (value != null) {
public static boolean checkAccessRestrictions(SootMethod container, SootMethod target, String modifierOptions) { // Check the body of the method to inline for // method or field access restrictions { Body inlineeBody = target.getActiveBody(); Iterator unitsIt = inlineeBody.getUnits().iterator(); while (unitsIt.hasNext()) { Stmt st = (Stmt) unitsIt.next(); if (st.containsInvokeExpr()) { InvokeExpr ie1 = st.getInvokeExpr(); if (!AccessManager.ensureAccess(container, ie1.getMethod(), modifierOptions)) { return false; } } if (st instanceof AssignStmt) { Value lhs = ((AssignStmt) st).getLeftOp(); Value rhs = ((AssignStmt) st).getRightOp(); if (lhs instanceof FieldRef && !AccessManager.ensureAccess(container, ((FieldRef) lhs).getField(), modifierOptions)) { return false; } if (rhs instanceof FieldRef && !AccessManager.ensureAccess(container, ((FieldRef) rhs).getField(), modifierOptions)) { return false; } } } } return true; }
/** * Returns true if the statement <code>stmt</code> contains an illegal access to a field or method, assuming the statement * is in method <code>container</code> * * @param container * @param stmt * @return */ public static boolean isAccessLegal(SootMethod container, Stmt stmt) { if (stmt.containsInvokeExpr()) { return AccessManager.isAccessLegal(container, stmt.getInvokeExpr().getMethod()); } else if (stmt instanceof AssignStmt) { AssignStmt as = (AssignStmt) stmt; if (as.getRightOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getRightOp(); return AccessManager.isAccessLegal(container, r.getField()); } if (as.getLeftOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getLeftOp(); return AccessManager.isAccessLegal(container, r.getField()); } } return true; }
if (v instanceof FieldRef) { FieldRef fieldRef = (FieldRef) v; SootField f = fieldRef.getField(); if (f.equals(sf)) { if (Modifier.isPublic(sf.getModifiers())) {
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(); }
private SootMethod getOrCreateInitializer(SootClass sc, Set<SootField> alreadyInitialized) { SootMethod smInit; // Create a static initializer if we don't already have one smInit = sc.getMethodByNameUnsafe(SootMethod.staticInitializerName); if (smInit == null) { smInit = Scene.v().makeSootMethod(SootMethod.staticInitializerName, Collections.<Type>emptyList(), VoidType.v()); smInit.setActiveBody(Jimple.v().newBody(smInit)); sc.addMethod(smInit); smInit.setModifiers(Modifier.PUBLIC | Modifier.STATIC); } else if (smInit.isPhantom()) { return null; } else { smInit.retrieveActiveBody(); // We need to collect those variables that are already initialized // somewhere for (Unit u : smInit.getActiveBody().getUnits()) { Stmt s = (Stmt) u; for (ValueBox vb : s.getDefBoxes()) { if (vb.getValue() instanceof FieldRef) { alreadyInitialized.add(((FieldRef) vb.getValue()).getField()); } } } } return smInit; }
v = pag.findLocalVarNode(lhs); } else if (lhs instanceof FieldRef) { v = pag.findGlobalVarNode(((FieldRef) lhs).getField());