soot.jimple.AssignStmt Java Examples

The following examples show how to use soot.jimple.AssignStmt. 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 Project: FuzzDroid   Author: srasthofer   File: TimingBombTransformer.java    License: Apache License 2.0 7 votes vote down vote up
private void prepareAlarmManagerSet(Body body, InvokeStmt setStmt, SootMethodRef reportRef) {
	Value oldVal = setStmt.getInvokeExpr().getArg(1);
	
	Local longLocal = UtilInstrumenter.generateFreshLocal(body, LongType.v());
	SootMethod currentTimeMillis = Scene.v().getMethod("<java.lang.System: long currentTimeMillis()>");		
	StaticInvokeExpr timeInvoke = Jimple.v().newStaticInvokeExpr(currentTimeMillis.makeRef());		
	AssignStmt timeInitalize = Jimple.v().newAssignStmt(longLocal, timeInvoke);
	
	AddExpr addTime = Jimple.v().newAddExpr(longLocal, LongConstant.v(2000L));
	AssignStmt timeAssign = Jimple.v().newAssignStmt(longLocal, addTime);
			
	
	body.getUnits().insertBefore(timeInitalize, setStmt);
	body.getUnits().insertBefore(timeAssign, setStmt);
	
	InvokeExpr expr = setStmt.getInvokeExpr();
	expr.setArg(0, IntConstant.v(0));
	expr.setArg(1, longLocal);
	
	// Report the change
	InvokeStmt reportStmt = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(
			reportRef, oldVal, longLocal));
	reportStmt.addTag(new InstrumentedCodeTag());
	body.getUnits().insertAfter(reportStmt, setStmt);
}
 
Example #2
Source Project: FuzzDroid   Author: srasthofer   File: SMTPreparationPhase.java    License: Apache License 2.0 6 votes vote down vote up
private ResultSourceInfo findDataFlowPathForSink(Stmt sinkStmt, Local sinkLokal, List<ResultSourceInfo> allDataFlows) {
	for(ResultSourceInfo singleFlow : allDataFlows){
		Stmt[] statements = singleFlow.getPath();
		AccessPath[] accessPath = singleFlow.getPathAccessPaths();
		
		for(int i = 0; i < statements.length; i++) {	
			Stmt currentStmt = statements[i];
			if(currentStmt == sinkStmt) {
				if(accessPath[i].getPlainValue() == sinkLokal)
					return singleFlow;
			}
			
			else if(currentStmt instanceof AssignStmt) {
				AssignStmt assignStmt = (AssignStmt)currentStmt;
				Value lhs = assignStmt.getLeftOp();
			
				if(lhs == sinkLokal)						
					return singleFlow;		
			}
		}
	}
	return null;
}
 
Example #3
Source Project: FuzzDroid   Author: srasthofer   File: SmartConstantDataExtractorFuzzyAnalysis.java    License: 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 #4
Source Project: FuzzDroid   Author: srasthofer   File: SmartConstantDataExtractorFuzzyAnalysis.java    License: Apache License 2.0 6 votes vote down vote up
private int getConstantArrayIndexForSplitDataFlow(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 ((IntConstant) index).value;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return -1;
}
 
Example #5
Source Project: JAADAS   Author: flankerhqd   File: AndroidSourceSinkManager.java    License: 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 #6
Source Project: JAADAS   Author: flankerhqd   File: BaseEntryPointCreator.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs an array of the given type with a single element of this type
 * in the given method
 * @param body The body of the method in which to create the array
 * @param gen The local generator
 * @param tp The type of which to create the array
 * @param constructionStack Set of classes currently being built to avoid
 * constructor loops
 * @param parentClasses If a requested type is compatible with one of the
 * types in this list, the already-created object is used instead of
 * creating a new one.
 * @return The local referencing the newly created array, or null if the
 * array generation failed
 */
private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp,
		Set<SootClass> constructionStack, Set<SootClass> parentClasses) {
	Local local = gen.generateLocal(tp);

	// Generate a new single-element array
	NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(),
			IntConstant.v(1));
	AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr);
	body.getUnits().add(assignArray);
	
	// Generate a single element in the array
	AssignStmt assign = Jimple.v().newAssignStmt
			(Jimple.v().newArrayRef(local, IntConstant.v(0)),
			getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses));
	body.getUnits().add(assign);
	return local;
}
 
