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

The following examples show how to use soot.jimple.IdentityStmt#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: ConstraintChecker.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void caseIdentityStmt(IdentityStmt stmt) {
	Value l = stmt.getLeftOp();
	Value r = stmt.getRightOp();

	if (l instanceof Local) {
		if (((Local) l).getType() instanceof IntegerType) {
			TypeNode left = ClassHierarchy.v().typeNode(
					(((Local) l).getType()));
			TypeNode right = ClassHierarchy.v().typeNode(r.getType());

			if (!right.hasAncestor_1(left)) {
				if (fix) {
					((soot.jimple.internal.JIdentityStmt) stmt)
							.setLeftOp(insertCastAfter((Local) l,
									getTypeForCast(left),
									getTypeForCast(right), stmt));
				} else {
					error("Type Error(16)");
				}
			}
		}
	}
}
 
Example 2
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void caseIdentityStmt(IdentityStmt stmt) {
	Value l = stmt.getLeftOp();
	Value r = stmt.getRightOp();

	if (l instanceof Local) {
		TypeVariable left = resolver.typeVariable((Local) l);

		if (!(r instanceof CaughtExceptionRef)) {
			TypeVariable right = resolver.typeVariable(r.getType());
			right.addParent(left);
		} else {
			List<RefType> exceptionTypes = TrapManager.getExceptionTypesOf(stmt, stmtBody);
			Iterator<RefType> typeIt = exceptionTypes.iterator();

			while (typeIt.hasNext()) {
				Type t = typeIt.next();

				resolver.typeVariable(t).addParent(left);
			}

			if (uses) {
				left.addParent(resolver.typeVariable(RefType.v("java.lang.Throwable")));
			}
		}
	}
}
 
Example 3
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
	Value lhs = stmt.getLeftOp();
	Value rhs = stmt.getRightOp();
	if (rhs instanceof CaughtExceptionRef) {
		// save the caught exception with move-exception
		Register localReg = regAlloc.asLocal(lhs);
		
           addInsn(new Insn11x(Opcode.MOVE_EXCEPTION, localReg), stmt);

           this.insnRegisterMap.put(insns.get(insns.size() - 1), LocalRegisterAssignmentInformation.v(localReg, (Local)lhs));
	} else if (rhs instanceof ThisRef || rhs instanceof ParameterRef) {
		/* 
		 * do not save the ThisRef or ParameterRef in a local, because it always has a parameter register already.
		 * at least use the local for further reference in the statements
		 */
		Local localForThis = (Local) lhs;
		regAlloc.asParameter(belongingMethod, localForThis);
		
		parameterInstructionsList.add(LocalRegisterAssignmentInformation.v(regAlloc.asLocal(localForThis).clone(), localForThis));
	} else {
		throw new Error("unknown Value as right-hand side of IdentityStmt: " + rhs);
	}
}
 
Example 4
Source File: Body.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/** Return LHS of the first identity stmt assigning from \@parameter i. **/
public Local getParameterLocal(int i)
{
    for (Unit s : getUnits())
    {
        if (s instanceof IdentityStmt &&
            ((IdentityStmt)s).getRightOp() instanceof ParameterRef)
        {
            IdentityStmt is = (IdentityStmt)s;
            ParameterRef pr = (ParameterRef)is.getRightOp();
            if (pr.getIndex() == i)
                return (Local)is.getLeftOp();
        }
    }

    throw new RuntimeException("couldn't find parameterref" + i +"! in "+getMethod());
}
 
Example 5
Source File: Body.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get all the LHS of the identity statements assigning from parameter references.
 *
 * @return a list of size as per <code>getMethod().getParameterCount()</code> with all elements ordered as per the parameter index.
 * @throws RuntimeException if a parameterref is missing
 */
public List<Local> getParameterLocals(){
    final int numParams = getMethod().getParameterCount();
    final List<Local> retVal = new ArrayList<Local>(numParams);

    //Parameters are zero-indexed, so the keeping of the index is safe
    for (Unit u : getUnits()){
        if (u instanceof IdentityStmt){
            IdentityStmt is = ((IdentityStmt)u);
            if (is.getRightOp() instanceof ParameterRef){
                ParameterRef pr = (ParameterRef) is.getRightOp();
                retVal.add(pr.getIndex(), (Local) is.getLeftOp());
            }
        }
    }
    if (retVal.size() != numParams){
    	//FLANKER FIX BEGIN
        //throw new RuntimeException("couldn't find parameterref! in " + getMethod());
    	return retVal;
    	//FLANKER FIX END
    }
    return retVal;
}
 
