soot.toolkits.scalar.Pair Java Examples

The following examples show how to use soot.toolkits.scalar.Pair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: APIVulnManager.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void isParamVulnAndStore(SootMethod originMethod, Stmt originStmt, Value reachedValue) { //avoid sideeffect
	//constant already guaranteed by caller
	System.out.println(originStmt);
	String funcSig = originStmt.getInvokeExpr().getMethod().getSignature();
	String valueString = reachedValue.toString();
	if (evaluateResult(funcSig, valueString)) {
		if(DEBUG) {
			System.out.println("result found");
			System.out.println("originstmt: " + originStmt + " reachedValue: " + reachedValue);
		}
		this.results.add(new Pair<>(originMethod, new Pair<>(originStmt, valueString)));
	}
	if(DEBUG) {
		if (reachedValue instanceof Constant || reachedValue instanceof StaticFieldRef) {
			System.out.println("originstmt: " + originStmt + " reachedValue: " + reachedValue);
		}
	}
}
 
Example #2
Source File: ValidMatches.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public ValidMatches(PAG pag, FieldToEdgesMap fieldToStores) {
	for (Iterator iter = pag.loadSources().iterator(); iter.hasNext();) {
		FieldRefNode loadSource = (FieldRefNode) iter.next();
		SparkField field = loadSource.getField();
		VarNode loadBase = loadSource.getBase();
		ArraySet<Pair<VarNode, VarNode>> storesOnField = fieldToStores.get(field);
		for (Pair<VarNode, VarNode> store : storesOnField) {
			VarNode storeBase = store.getO2();				
			if (loadBase.getP2Set().hasNonEmptyIntersection(storeBase.getP2Set())) {
				VarNode matchSrc = store.getO1();
				Node[] loadTargets = pag.loadLookup(loadSource);
				for (int i = 0; i < loadTargets.length; i++) {
					VarNode matchTgt = (VarNode) loadTargets[i];
					vMatchEdges.put(matchSrc, matchTgt);
					vMatchBarEdges.put(matchTgt, matchSrc);
				}
			}				
		}
	}
}
 
Example #3
Source File: SootUtil.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public static FieldAccessMap buildStoreMap(PAG pag) {
  FieldAccessMap ret = new FieldAccessMap();
  Iterator frNodeIter = pag.storeInvSourcesIterator();
  while (frNodeIter.hasNext()) {
    FieldRefNode frNode = (FieldRefNode) frNodeIter.next();
    SparkField field = frNode.getField();
    Node[] targets = pag.storeInvLookup(frNode);
    for (int i = 0; i < targets.length; i++) {
      VarNode target = (VarNode) targets[i];
      if (target instanceof GlobalVarNode)
        continue;
      ret.put(field, new Pair<FieldRefNode, LocalVarNode>(frNode, (LocalVarNode) target));
    }
  }
  return ret;
}
 
Example #4
Source File: MethodNodeFactory.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
final public void caseNewMultiArrayExpr( NewMultiArrayExpr nmae ) {
    ArrayType type = (ArrayType) nmae.getType();
    AllocNode prevAn = pag.makeAllocNode(
        new Pair<Expr, Integer>( nmae, new Integer( type.numDimensions ) ), type, method );
    VarNode prevVn = pag.makeLocalVarNode( prevAn, prevAn.getType(), method );
    mpag.addInternalEdge( prevAn, prevVn );
    setResult( prevAn );
    while( true ) {
        Type t = type.getElementType();
        if( !( t instanceof ArrayType ) ) break;
        type = (ArrayType) t;
        AllocNode an = pag.makeAllocNode(
            new Pair<Expr, Integer>( nmae, new Integer( type.numDimensions ) ), type, method );
        VarNode vn = pag.makeLocalVarNode( an, an.getType(), method );
        mpag.addInternalEdge( an, vn );
        mpag.addInternalEdge( vn, pag.makeFieldRefNode( prevVn, ArrayElement.v() ) );
        prevAn = an;
        prevVn = vn;
    }
}
 
