Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2015 The Pennsylvania State University and the University of Wisconsin
   * Systems and Internet Infrastructure Security Laboratory
   *
   * Author: Damien Octeau
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package edu.psu.cse.siis.coal;
 
 
 import java.util.Set;
 
 
 import soot.Hierarchy;
 import soot.Local;
 import soot.Scene;
 import soot.SootClass;
 import soot.Unit;
 import soot.Value;
A factory for normal flow functions. Normal edge functions indicate how symbols (variables) are propagated through normal (non-call) statements.
 
 public class NormalFlowFunctionFactory {
   private final Logger logger = LoggerFactory.getLogger(getClass());

  
Returns a normal flow function.

Parameters:
src The source statement, whose influence will be modeled by the returned function.
dest The destination statement.
zeroValue The zero value, which represents the absence of a data flow fact.
pointsToAnalysis The pointer analysis.
Returns:
A normal flow function.
 
   public FlowFunction<ValuegetNormalFlowFunction(final Unit srcUnit dest,
       final Value zeroValuefinal PointsToAnalysis pointsToAnalysis) {
     if (src instanceof AssignStmt) {
 
       final AssignStmt definitionStmt = (AssignStmtsrc;
 
       final Value left = definitionStmt.getLeftOp();
       final String type = left.getType().toString();
 
       if (Model.v().isModeledType(type)) {
         return new FlowFunction<Value>() {
           @Override
           public Set<ValuecomputeTargets(Value source) {
             if (.isDebugEnabled()) {
               .debug("Normal flow stmt: " + src);
             }
             Value right = definitionStmt.getRightOp();
             Set<Valueres = new HashSet<Value>();
             if (.isDebugEnabled()) {
               .debug("Source: " + source + " " + (source instanceof StaticFieldRef) + " "
                   + (right instanceof StaticFieldRef));
             }
 
             if (source.equivTo(zeroValue) && right instanceof StaticFieldRef) {
               StaticFieldRef rightFieldRef = (StaticFieldRefright;
 
               if (Model.v().getArgumentsForStaticField(rightFieldRef.getField().getSignature()) != null) {
                 if (.isDebugEnabled()) {
                   .debug("Adding constant");
                 }
                 res.add(left);
               }
             } else if (source.equivTo(zeroValue) && right instanceof NullConstant) {
               res.add(left);
             } else if (source instanceof InstanceFieldRef && right instanceof InstanceFieldRef) {
               InstanceFieldRef sourceFieldRef = (InstanceFieldRefsource;
               InstanceFieldRef rightFieldRef = (InstanceFieldRefright;
               PointsToSet sourceBasePointsToSet =
                   pointsToAnalysis.reachingObjects((LocalsourceFieldRef.getBase());
              PointsToSet rightBasePointsToSet =
                  pointsToAnalysis.reachingObjects((LocalrightFieldRef.getBase());
              if (sourceBasePointsToSet.hasNonEmptyIntersection(rightBasePointsToSet)) {
                PointsToSet sourceFieldPointsToSet =
                    pointsToAnalysis.reachingObjects(sourceBasePointsToSet,
                        sourceFieldRef.getField());
                PointsToSet rightFieldPointsToSet =
                    pointsToAnalysis
                        .reachingObjects(rightBasePointsToSetrightFieldRef.getField());
                // Some cases where a field ref was not detected were seen (see
                // application yong.app.yyvideoplayer).
                if (sourceFieldRef.getField().getSubSignature()
                    .equals(rightFieldRef.getField().getSubSignature())
                    || sourceFieldPointsToSet.hasNonEmptyIntersection(rightFieldPointsToSet)) {
                  res.add(left);
                }
              }
            } else if (source instanceof StaticFieldRef && right instanceof StaticFieldRef) {
              StaticFieldRef sourceFieldRef = (StaticFieldRefsource;
              StaticFieldRef rightFieldRef = (StaticFieldRefright;
              PointsToSet sourcePointsToSet =
                  pointsToAnalysis.reachingObjects(sourceFieldRef.getField());
              PointsToSet rightPointsToSet =
                  pointsToAnalysis.reachingObjects(rightFieldRef.getField());
              if (source.toString().equals(right.toString())
                  || sourcePointsToSet.hasNonEmptyIntersection(rightPointsToSet)
                  || haveCommonFields(sourceFieldRef.getFieldRef().declaringClass(), rightFieldRef
                      .getFieldRef().declaringClass())) {
                res.add(left);
              }
            } else if (source.equivTo(right) || source.equals(zeroValue)
                || (right instanceof PhiExpr && ((PhiExprright).getValues().contains(source))
                || (right instanceof PiExpr && ((PiExprright).getValue().equals(source))) {
              res.add(left);
            }
            if (source.equivTo(zeroValue)) {
              res.add(source);
            }
            if (!source.equivTo(left) && !source.equals(zeroValue)
                && !(source.toString().equals(left.toString()) && Model.v().isModeledType(type))) {
              res.add(source);
            }
            if (.isDebugEnabled()) {
              .debug("Returning " + res);
            }
            return res;
          }
        };
      }
    }
    return Identity.v();
  }

  
Determines if two classes have common fields. This includes interface types. For example, this can happen when a class implements an interface or when it subclasses another class.

Parameters:
sootClass1 A Soot class.
sootClass2 Another Soot class.
Returns:
True if the two classes have common fields.
  public boolean haveCommonFields(SootClass sootClass1SootClass sootClass2) {
    if (.isDebugEnabled()) {
      .debug(sootClass1 + "\n" + sootClass2);
    }
    boolean haveCommonFields = false;
    Hierarchy hierarchy = Scene.v().getActiveHierarchy();
    if (sootClass1.isInterface()) {
      if (sootClass2.isInterface()) {
        haveCommonFields =
            hierarchy.isInterfaceSubinterfaceOf(sootClass1sootClass2)
                || hierarchy.isInterfaceSuperinterfaceOf(sootClass1sootClass2);
        if (.isDebugEnabled()) {
          .debug("1: " + haveCommonFields);
        }
      } else {
        haveCommonFields = sootClass2.implementsInterface(sootClass1.getName());
        if (.isDebugEnabled()) {
          .debug("2: " + haveCommonFields);
        }
      }
    } else {
      if (sootClass2.isInterface()) {
        haveCommonFields = sootClass1.implementsInterface(sootClass2.getName());
        if (.isDebugEnabled()) {
          .debug("3: " + haveCommonFields);
        }
      } else {
        haveCommonFields =
            hierarchy.isClassSubclassOf(sootClass1sootClass2)
                || hierarchy.isClassSuperclassOf(sootClass1sootClass2);
        if (.isDebugEnabled()) {
          .debug("4: " + haveCommonFields);
        }
      }
    }
    return haveCommonFields;
  }
New to GrepCode? Check out our FAQ X