Example #7
Source Project: DroidForce   Author: secure-software-engineering   File: UpdateManifestAndCodeForWaitPDP.java    License: 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 Project: JAADAS   Author: flankerhqd   File: DexNumTransformer.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Collect all the locals which are assigned a IntConstant(0) or are used
 * within a zero comparison.
 *
 * @param body
 *            the body to analyze
 */
private Set<Local> getNumCandidates(Body body) {
	Set<Local> candidates = new HashSet<Local>();
	for (Unit u : body.getUnits()) {
		if (u instanceof AssignStmt) {
			AssignStmt a = (AssignStmt) u;
			if (!(a.getLeftOp() instanceof Local))
				continue;
			Local l = (Local) a.getLeftOp();
			Value r = a.getRightOp();
			if ((r instanceof IntConstant || r instanceof LongConstant)) {
				candidates.add(l);
				Debug.printDbg("[add null candidate: ", u);
			}
		}
	}

	return candidates;
}
 
Example #9
Source Project: JAADAS   Author: flankerhqd   File: FieldInstruction.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
     * Check if the field type equals the type of the value that will be stored in the field. A cast expression has to be introduced for the unequal case.
     * @return assignment statement which hold a cast or not depending on the types of the operation
     */
    protected AssignStmt getAssignStmt(DexBody body, Local sourceValue, ConcreteRef instanceField) {
    	AssignStmt assign;
//		Type targetType = getTargetType(body);
//		if(targetType != UnknownType.v() && targetType != sourceValue.getType() && ! (targetType instanceof RefType)) {
//			CastExpr castExpr = Jimple.v().newCastExpr(sourceValue, targetType);
//			Local local = body.generateLocal(targetType);
//			assign = Jimple.v().newAssignStmt(local, castExpr);
//			body.add(assign);
//			beginUnit = assign;
//			assign = Jimple.v().newAssignStmt(instanceField, local);
//		}
//		else {
			assign = Jimple.v().newAssignStmt(instanceField, sourceValue);
//		}
		return assign;
    }
 
Example #10
Source Project: JAADAS   Author: flankerhqd   File: DexNullTransformer.java    License: 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 #11
Source Project: JAADAS   Author: flankerhqd   File: AsmMethodSource.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void convertArrayStoreInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == LASTORE || op == DASTORE;
	StackFrame frame = getFrame(insn);
	if (!units.containsKey(insn)) {
		Operand valu = dword ? popImmediateDual() : popImmediate();
		Operand indx = popImmediate();
		Operand base = popLocal();
		ArrayRef ar = Jimple.v().newArrayRef(
				base.stackOrValue(), indx.stackOrValue());
		indx.addBox(ar.getIndexBox());
		base.addBox(ar.getBaseBox());
		AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue());
		valu.addBox(as.getRightOpBox());
		frame.in(valu, indx, base);
		frame.boxes(as.getRightOpBox(),
				ar.getIndexBox(), ar.getBaseBox());
		setUnit(insn, as);
	} else {
		frame.mergeIn(dword ? popDual() : pop(), pop(), pop());
	}
}
 
Example #12
Source Project: SPDS   Author: CROSSINGTUD   File: ForwardBoomerangSolver.java    License: 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 #13
Source Project: DroidForce   Author: secure-software-engineering   File: Util.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void changeConstantStringInField(SootField sf,
		String newConstantString) {
	SootClass sc = sf.getDeclaringClass();
	SootMethod sm = sc.getMethodByName("<clinit>");
	
	boolean hasBeenUpdated = false;
	for (Unit u: sm.retrieveActiveBody().getUnits()) {
		if (u instanceof AssignStmt) {
			AssignStmt ass = (AssignStmt)u;
			Value lop = ass.getLeftOp();
			if (lop.toString().equals(sf.toString())) {
				System.out.println("previous string: "+ ass);
				ass.setRightOp(StringConstant.v(newConstantString));
				hasBeenUpdated = true;
				System.out.println("updated string : "+ ass);
			}
		}
	}
	
	if (!hasBeenUpdated)
		throw new RuntimeException("error: no StringConstant found for field "+ sf);
	
}
 