Example #5
Source File: VarNode.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/** Returns true if this VarNode represents the THIS pointer */
public boolean isThisPtr()
{
	if ( variable instanceof Pair ) {
		Pair o = (Pair)variable;
		return o.isThisParameter();
	}
	
	return false;
}
 
Example #6
Source File: MethodNodeFactory.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
final public void caseCastExpr( CastExpr ce ) {
Pair<Expr, String> castPair = new Pair<Expr, String>( ce, PointsToAnalysis.CAST_NODE );
ce.getOp().apply( this );
Node opNode = getNode();
Node castNode = pag.makeLocalVarNode( castPair, ce.getCastType(), method );
mpag.addInternalEdge( opNode, castNode );
setResult( castNode );
   }
 
Example #7
Source File: MethodNodeFactory.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
final public void casePhiExpr(PhiExpr e) {
    Pair<Expr, String> phiPair = new Pair<Expr, String>( e, PointsToAnalysis.PHI_NODE );
    Node phiNode = pag.makeLocalVarNode( phiPair, e.getType(), method );
    for (Value op : e.getValues()) {
        op.apply( MethodNodeFactory.this );
        Node opNode = getNode();
        mpag.addInternalEdge( opNode, phiNode );
    }
    setResult( phiNode );
}
 
Example #8
Source File: MethodNodeFactory.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
final public Node caseParm( int index ) {
    VarNode ret = pag.makeLocalVarNode(
                new Pair<SootMethod, Integer>( method, new Integer( index ) ),
                method.getParameterType( index ), method );
    ret.setInterProcTarget();
    return ret;
}
 
Example #9
Source File: MethodNodeFactory.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
final public Node caseThis() {
VarNode ret = pag.makeLocalVarNode(
	    new Pair<SootMethod, String>( method, PointsToAnalysis.THIS_NODE ),
	    method.getDeclaringClass().getType(), method );
       ret.setInterProcTarget();
       return ret;
   }
 
Example #10
Source File: GlobalNodeFactory.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
final public Node caseNewInstance( VarNode cls ) {
       if( cls instanceof ContextVarNode ) cls = pag.findLocalVarNode( cls.getVariable() );
VarNode local = pag.makeGlobalVarNode( cls, RefType.v( "java.lang.Object" ) );
       for (SootClass cl : Scene.v().dynamicClasses()) {
           AllocNode site = pag.makeAllocNode( new Pair<VarNode, SootClass>(cls, cl), cl.getType(), null );
           pag.addEdge( site, local );
       }
       return local;
   }
 
Example #11
Source File: SynchronizedRegion.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public SynchronizedRegion()
{
	this.prepStmt = null;
	this.entermonitor = null;
	this.beginning = null;
	this.earlyEnds = new ArrayList<Pair<Stmt, Stmt>>();
	this.exceptionalEnd = null;
	this.end = null;
	this.last = null;
	this.after = null;
}
 
Example #12
Source File: SynchronizedRegion.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public SynchronizedRegion(SynchronizedRegion sr)
{
	this.prepStmt = sr.prepStmt;
	this.entermonitor = sr.entermonitor;
	this.beginning = sr.beginning;
	this.earlyEnds = new ArrayList<Pair<Stmt, Stmt>>();
	this.earlyEnds.addAll(sr.earlyEnds);
	this.exceptionalEnd = null;
	this.end = sr.end;
	this.last = sr.last;
	this.after = sr.after;
}
 
Example #13
Source File: IntValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return all possible values for an integer local variable.
 * 
 * @param start The statement where the analysis should start.
 * @param local The local variable whose values we are looking for.
 * @param visitedStmts The set of visited statement.
 * @return The set of possible values for the local variable.
 */
