Java Code Examples for soot.jimple.IfStmt#getTarget()

The following examples show how to use soot.jimple.IfStmt#getTarget() . 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: ConditionTracking.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private void instrumentEachBranchAccess(Body body, Unit unit){
	SootClass sootClass = Scene.v().getSootClass(
			UtilInstrumenter.JAVA_CLASS_FOR_PATH_INSTRUMENTATION);
	
	// Create the method invocation
	SootMethod createAndAdd = sootClass.getMethod("reportConditionOutcomeSynchronous",
			Collections.<Type>singletonList(BooleanType.v()));
	StaticInvokeExpr sieThen = Jimple.v().newStaticInvokeExpr(
			createAndAdd.makeRef(), IntConstant.v(1));
	StaticInvokeExpr sieElse = Jimple.v().newStaticInvokeExpr(
			createAndAdd.makeRef(), IntConstant.v(0));
	Unit sieThenUnit = Jimple.v().newInvokeStmt(sieThen);
	sieThenUnit.addTag(new InstrumentedCodeTag());
	Unit sieElseUnit = Jimple.v().newInvokeStmt(sieElse);
	sieElseUnit.addTag(new InstrumentedCodeTag());
	
	//treatment of target statement ("true"-branch)
	IfStmt ifStmt = (IfStmt)unit;
	Stmt targetStmt = ifStmt.getTarget();
	if(!branchTargetStmt.contains(targetStmt.toString())) {
		branchTargetStmt.add(sieThenUnit.toString());
		body.getUnits().insertBefore(sieThenUnit, targetStmt);
		
		NopStmt nop = Jimple.v().newNopStmt();
		GotoStmt gotoNop = Jimple.v().newGotoStmt(nop);
		body.getUnits().insertBeforeNoRedirect(nop, targetStmt);
		body.getUnits().insertBeforeNoRedirect(gotoNop, sieThenUnit);
	}
	
	
	//treatment of "else"-branch
	body.getUnits().insertAfter(sieElseUnit, unit);
}
 
Example 2
Source File: PathExecutionTransformer.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private void instrumentEachBranchAccess(Body body, IfStmt ifStmt){		
	String methodSignature =  body.getMethod().getSignature();
	String condition = ifStmt.getCondition().toString();		
	Unit generatedJimpleCodeForBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", 
			RefType.v("java.lang.String"), StringConstant.v(methodSignature),
			RefType.v("java.lang.String"), StringConstant.v(condition),
			RefType.v("java.lang.String"), NullConstant.v()
			);
	generatedJimpleCodeForBranch.addTag(new InstrumentedCodeTag());
	
	Unit generatedJimpleCodeThenBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", 
			RefType.v("java.lang.String"), StringConstant.v(methodSignature),
			RefType.v("java.lang.String"), NullConstant.v(),
			RefType.v("java.lang.String"), StringConstant.v("then branch")
			);
	generatedJimpleCodeThenBranch.addTag(new InstrumentedCodeTag());
	
	Unit generatedJimpleCodeElseBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", 
			RefType.v("java.lang.String"), StringConstant.v(methodSignature),
			RefType.v("java.lang.String"), NullConstant.v(),
			RefType.v("java.lang.String"), StringConstant.v("else branch")
			);
	generatedJimpleCodeElseBranch.addTag(new InstrumentedCodeTag());
	
	body.getUnits().insertBefore(generatedJimpleCodeForBranch, ifStmt);
	
	//treatment of target statement ("true"-branch)
	Stmt targetStmt = ifStmt.getTarget();
	if(!branchTargetStmt.contains(targetStmt.toString())) {
		branchTargetStmt.add(generatedJimpleCodeThenBranch.toString());
		body.getUnits().insertBefore(generatedJimpleCodeThenBranch, targetStmt);
	}
	
	//treatment of "else"-branch
	body.getUnits().insertAfter(generatedJimpleCodeElseBranch, ifStmt);
}
 
Example 3
Source File: BaseEntryPointCreator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Eliminates all loops of length 0 (if a goto <if a>)
 * @param body The body from which to eliminate the self-loops
 */
protected void eliminateSelfLoops(Body body) {
	// Get rid of self-loops
	for (Iterator<Unit> unitIt = body.getUnits().iterator(); unitIt.hasNext(); ) {
		Unit u = unitIt.next();
		if (u instanceof IfStmt) {
			IfStmt ifStmt = (IfStmt) u;
			if (ifStmt.getTarget() == ifStmt)
				unitIt.remove();
		}
	}
}
 
Example 4
Source File: StmtTemplatePrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void caseIfStmt(IfStmt stmt) {		
	String varName = printValueAssignment(stmt.getCondition(), "condition");
	
	Unit target = stmt.getTarget();

	vtp.suggestVariableName("target");
	String targetName = vtp.getLastAssignedVarName();
	p.println("Unit "+targetName+"=" + nameOfJumpTarget(target) + ";");
	
	printStmt(stmt,varName,targetName);
}
 
Example 5
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void caseIfStmt(IfStmt stmt) {
	Stmt target = stmt.getTarget();
       exprV.setOrigStmt(stmt);
	exprV.setTargetForOffset(target);
	stmt.getCondition().apply(exprV);
}