Example #14
Source Project: SPDS   Author: CROSSINGTUD   File: WholeProgramBoomerang.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SeedFactory<W> getSeedFactory() {
    if (seedFactory == null) {
        seedFactory = new SeedFactory<W>() {

            @Override
            protected Collection<? extends Query> generate(SootMethod method, Stmt u) {
                if (u instanceof AssignStmt) {
                    AssignStmt assignStmt = (AssignStmt) u;
                    if (options.isAllocationVal(assignStmt.getRightOp())) {
                        return Collections.singleton(
                                new ForwardQuery(new Statement(u, method), new AllocVal(assignStmt.getLeftOp(),
                                        method, assignStmt.getRightOp(), new Statement((Stmt) u, method))));
                    }
                }
                return Collections.emptySet();
            }

            @Override
            public ObservableICFG<Unit, SootMethod> icfg() {
                return new ObservableStaticICFG(new BoomerangICFG(false));
            }
        };
    }
    return seedFactory;
}
 
Example #15
Source Project: SPDS   Author: CROSSINGTUD   File: AbstractBoomerangTest.java    License: 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 #16
Source Project: SPDS   Author: CROSSINGTUD   File: AbstractBoomerangTest.java    License: 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 #17
Source Project: SPDS   Author: CROSSINGTUD   File: AbstractBoomerangTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SeedFactory<Weight.NoWeight> getSeedFactory() {
    return new SeedFactory<Weight.NoWeight>() {

        @Override
        protected Collection<? extends Query> generate(SootMethod method, Stmt u) {
            if (u instanceof AssignStmt) {
                AssignStmt assignStmt = (AssignStmt) u;
                if (options.isAllocationVal(assignStmt.getRightOp())) {
                    return Collections.singleton(new ForwardQuery(new Statement((Stmt) u, method),
                            new AllocVal(assignStmt.getLeftOp(), method, assignStmt.getRightOp(),
                                    new Statement((Stmt) u, method))));
                }
            }
            return Collections.emptySet();
        }

        @Override
        public ObservableICFG<Unit, SootMethod> icfg() {
            return staticIcfg;
        }
    };
}
 
Example #18
Source Project: SPDS   Author: CROSSINGTUD   File: HasNextStateMachine.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Set<WeightedForwardQuery<TransitionFunction>> generateSeed(SootMethod method, Unit unit) {
    Iterator<Edge> edIt = Scene.v().getCallGraph().edgesOutOf(unit);
    while (edIt.hasNext()) {
        SootMethod m = edIt.next().getTgt().method();
        if (retrieveIteratorConstructors().contains(m)) {
            Stmt stmt = ((Stmt) unit);
            InvokeExpr invokeExpr = stmt.getInvokeExpr();
            if (stmt instanceof AssignStmt) {
                AssignStmt assignStmt = (AssignStmt) stmt;
                InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr;
                return Collections
                        .singleton(new WeightedForwardQuery<>(
                                new Statement(stmt, method), new AllocVal(assignStmt.getLeftOp(), method,
                                        assignStmt.getLeftOp(), new Statement((Stmt) unit, m)),
                                initialTransition()));
            }
        }
    }
    return Collections.emptySet();
}
 
Example #19
Source Project: SPDS   Author: CROSSINGTUD   File: TypeStateMachineWeightFunctions.java    License: 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 #20
Source Project: DroidRA   Author: serval-snt-uni-lu   File: DummyMainGenerator.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void instrumentDummyMainMethod(SootMethod mainMethod)
{
	Body body = mainMethod.getActiveBody();
   	
   	PatchingChain<Unit> units = body.getUnits();
   	for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); )
   	{
   		Stmt stmt = (Stmt) iter.next();
   		
   		if (stmt instanceof IdentityStmt)
   		{
   			continue;
   		}
   		   	
   		//For the purpose of confusion dex optimization (because of the strategy of generating dummyMain method)
		AssignStmt aStmt = (AssignStmt) stmt;
		SootMethod fuzzyMe = generateFuzzyMethod(mainMethod.getDeclaringClass());
		InvokeExpr invokeExpr = Jimple.v().newVirtualInvokeExpr(body.getThisLocal(), fuzzyMe.makeRef());
		Unit assignU = Jimple.v().newAssignStmt(aStmt.getLeftOp(), invokeExpr);
		units.insertAfter(assignU, aStmt);
		
		break;
   	}
}
 