private Set<Object> findIntAssignmentsForLocal(Stmt start, Local local, Set<Stmt> visitedStmts) {
  List<DefinitionStmt> assignStmts =
      findAssignmentsForLocal(start, local, true, new HashSet<Pair<Unit, Local>>());
  Set<Object> result = new HashSet<>(assignStmts.size());

  for (DefinitionStmt assignStmt : assignStmts) {
    Value rhsValue = assignStmt.getRightOp();
    if (rhsValue instanceof IntConstant) {
      result.add(((IntConstant) rhsValue).value);
    } else if (rhsValue instanceof LongConstant) {
      result.add(((LongConstant) rhsValue).value);
    } else if (rhsValue instanceof ParameterRef) {
      ParameterRef parameterRef = (ParameterRef) rhsValue;
      Iterator<Edge> edges =
          Scene.v().getCallGraph()
              .edgesInto(AnalysisParameters.v().getIcfg().getMethodOf(assignStmt));
      while (edges.hasNext()) {
        Edge edge = edges.next();
        InvokeExpr invokeExpr = edge.srcStmt().getInvokeExpr();
        Value argValue = invokeExpr.getArg(parameterRef.getIndex());
        if (argValue instanceof IntConstant) {
          result.add(((IntConstant) argValue).value);
        } else if (argValue instanceof LongConstant) {
          result.add(((LongConstant) argValue).value);
        } else if (argValue instanceof Local) {
          Set<Object> newResults =
              findIntAssignmentsForLocal(edge.srcStmt(), (Local) argValue, visitedStmts);
          result.addAll(newResults);
        } else {
          result.add(TOP_VALUE);
        }
      }
    } else {
      return Collections.singleton((Object) TOP_VALUE);
    }
  }

  return result;
}
 
Example #14
Source File: SparkNativeHelper.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected void assignObjectToImpl(ReferenceVariable lhs, AbstractObject obj) {
AllocNode objNode = pag.makeAllocNode( 
	new Pair( "AbstractObject", obj.getType() ),
	 obj.getType(), null );

       VarNode var;
       if( lhs instanceof FieldRefNode ) {
    var = pag.makeGlobalVarNode( objNode, objNode.getType() );
           pag.addEdge( (Node) lhs, var );
       } else {
           var = (VarNode) lhs;
       }
       pag.addEdge( objNode, var );
   }
 
Example #15
Source File: Parm.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public static Parm v( SootMethod m, int index ) {
    Pair<SootMethod, Integer> p = new Pair<SootMethod, Integer>( m, new Integer(index) );
    Parm ret = (Parm) G.v().Parm_pairToElement.get( p );
    if( ret == null ) {
        G.v().Parm_pairToElement.put( p, ret = new Parm( m, index ) );
    }
    return ret;
}
 
Example #16
Source File: ClassValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the set of possible values of a variable of type class.
 * 
 * @param value The variable whose value we are looking for.
 * @param start The statement where the analysis should start.
 * @return The set of possible values for the variable.
 */
@Override
public Set<Object> computeVariableValues(Value value, Stmt start) {
  if (value instanceof ClassConstant) {
    return Collections.singleton((Object) ((ClassConstant) value).getValue());
  } else if (value instanceof Local) {
    return processClassAssignments(
        findAssignmentsForLocal(start, (Local) value, true, new HashSet<Pair<Unit, Local>>()),
        new HashSet<Stmt>());
  } else {
    return Collections.singleton((Object) TOP_VALUE);
  }
}
 
Example #17
Source File: PAG.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public Pair<Node, Node> addInterproceduralAssignment(Node from, Node to, Edge e) 
{
	Pair<Node, Node> val = new Pair<Node, Node>(from, to);
	
	if ( runGeomPTA ) {
		Set<Edge> sets = assign2edges.get(val);
		if ( sets == null ) {
			sets = new HashSet<Edge>();
			assign2edges.put(val, sets);
		}
		sets.add(e);
	}
	
	return val;
}
 