Example 6
Source File: DefaultSourceSinkManager.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SourceInfo getSourceInfo(Stmt sCallSite, InterproceduralCFG<Unit, SootMethod> cfg) {
	SootMethod callee = sCallSite.containsInvokeExpr() ?
			sCallSite.getInvokeExpr().getMethod() : null;
	
	AccessPath targetAP = null;
	if (callee != null && sources.contains(callee.toString())) {
		if (callee.getReturnType() != null 
				&& sCallSite instanceof DefinitionStmt) {
			// Taint the return value
			Value leftOp = ((DefinitionStmt) sCallSite).getLeftOp();
			targetAP = new AccessPath(leftOp, true);
		}
		else if (sCallSite.getInvokeExpr() instanceof InstanceInvokeExpr) {
			// Taint the base object
			Value base = ((InstanceInvokeExpr) sCallSite.getInvokeExpr()).getBase();
			targetAP = new AccessPath(base, true);
		}
	}
	// Check whether we need to taint parameters
	else if (sCallSite instanceof IdentityStmt) {
		IdentityStmt istmt = (IdentityStmt) sCallSite;
		if (istmt.getRightOp() instanceof ParameterRef) {
			ParameterRef pref = (ParameterRef) istmt.getRightOp();
			SootMethod currentMethod = cfg.getMethodOf(istmt);
			if (parameterTaintMethods.contains(currentMethod.toString()))
				targetAP = new AccessPath(currentMethod.getActiveBody()
						.getParameterLocal(pref.getIndex()), true);
		}
	}
	
	if (targetAP == null)
		return null;
	
	// Create the source information data structure
	return new SourceInfo(targetAP);
}
 
Example 7
Source File: InterproceduralConstantValuePropagator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the first statement in the body of the given method that does not
 * assign the "this" local or a parameter local
 * @param sm The method in whose body to look
 * @return The first non-identity statement in the body of the given method.
 */
private Unit getFirstNonIdentityStmt(SootMethod sm) {
	for (Unit u : sm.getActiveBody().getUnits()) {
		if (!(u instanceof IdentityStmt))
			return u;
		
		IdentityStmt id = (IdentityStmt) u;
		if (!(id.getRightOp() instanceof ThisRef)
				&& !(id.getRightOp() instanceof ParameterRef))
			return u;
	}
	return null;
}
 
Example 8
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void caseIdentityStmt(IdentityStmt stmt) {
	Value l = stmt.getLeftOp();
	Value r = stmt.getRightOp();

	if (l instanceof Local) {
		if (((Local) l).getType() instanceof IntegerType) {
			TypeVariable left = resolver.typeVariable((Local) l);

			TypeVariable right = resolver.typeVariable(r.getType());
			right.addParent(left);
		}
	}
}
 
Example 9
Source File: FastDexTrapTightener.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private boolean isDexInstruction(Unit unit) {
	if (unit instanceof IdentityStmt) {
		IdentityStmt is = (IdentityStmt) unit;
		return !(is.getRightOp() instanceof ThisRef
				|| is.getRightOp() instanceof ParameterRef);
	}
	return true;
}
 
Example 10
Source File: JimpleStmtVisitorImpl.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void caseInvokeStmt(InvokeStmt stmt) {
	InvokeExpr invokeExpr = stmt.getInvokeExpr();
	SootClass declaringClass = invokeExpr.getMethod().getDeclaringClass();
	if(exprVisitor.isExpressionThatNeedsToBeConvertedToSMT(invokeExpr))
		exprVisitor.convertSpecialExpressionsToSMT(invokeExpr, stmt);
	else if(UtilInstrumenter.isAppDeveloperCode(declaringClass)) {
		SootMethod method = invokeExpr.getMethod();
		Body body = method.retrieveActiveBody();
		
		SMTBinding newRhs = getBindingForTaintedValue(stmt);
		//if there is no taint-tracking involved (newRhs == null), we do not have to do anything here
		if(newRhs == null)
			return;
		
		int indexOfInterest = -1;
		for(int i = 0; i < invokeExpr.getArgCount(); i++) {
			if(newRhs.getVariableName().equals(invokeExpr.getArg(i).toString())) {
				indexOfInterest = i;
				break;
			}
		}
		
		if(indexOfInterest == -1)
			return;
		
		
		for(Unit unit : body.getUnits()) {
			if(unit instanceof IdentityStmt) {
				IdentityStmt identity = (IdentityStmt)unit;
				Value rhs = identity.getRightOp();
				if(rhs instanceof ParameterRef) {
					ParameterRef param = (ParameterRef)rhs;
					if(param.getIndex() == indexOfInterest) {
						Value lhs = identity.getLeftOp();
						SMTBinding newLhs = createNewBindingForValue(lhs);
						addValueBindingToVariableDeclaration(lhs, newLhs);
						SMTSimpleAssignment simpleAssignment = new SMTSimpleAssignment(newLhs, new SMTBindingValue(newRhs));
						SMTAssertStatement assignmentAssert = new SMTAssertStatement(simpleAssignment);
						addAssertStmtToAllPrograms(assignmentAssert);
					}
				}					
			}
		}
	}		
	else {
		System.err.println(String.format("Double-Check if the following method contains useful information which can be extracted: \n%s", stmt));
	}
	
}