Example #21
Source Project: FuzzDroid   Author: srasthofer   File: ClassLoaderTransformer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void internalTransform(Body b, String phaseName,
		Map<String, String> options) {
	// Do not instrument methods in framework classes
	if (!canInstrumentMethod(b.getMethod()))
		return;
	
	// Check for calls to DexFile.loadClass
	for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext(); ) {
		Stmt stmt = (Stmt) unitIt.next();
		if (stmt.hasTag(InstrumentedCodeTag.name))
			continue;
		if (!(stmt instanceof AssignStmt))
			continue;
		AssignStmt assignStmt = (AssignStmt) stmt;
		
		if (stmt.containsInvokeExpr()) {
			InvokeExpr iexpr = stmt.getInvokeExpr();
			if (iexpr.getMethod()  == methodDexFileLoadClass) {
				List<Value> args = new ArrayList<>();
				args.add(((InstanceInvokeExpr) iexpr).getBase());
				args.addAll(iexpr.getArgs());
				InvokeExpr newLoadExpr = Jimple.v().newStaticInvokeExpr(methodOwnLoader.makeRef(), args);
				b.getUnits().swapWith(stmt, Jimple.v().newAssignStmt(assignStmt.getLeftOp(), newLoadExpr));
			}
		}
	}
}
 
Example #22
Source Project: FuzzDroid   Author: srasthofer   File: JimpleExprVisitorImpl.java    License: 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 #23
Source Project: FuzzDroid   Author: srasthofer   File: SmartConstantDataExtractorFuzzyAnalysis.java    License: Apache License 2.0 5 votes vote down vote up
private String getValueOfInterestForSplitDataflow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		return ass.getLeftOp().toString();
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
}
 
Example #24
Source Project: JAADAS   Author: flankerhqd   File: ImplicitFlowAliasStrategy.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes the global non-flow-sensitive alias information for the given
 * method
 * @param method The method for which to compute the alias information
 */
private Map<AccessPath, Set<AccessPath>> computeGlobalAliases(SootMethod method) {
	Map<AccessPath, Set<AccessPath>> res = new HashMap<AccessPath, Set<AccessPath>>();

	// Find the aliases
	for (Unit u : method.getActiveBody().getUnits()) {
		if (!(u instanceof AssignStmt))
			continue;
		final AssignStmt assign = (AssignStmt) u;
		
		// Aliases can only be generated on the heap
		if (!(assign.getLeftOp() instanceof FieldRef
				&& (assign.getRightOp() instanceof FieldRef
						|| assign.getRightOp() instanceof Local)))
			if (!(assign.getRightOp() instanceof FieldRef
					&& (assign.getLeftOp() instanceof FieldRef
							|| assign.getLeftOp() instanceof Local)))
				continue;
		
		final AccessPath apLeft = new AccessPath(assign.getLeftOp(), true);
		final AccessPath apRight = new AccessPath(assign.getRightOp(), true);
		
		Set<AccessPath> mapLeft = res.get(apLeft);
		if (mapLeft == null) {
			mapLeft = new HashSet<AccessPath>();
			res.put(apLeft, mapLeft);
		}
		mapLeft.add(apRight);
		
		Set<AccessPath> mapRight = res.get(apRight);
		if (mapRight == null) {
			mapRight = new HashSet<AccessPath>();
			res.put(apRight, mapRight);
		}
		mapLeft.add(apLeft);
	}
	return res;
}
 
Example #25
Source Project: vasco   Author: rohanpadhye   File: CopyConstantAnalysis.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Map<Local, Constant> callLocalFlowFunction(Context<SootMethod, Unit, Map<Local, Constant>> context, Unit unit, Map<Local, Constant> inValue) {
	// Initialise result to the input
	Map<Local, Constant> afterCallValue = copy(inValue);
	// Remove information for return value (as it's value will flow from the call)
	if (unit instanceof AssignStmt) {
		Value lhsOp = ((AssignStmt) unit).getLeftOp();
		afterCallValue.remove(lhsOp);
	}
	// Rest of the map remains the same
	return afterCallValue;
	
}
 
Example #26
Source Project: JAADAS   Author: flankerhqd   File: DexNullTransformer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Collect all the locals which are assigned a IntConstant(0) or are used
 * within a zero comparison.
 *
 * @param body
 *            the body to analyze
 */
private Set<Local> getNullCandidates(Body body) {
	Set<Local> candidates = null;
	for (Unit u : body.getUnits()) {
		if (u instanceof AssignStmt) {
			AssignStmt a = (AssignStmt) u;
			if (!(a.getLeftOp() instanceof Local))
				continue;
			Local l = (Local) a.getLeftOp();
			Value r = a.getRightOp();
			if ((r instanceof IntConstant && ((IntConstant) r).value == 0)
					|| (r instanceof LongConstant && ((LongConstant) r).value == 0)) {
				if (candidates == null)
					candidates = new HashSet<Local>();
				candidates.add(l);
				Debug.printDbg("[add null candidate: ", u);
			}
		} else if (u instanceof IfStmt) {
			ConditionExpr expr = (ConditionExpr) ((IfStmt) u)
					.getCondition();
			if (isZeroComparison(expr) && expr.getOp1() instanceof Local) {
				if (candidates == null)
					candidates = new HashSet<Local>();
				candidates.add((Local) expr.getOp1());
				Debug.printDbg("[add null candidate if: ", u);
			}
		}
	}

	return candidates == null ? Collections.<Local>emptySet() : candidates;
}
 