Example #18
Source File: DemandCSPointsTo.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected PointsToSetInternal checkContextsForAllocsCache(
		VarAndContext varAndContext, AllocAndContextSet ret,
		PointsToSetInternal locs) {
	PointsToSetInternal retSet = null;
	if (contextsForAllocsCache.containsKey(varAndContext)) {
		for (AllocAndContext allocAndContext : contextsForAllocsCache.get(
				varAndContext).getO2()) {
			if (locs.contains(allocAndContext.alloc)) {
				ret.add(allocAndContext);
			}
		}
		final PointsToSetInternal oldLocs = contextsForAllocsCache.get(
				varAndContext).getO1();
		final PointsToSetInternal tmpSet = new HybridPointsToSet(locs
				.getType(), pag);
		locs.forall(new P2SetVisitor() {

			@Override
			public void visit(Node n) {
				if (!oldLocs.contains(n)) {
					tmpSet.add(n);
				}
			}
		});
		retSet = tmpSet;
		oldLocs.addAll(tmpSet, null);
	} else {
		PointsToSetInternal storedSet = new HybridPointsToSet(locs
				.getType(), pag);
		storedSet.addAll(locs, null);
		contextsForAllocsCache.put(varAndContext,
				new Pair<PointsToSetInternal, AllocAndContextSet>(
						storedSet, new AllocAndContextSet()));
		retSet = locs;
	}
	return retSet;
}
 
Example #19
Source File: SootUtil.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param node
 * @return <code>true</code> if <code>node</code> represents the this
 *         parameter of a method; <code>false</code> otherwise
 */
public static boolean isThisNode(VarNode node) {
  if (node.getVariable() instanceof soot.toolkits.scalar.Pair) {
    soot.toolkits.scalar.Pair pair = (soot.toolkits.scalar.Pair) node.getVariable();
    return (pair.getO1() instanceof SootMethod) && (pair.getO2() == PointsToAnalysis.THIS_NODE);
  }
  return false;
}
 
Example #20
Source File: SootUtil.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isParamNode(VarNode node) {
  if (node.getVariable() instanceof soot.toolkits.scalar.Pair) {
    soot.toolkits.scalar.Pair pair = (soot.toolkits.scalar.Pair) node.getVariable();
    return (pair.getO1() instanceof SootMethod && (pair.getO2() instanceof Integer || pair.getO2() == PointsToAnalysis.THIS_NODE));
  }
  return false;
}
 
Example #21
Source File: Context.java    From vasco with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a new context for phantom method
 * 
 * @param method
 */
public Context(M method) {
	count++;
	this.id = count;
	this.method = method;
	this.inValues = new HashMap<N, A>();
	this.outValues = new HashMap<N, A>();
	this.analysed = false;
	this.workList = new TreeSet<N>();
	this.workListOfEdges = new LinkedList<Pair<N, N>>();
}
 
Example #22
Source File: IFDSPossibleTypes.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Pair<Value,Type> createZeroValue() {
	return new Pair<Value, Type>(Jimple.v().newLocal("<dummy>", UnknownType.v()), UnknownType.v());
}
 
Example #23
Source File: Context.java    From vasco with GNU Lesser General Public License v2.1 4 votes vote down vote up
public LinkedList<Pair<N, N>> getWorkListOfEdges() {
	return this.workListOfEdges;
}
 
Example #24
Source File: IntentTaintFact.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void putPair(Value Value, Pair<IntentSource, DataObject> pair)
{
	facts.put(Value, pair);
}
 
Example #25
Source File: IntentTaintFact.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Pair<IntentSource, DataObject> getPairFromValue(Value value)
{
	return facts.get(value);
}
 
Example #26
Source File: BackwardValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns all assignments for a local variable. This walks the interprocedural control flow graph
 * back from a statement looking for all assignments to a given local variable.
 * 
 * @param start The statement where the analysis should start.
 * @param local The local variable whose assignments should be found.
 * @param init A boolean that indicates whether the analysis should be initialized. This should
 *          always be true for non-recursive calls.
 * @param visitedUnits The set of statements visited by the analysis.
 * @return The set of assignment statements for the local variable.
 */
