Java Code Examples for soot.jimple.AssignStmt#getRightOp()

The following examples show how to use soot.jimple.AssignStmt#getRightOp() . 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: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
private boolean hasConstantIndexAtArrayForSplitDataFlow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		Value value = ass.getRightOp();
		if(value instanceof ArrayRef) {
			ArrayRef aRef = (ArrayRef)value;
			Value index = aRef.getIndex();
			
			if(index instanceof IntConstant)
				return true;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return false;
}
 
Example 2
Source File: ForwardBoomerangSolver.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected boolean killFlow(SootMethod m, Stmt curr, Val value) {
    if (!m.getActiveBody().getLocals().contains(value.value()) && !value.isStatic())
        return true;
    if (curr instanceof AssignStmt) {
        AssignStmt as = (AssignStmt) curr;
        // Kill x at any statement x = * during propagation.
        if (as.getLeftOp().equals(value.value())) {
            // But not for a statement x = x.f
            if (as.getRightOp() instanceof InstanceFieldRef) {
                InstanceFieldRef iie = (InstanceFieldRef) as.getRightOp();
                if (iie.getBase().equals(value.value())) {
                    return false;
                }
            }
            return true;
        }
        if (as.getLeftOp() instanceof StaticFieldRef) {
            StaticFieldRef sfr = (StaticFieldRef) as.getLeftOp();
            if (value.isStatic() && value.equals(new StaticFieldVal(as.getLeftOp(), sfr.getField(), m))) {
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source File: AbstractBoomerangTest.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
public Optional<? extends Query> test(Stmt stmt) {
    if (stmt instanceof AssignStmt) {
        AssignStmt as = (AssignStmt) stmt;
        if (as.getLeftOp().toString().equals("allocation")) {
            Statement statement = new Statement(stmt, staticIcfg.getMethodOf(stmt));
            if (as.getLeftOp() instanceof Local && as.getRightOp() instanceof IntConstant) {
                Local local = (Local) as.getLeftOp();
                ForwardQuery forwardQuery = new ForwardQuery(statement,
                        new AllocVal(local, staticIcfg.getMethodOf(stmt), as.getRightOp(),
                                new Statement(as, staticIcfg.getMethodOf(stmt))));
                return Optional.<Query> of(forwardQuery);
            }

            if (as.containsInvokeExpr()) {
                AtomicReference<Query> returnValue = new AtomicReference<>();
                staticIcfg.addCalleeListener(
                        new IntegerAllocationSiteCalleeListener(returnValue, as, statement, stmt));
                if (returnValue.get() != null) {
                    return Optional.of(returnValue.get());
                }
            }
        }
    }

    return Optional.empty();
}
 
Example 4
Source File: DexNullTransformer.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private boolean isObjectArray(Value v, Body body) {
	for (Unit u : body.getUnits()) {
		if (u instanceof AssignStmt) {
			AssignStmt assign = (AssignStmt) u;
			if (assign.getLeftOp() == v) {
				if (assign.getRightOp() instanceof NewArrayExpr) {
					NewArrayExpr nea = (NewArrayExpr) assign.getRightOp();
					if (isObject(nea.getBaseType()))
						return true;
				}
				else if (assign.getRightOp() instanceof FieldRef) {
					FieldRef fr = (FieldRef) assign.getRightOp();
					if (fr.getType() instanceof ArrayType)
						if (isObject(((ArrayType) fr.getType())
								.getArrayElementType()))
							return true;
				}
			}
		}
	}
	return false;
}
 
Example 5
Source File: TypeStateMachineWeightFunctions.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
protected Collection<WeightedForwardQuery<TransitionFunction>> generateAtAllocationSiteOf(SootMethod m, Unit unit,
        Class allocationSuperType) {
    if (unit instanceof AssignStmt) {
        AssignStmt assignStmt = (AssignStmt) unit;
        if (assignStmt.getRightOp() instanceof NewExpr) {
            NewExpr newExpr = (NewExpr) assignStmt.getRightOp();
            Value leftOp = assignStmt.getLeftOp();
            soot.Type type = newExpr.getType();
            if (Scene.v().getOrMakeFastHierarchy().canStoreType(type,
                    Scene.v().getType(allocationSuperType.getName()))) {
                return Collections.singleton(new WeightedForwardQuery<>(new Statement((Stmt) unit, m),
                        new AllocVal(leftOp, m, assignStmt.getRightOp(), new Statement((Stmt) unit, m)),
                        initialTransition()));
            }
        }
    }
    return Collections.emptySet();
}
 
Example 6
Source File: AbstractBoomerangTest.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
public Optional<? extends Query> test(Stmt unit) {
    if (unit instanceof AssignStmt) {
        AssignStmt as = (AssignStmt) unit;
        if (as.getLeftOp() instanceof Local && as.getRightOp() instanceof NewExpr) {
            NewExpr expr = ((NewExpr) as.getRightOp());
            if (allocatesObjectOfInterest(expr)) {
                Local local = (Local) as.getLeftOp();
                Statement statement = new Statement(unit, staticIcfg.getMethodOf(unit));
                ForwardQuery forwardQuery = new ForwardQuery(statement,
                        new AllocVal(local, staticIcfg.getMethodOf(unit), as.getRightOp(), statement));
                return Optional.<Query> of(forwardQuery);
            }
        }
    }
    return Optional.empty();
}
 
Example 7
Source File: UpdateManifestAndCodeForWaitPDP.java    From DroidForce with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 
 * @param mainActivityClass
 * @param mainActivityClass 
 */
public static void updateWaitPDPActivity(String packageName, String mainActivityClass) {
	
	if (mainActivityClass.startsWith(".")) {
		mainActivityClass = packageName + mainActivityClass;
	}
	
	SootClass sc = Scene.v().getSootClass("de.ecspride.javaclasses.WaitPDPActivity");
	SootMethod sm = sc.getMethodByName("<init>");
	Body b = sm.retrieveActiveBody();
	for (Unit u: b.getUnits()) {
		if (u instanceof AssignStmt) {
			AssignStmt asg = (AssignStmt)u;
			if (asg.getRightOp() instanceof StringConstant) {
				StringConstant cst = (StringConstant)asg.getRightOp();
				System.out.println("cst: "+ cst);
				if (cst.value.equals("")) {
					asg.setRightOp(StringConstant.v(mainActivityClass));
					System.out.println("asg: "+ asg);
				}
			}
		}
	}
}
 
Example 8
Source File: AndroidSourceSinkManager.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Finds the last assignment to the given String local by searching upwards
 * from the given statement
 * 
 * @param stmt
 *            The statement from which to look backwards
 * @param local
 *            The variable for which to look for assignments
 * @return The last value assigned to the given variable
 */
private String findLastStringAssignment(Stmt stmt, Local local, BiDiInterproceduralCFG<Unit, SootMethod> cfg) {
	if (stmt instanceof AssignStmt) {
		AssignStmt assign = (AssignStmt) stmt;
		if (assign.getLeftOp() == local) {
			// ok, now find the new value from the right side
			if (assign.getRightOp() instanceof StringConstant)
				return ((StringConstant) assign.getRightOp()).value;
		}
	}

	// Continue the search upwards
	for (Unit pred : cfg.getPredsOf(stmt)) {
		if (!(pred instanceof Stmt))
			continue;
		String lastAssignment = findLastStringAssignment((Stmt) pred, local, cfg);
		if (lastAssignment != null)
			return lastAssignment;
	}
	return null;
}
 
Example 9
Source File: NormalEdgeFunctionFactory.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns a normal edge function.
 * 
 * @param curr The current statement.
 * @param currNode The current variable.
 * @param succNode The variable the current variable is propagated to after the statement.
 * @param zeroValue The zero value, which represents the absence of a data flow fact.
 * @param pointsToAnalysis The pointer analysis.
 * @return A normal edge function.
 */
public EdgeFunction<BasePropagationValue> getNormalEdgeFunction(Unit curr, Value currNode,
    Value succNode, Value zeroValue, PointsToAnalysis pointsToAnalysis) {
  if (curr instanceof AssignStmt) {
    if (logger.isDebugEnabled()) {
      logger.debug("Normal edge: " + curr);
      logger.debug(currNode + " " + succNode);
    }
    AssignStmt assignStmt = (AssignStmt) curr;

    final Value left = assignStmt.getLeftOp();
    final String type = left.getType().toString();
    final Value right = assignStmt.getRightOp();

    if (Model.v().isModeledType(type)) {
      if (currNode.equivTo(zeroValue) && succNode.equivTo(left)) {
        if (right instanceof StaticFieldRef) {
          StaticFieldRef staticFieldRef = (StaticFieldRef) right;

          Argument[] arguments =
              Model.v().getArgumentsForStaticField(staticFieldRef.getField().getSignature());

          EdgeFunction<BasePropagationValue> result =
              PropagationTransformerFactory.makeTransformer(null, arguments, false);
          if (arguments != null) {
            if (logger.isDebugEnabled()) {
              logger.debug("Returning " + result);
            }
            return PropagationTransformerFactory.makeTransformer(null, arguments, false);
          }
        } else if (right instanceof NullConstant) {
          return PropagationTransformerFactory.makeTransformer(null, null, false);
        }
      }
    }
  }
  return EdgeIdentity.v();
}
 
Example 10
Source File: WeightedBoomerang.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
protected FieldReadPOI createFieldLoad(Statement s) {
    Stmt stmt = s.getUnit().get();
    AssignStmt as = (AssignStmt) stmt;
    InstanceFieldRef ifr = (InstanceFieldRef) as.getRightOp();
    Val base = new Val(ifr.getBase(), icfg().getMethodOf(as));
    Field field = new Field(ifr.getField());
    return fieldReads
            .getOrCreate(new FieldReadPOI(s, base, field, new Val(as.getLeftOp(), icfg().getMethodOf(as))));
}
 
Example 11
Source File: WeightedBoomerang.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
protected FieldWritePOI createFieldStore(Statement s) {
    Stmt stmt = s.getUnit().get();
    AssignStmt as = (AssignStmt) stmt;
    InstanceFieldRef ifr = (InstanceFieldRef) as.getLeftOp();
    Val base = new Val(ifr.getBase(), icfg().getMethodOf(as));
    Val stored = new Val(as.getRightOp(), icfg().getMethodOf(as));
    Field field = new Field(ifr.getField());
    return fieldWrites.getOrCreate(new FieldWritePOI(s, base, field, stored));
}
 
Example 12
Source File: AbstractBoomerangSolver.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
private boolean containsStaticFieldAccess(Stmt succ) {
    if (succ instanceof AssignStmt) {
        AssignStmt assignStmt = (AssignStmt) succ;
        return assignStmt.getLeftOp() instanceof StaticFieldRef
                || assignStmt.getRightOp() instanceof StaticFieldRef;
    }
    return false;
}
 
Example 13
Source File: WeightedBoomerang.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
protected FieldWritePOI createArrayFieldStore(Statement s) {
    Stmt stmt = s.getUnit().get();
    AssignStmt as = (AssignStmt) stmt;
    ArrayRef ifr = (ArrayRef) as.getLeftOp();
    Val base = new Val(ifr.getBase(), icfg().getMethodOf(as));
    Val stored = new Val(as.getRightOp(), icfg().getMethodOf(as));
    return fieldWrites.getOrCreate(new FieldWritePOI(s, base, Field.array(), stored));
}
 
Example 14
Source File: AbstractBoomerangSolver.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
private boolean isCastNode(Node<Statement, Val> node) {
    Stmt stmt = node.stmt().getUnit().get();
    AssignStmt x;
    if (stmt instanceof AssignStmt && (x = (AssignStmt) stmt).getRightOp() instanceof CastExpr) {
        CastExpr c = (CastExpr) x.getRightOp();
        if (c.getOp().equals(node.fact().value())) {
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: JimpleExprVisitorImpl.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private int findMaxIndexOfArray(InvokeExpr invokeExpr) {
	Value array = null;
	int maxIndex = -1;
	for(Stmt stmt : stmtVisitor.getJimpleDataFlowStatements()) {
		if(stmt instanceof AssignStmt) {
			AssignStmt assign = (AssignStmt)stmt;
			if(array == null) {
				if(assign.getRightOp().equals(invokeExpr)) {
					array = assign.getLeftOp();
				}
			}
			else{
				Value rhs = assign.getRightOp();
				if(rhs instanceof ArrayRef) {
					ArrayRef arrayRef = (ArrayRef)rhs;
					if(arrayRef.getBase().equals(array)) {
						Value index = arrayRef.getIndex();
						if(index instanceof IntConstant) {
							IntConstant constant = (IntConstant)index;
							maxIndex = constant.value;
						}
					}
				}
			}
		}
	}
	return maxIndex;
}
 
Example 16
Source File: TypeResolver.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void split_new()
{		
	LocalDefs defs = LocalDefs.Factory.newLocalDefs(jb);
	PatchingChain<Unit> units = this.jb.getUnits();
	Stmt[] stmts = new Stmt[units.size()];
	
	units.toArray(stmts);
	
	for ( Stmt stmt : stmts )
	{
		if ( stmt instanceof InvokeStmt )
		{
			InvokeStmt invoke = (InvokeStmt)stmt;
			
			if ( invoke.getInvokeExpr() instanceof SpecialInvokeExpr )
			{
				SpecialInvokeExpr special
					= (SpecialInvokeExpr)invoke.getInvokeExpr();
				
				if ( special.getMethodRef().name().equals("<init>") )
				{
					List<Unit> deflist = defs.getDefsOfAt(
						(Local)special.getBase(), invoke);
					
					while ( deflist.size() == 1 )
					{
						Stmt stmt2 = (Stmt)deflist.get(0);
						
						if ( stmt2 instanceof AssignStmt )
						{
							AssignStmt assign = (AssignStmt)stmt2;
							
							if ( assign.getRightOp() instanceof Local )
							{
								deflist = defs.getDefsOfAt(
									(Local)assign.getRightOp(), assign);
								continue;
							}
							else if ( assign.getRightOp()
								instanceof NewExpr )
							{
								Local newlocal = Jimple.v().newLocal(
									"tmp", null);
								newlocal.setName("tmp$" + System.identityHashCode(newlocal));
								this.jb.getLocals().add(newlocal);
								
								special.setBase(newlocal);
								
								DefinitionStmt assignStmt
									= Jimple.v().newAssignStmt(
									assign.getLeftOp(), newlocal);
								Unit u = Util.findLastIdentityUnit(jb, assign);
								units.insertAfter(assignStmt, u);
								assign.setLeftOp(newlocal);
								
								this.addLocal(newlocal);
								this.initAssignment(assignStmt);
							}
						}
						break;
					}
				}
			}
		}
	}
}
 
Example 17
Source File: TypeResolverBV.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void split_new()
 {
LocalDefs defs = LocalDefs.Factory.newLocalDefs(stmtBody);
   PatchingChain<Unit> units = stmtBody.getUnits();
   Stmt[] stmts = new Stmt[units.size()];

   units.toArray(stmts);
   
   for (Stmt stmt : stmts) {
if(stmt instanceof InvokeStmt)
  {
    InvokeStmt invoke = (InvokeStmt) stmt;
    
    if(invoke.getInvokeExpr() instanceof SpecialInvokeExpr)
      {
	SpecialInvokeExpr special = (SpecialInvokeExpr) invoke.getInvokeExpr();
	
	if(special.getMethodRef().name().equals("<init>"))
	  {
	    List<Unit> deflist = defs.getDefsOfAt((Local) special.getBase(), invoke);
	    
	    while(deflist.size() == 1)
	      {
		Stmt stmt2 = (Stmt) deflist.get(0);
		
		if(stmt2 instanceof AssignStmt)
		  {
		    AssignStmt assign = (AssignStmt) stmt2;
		    
		    if(assign.getRightOp() instanceof Local)
		      {
			deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign);
			continue;
		      }
		    else if(assign.getRightOp() instanceof NewExpr)
		      {			
			// We split the local.
			//G.v().out.println("split: [" + assign + "] and [" + stmt + "]");
			Local newlocal = Jimple.v().newLocal("tmp", null);
			stmtBody.getLocals().add(newlocal);
			
			special.setBase(newlocal);
			
			units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign);
			assign.setLeftOp(newlocal);
		      }
		  }
		break;
	      }
	  }
      }
  }
     }
 }
 
Example 18
Source File: DexReturnValuePropagator.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
       ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v(), true);
       LocalDefs localDefs = LocalDefs.Factory.newLocalDefs(graph);
       LocalUses localUses = null;
       LocalCreation localCreation = null;
       
	// If a return statement's operand has only one definition and this is
	// a copy statement, we take the original operand
	for (Unit u : body.getUnits())
		if (u instanceof ReturnStmt) {
			ReturnStmt retStmt = (ReturnStmt) u;
			if (retStmt.getOp() instanceof Local) {
				List<Unit> defs = localDefs.getDefsOfAt((Local) retStmt.getOp(), retStmt);
				if (defs.size() == 1 && defs.get(0) instanceof AssignStmt) {
					AssignStmt assign = (AssignStmt) defs.get(0);
					final Value rightOp = assign.getRightOp();
					final Value leftOp = assign.getLeftOp();
					
					// Copy over the left side if it is a local
					if (rightOp instanceof Local) {
						// We must make sure that the definition we propagate to
						// the return statement is not overwritten in between
						// a = 1; b = a; a = 3; return b; may not be translated
						// to return a;
						if (!isRedefined((Local) rightOp, u, assign, graph))
							retStmt.setOp(rightOp);
					}
					else if (rightOp instanceof Constant) {
						retStmt.setOp(rightOp);
					}
					// If this is a field access which has no other uses,
					// we rename the local to help splitting
					else if (rightOp instanceof FieldRef) {
						if (localUses == null)
							localUses = LocalUses.Factory.newLocalUses(body, localDefs);
						if (localUses.getUsesOf(assign).size() == 1) {
							if (localCreation == null)
								localCreation = new LocalCreation(body.getLocals(), "ret");
							Local newLocal = localCreation.newLocal(leftOp.getType());
							assign.setLeftOp(newLocal);
							retStmt.setOp(newLocal);
						}
					}
				}
			}
		}
}
 
Example 19
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 20
Source File: AbstractBoomerangSolver.java    From SPDS with Eclipse Public License 2.0 4 votes vote down vote up
protected Field getLoadedField(Stmt curr) {
    AssignStmt as = (AssignStmt) curr;
    InstanceFieldRef ifr = (InstanceFieldRef) as.getRightOp();
    return new Field(ifr.getField());
}