Example #27
Source Project: JAADAS   Author: flankerhqd   File: DexTransformer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Collect definitions of l in body including the definitions of aliases of
 * l.
 * 
 * In this context an alias is a local that propagates its value to l.
 * 
 * @param l
 *            the local whose definitions are to collect
 * @param localDefs
 *            the LocalDefs object
 * @param body
 *            the body that contains the local
 */
protected List<Unit> collectDefinitionsWithAliases(Local l,
		LocalDefs localDefs, LocalUses localUses, Body body) {
	Set<Local> seenLocals = new HashSet<Local>();
	Stack<Local> newLocals = new Stack<Local>();
	List<Unit> defs = new LinkedList<Unit>();
	newLocals.push(l);

	while (!newLocals.empty()) {
		Local local = newLocals.pop();
		Debug.printDbg("[null local] ", local);
		if (!seenLocals.add(local))
			continue;
		for (Unit u : collectDefinitions(local, localDefs, body)) {
			if (u instanceof AssignStmt) {
				Value r = ((AssignStmt) u).getRightOp();
				if (r instanceof Local && !seenLocals.contains((Local) r))
					newLocals.push((Local) r);
			}
			defs.add(u);
			//
			List<UnitValueBoxPair> usesOf = (List<UnitValueBoxPair>) localUses
					.getUsesOf(u);
			for (UnitValueBoxPair pair : usesOf) {
				Unit unit = pair.getUnit();
				if (unit instanceof AssignStmt) {
					Value right = ((AssignStmt) unit).getRightOp();
					Value left = ((AssignStmt) unit).getLeftOp();
					if (right == local && left instanceof Local
							&& !seenLocals.contains((Local) left))
						newLocals.push((Local) left);
				}
			}
			//
		}
	}
	return defs;
}
 
Example #28
Source Project: JAADAS   Author: flankerhqd   File: DexReturnValuePropagator.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks whether the given local has been redefined between the original
 * definition unitDef and the use unitUse.
 * @param l The local for which to check for redefinitions
 * @param unitUse The unit that uses the local
 * @param unitDef The unit that defines the local
 * @param graph The unit graph to use for the check
 * @return True if there is at least one path between unitDef and unitUse on
 * which local l gets redefined, otherwise false 
 */
   private boolean isRedefined(Local l, Unit unitUse, AssignStmt unitDef,
   		UnitGraph graph) {
   	List<Unit> workList = new ArrayList<Unit>();
   	workList.add(unitUse);
   	
   	Set<Unit> doneSet = new HashSet<Unit>();
   	
	// Check for redefinitions of the local between definition and use
   	while (!workList.isEmpty()) {
   		Unit curStmt = workList.remove(0);
   		if (!doneSet.add(curStmt))
   			continue;
   		
    	for (Unit u : graph.getPredsOf(curStmt)) {
    		if (u != unitDef) {
	    		if (u instanceof DefinitionStmt) {
	    			DefinitionStmt defStmt = (DefinitionStmt) u;
	    			if (defStmt.getLeftOp() == l)
	    				return true;
	    		}
	    		workList.add(u);
    		}
    	}
   	}
   	return false;
}
 
Example #29
Source Project: JAADAS   Author: flankerhqd   File: Shimple.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the corresponding PhiExpr if the unit is a Phi node,
 * null otherwise.
 **/
public static PhiExpr getPhiExpr(Unit unit)
{
    if(!(unit instanceof AssignStmt))
        return null;

    Value right = ((AssignStmt)unit).getRightOp();
    
    if(isPhiExpr(right))
        return (PhiExpr) right;

    return null;
}
 
Example #30
Source Project: JAADAS   Author: flankerhqd   File: Shimple.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static PiExpr getPiExpr(Unit unit)
{
    if(!(unit instanceof AssignStmt))
        return null;

    Value right = ((AssignStmt)unit).getRightOp();

    if(isPiExpr(right))
        return (PiExpr) right;

    return null;
}