protected List<DefinitionStmt> findAssignmentsForLocal(Unit start, Local local, boolean init,
    Set<Pair<Unit, Local>> visitedUnits) {
  if (logger.isDebugEnabled()) {
    logger.debug("Finding assignments for local " + local);
  }
  SootMethod method = AnalysisParameters.v().getIcfg().getMethodOf(start);
  ExceptionalUnitGraph graph = new ExceptionalUnitGraph(method.getActiveBody());
  List<DefinitionStmt> result = new ArrayList<DefinitionStmt>();

  Stack<Unit> stack = new Stack<Unit>();
  stack.push(start);
  if (init) {
    visitedUnits.clear();
  }

  while (!stack.empty()) {
    Unit current = stack.pop();
    if (logger.isDebugEnabled()) {
      logger.debug(current + " " + current.getClass());
    }
    Pair<Unit, Local> pair = new Pair<Unit, Local>(current, local);
    if (visitedUnits.contains(pair)) {
      continue;
    }
    visitedUnits.add(pair);
    if (current instanceof IdentityStmt) {
      IdentityStmt identityStmt = (IdentityStmt) current;
      // method.
      if (identityStmt.getLeftOp().equivTo(local)) {
        result.add(identityStmt);
      }
    } else if (current instanceof AssignStmt) {
      AssignStmt assignStmt = (AssignStmt) current;
      if (assignStmt.getLeftOp().equivTo(local)) {
        if (assignStmt.getRightOp() instanceof Local) {
          result.addAll(findAssignmentsForLocal(current, (Local) assignStmt.getRightOp(), false,
              visitedUnits));
        } else {
          result.add(assignStmt);
        }
        // The assignment generates the local on that path.
        // Anything before is irrelevant.
        continue;
      }
    }
    for (Unit pred : graph.getPredsOf(current)) {
      stack.push(pred);
    }
  }

  return result;
}
 
Example #27
Source File: ClassValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns the variable values that are associated with an call statement.
 * 
 * @param sourceStmt The statement at which we should start.
 * @param visitedStmts The set of visited statements.
 * @return The set of possible values.
 */
protected Set<Object> handleInvokeExpression(Stmt sourceStmt, Set<Stmt> visitedStmts) {
  if (visitedStmts.contains(sourceStmt)) {
    return Collections.emptySet();
  } else {
    visitedStmts.add(sourceStmt);
  }
  Iterator<Edge> edges = Scene.v().getCallGraph().edgesOutOf(sourceStmt);
  Set<Object> result = new HashSet<>();

  while (edges.hasNext()) {
    Edge edge = edges.next();
    SootMethod target = edge.getTgt().method();
    if (target.isConcrete()) {
      for (Unit unit : target.getActiveBody().getUnits()) {
        if (unit instanceof ReturnStmt) {
          ReturnStmt returnStmt = (ReturnStmt) unit;

          Value returnValue = returnStmt.getOp();
          if (returnValue instanceof StringConstant) {
            result.add(((StringConstant) returnValue).value);
          } else if (returnValue instanceof ClassConstant) {
            result.add(((ClassConstant) returnValue).value);
          } else if (returnValue instanceof Local) {
            List<DefinitionStmt> assignStmts =
                findAssignmentsForLocal(returnStmt, (Local) returnValue, true,
                    new HashSet<Pair<Unit, Local>>());
            Set<Object> classConstants = processClassAssignments(assignStmts, visitedStmts);
            if (classConstants == null || classConstants.contains(TOP_VALUE)
                || classConstants.contains(Constants.ANY_STRING)) {
              return null;
            } else {
              result.addAll(classConstants);
            }
          } else {
            return null;
          }
        }
      }
    }
  }

  return result;
}
 
Example #28
Source File: IFDSReachingDefinitionWithField.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Map<Unit, Set<Pair<Value, Set<DefinitionStmt>>>> initialSeeds() {
	return DefaultSeeds.make(
			Collections.singleton(Scene.v().getEntryPoints().get(0).getActiveBody()
					.getUnits().getFirst()), zeroValue());
}
 
Example #29
Source File: IFDSPossibleTypes.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Map<Unit, Set<Pair<Value,Type>>> initialSeeds() {
	return DefaultSeeds.make(Collections.singleton(Scene.v().getMainMethod().getActiveBody().getUnits().getFirst()), zeroValue());
}
 
Example #30
Source File: IFDSReachingDefinitions.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Pair<Value, Set<DefinitionStmt>> createZeroValue() {
	return new Pair<Value, Set<DefinitionStmt>>(new JimpleLocal("<<zero>>", NullType.v()), Collections.<DefinitionStmt> emptySet());
}