soot.jimple.ReturnVoidStmt Java Examples

The following examples show how to use soot.jimple.ReturnVoidStmt. 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: SootHelper.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Stmt getReturnStmt(SootMethod sootMethod)
{
	Stmt rtVal = null;
	
	Body b = sootMethod.retrieveActiveBody();
	PatchingChain<Unit> units = b.getUnits();
	
	for (Iterator<Unit> iter = units.iterator(); iter.hasNext(); )
	{
		Stmt stmt = (Stmt) iter.next();
		
		if (stmt instanceof ReturnStmt || stmt instanceof ReturnVoidStmt)
		{
			rtVal = stmt;
		}
	}
	
	return rtVal;
}
 
Example #2
Source File: IfElseSplitter.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public boolean tryBodyPattern(List<Object> body,SETNodeLabel label, List<Object> otherBody){
	Stmt lastStmt = getLastStmt(body);
	if(lastStmt == null){
		//dont have a last stmt so cant match pattern
		return false;
	}
		
	if(! (lastStmt instanceof ReturnStmt || lastStmt instanceof ReturnVoidStmt || lastStmt instanceof DAbruptStmt)){
		//lastStmt is not an abrupt stmt
		return false;
	}

	if(bodyTargetsLabel(label,body) || bodyTargetsLabel(label,otherBody)){
		//one of the bodies targets the label on the ifelse cant match pattern
		return false;
	}

	//pattern matched
	return true;
}
 
Example #3
Source File: PathExecutionTransformer.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
	// Do not instrument methods in framework classes
	if (!canInstrumentMethod(body.getMethod()))
		return;
	
	instrumentInfoAboutNonAPICall(body);
	
	//important to use snapshotIterator here
	Iterator<Unit> iterator = body.getUnits().snapshotIterator();
	while(iterator.hasNext()){
		Unit unit = iterator.next();
		if(unit instanceof ReturnStmt || unit instanceof ReturnVoidStmt)
			instrumentInfoAboutReturnStmt(body, unit);
		else if(unit instanceof DefinitionStmt || unit instanceof InvokeStmt)
			instrumentInfoAboutNonApiCaller(body, unit);
		else if(unit instanceof IfStmt)
			instrumentEachBranchAccess(body, (IfStmt)unit);
	}				
}
 
Example #4
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
       addInsn(new Insn10x(Opcode.RETURN_VOID), stmt);
}
 
Example #5
Source File: DummyMainGenerator.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod addMethod(SootMethod mainMethod, String methodSignature)
{
	Body body = mainMethod.getActiveBody();
   	
	Stmt returnStmt = null;
	
   	PatchingChain<Unit> units = body.getUnits();
   	for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); )
   	{
   		Stmt stmt = (Stmt) iter.next();
   		
   		if (stmt instanceof ReturnStmt || stmt instanceof ReturnVoidStmt)
   		{
   			returnStmt = stmt;
   		}
   	}
   	
   	SootMethod sm = Scene.v().getMethod(methodSignature);
   	
   	List<Type> paramTypes = sm.getParameterTypes();
   	List<Value> paramValues = new ArrayList<Value>();
   	for (int i = 0; i < paramTypes.size(); i++)
   	{
   		paramValues.add(InstrumentationUtils.toDefaultSootTypeValue(paramTypes.get(i)));
   	}
   	
   	
   	if (sm.isStatic())    //No need to construct its obj ref
   	{
   		InvokeExpr expr = Jimple.v().newStaticInvokeExpr(sm.makeRef(), paramValues);
   		Unit callU = Jimple.v().newInvokeStmt(expr);
   		units.insertBefore(callU, returnStmt);
   	}
   	else
   	{
   		//new obj first and then call the method
   		
   		SootClass sc = sm.getDeclaringClass();
   		List<SootMethod> methods = sc.getMethods();
   		
   		SootMethod init = null;
   		SootMethod clinit = null;
   		
   		for (SootMethod method : methods)
   		{
   			if (method.getName().equals("<clinit>"))
   			{
   				clinit = method;
   			}
   			
   			if (method.getName().equals("<init>"))
   			{
   				init = method;
   			}
   		}
   		
   		LocalGenerator localGenerator = new LocalGenerator(body);
   		
   		Local obj = localGenerator.generateLocal(sc.getType());
   		
   		Unit newU = Jimple.v().newAssignStmt(obj, Jimple.v().newNewExpr(sc.getType())); 
   		units.insertBefore(newU, returnStmt);
   		
   		if (null != clinit)
   		{
   			Unit clinitCallU = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(clinit.makeRef()));
   			units.insertBefore(clinitCallU, returnStmt);
   		}
   		
   		if (null != init)
   		{
   			List<Type> initParamTypes = init.getParameterTypes();
   	    	List<Value> initParamValues = new ArrayList<Value>();
   	    	for (int i = 0; i < initParamTypes.size(); i++)
   	    	{
   	    		initParamValues.add(InstrumentationUtils.toDefaultSootTypeValue(initParamTypes.get(i)));
   	    	}
   	    	
   	    	Unit initCallU = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(obj, init.makeRef(), initParamValues));
   	    	units.insertBefore(initCallU, returnStmt);
   		}
   		else
   		{
   			throw new RuntimeException("Is it possible that a class does not contain an <init> method?");
   		}
   	}
   	
   	System.out.println(body);
   	body.validate();
   	
   	return mainMethod;
}
 
Example #6
Source File: UnitThrowAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
	public void caseReturnVoidStmt(ReturnVoidStmt s) {
//	    result = result.add(mgr.ILLEGAL_MONITOR_STATE_EXCEPTION);
	}
 
Example #7
Source File: UnreachableCodeFinder.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DavaFlowSet processAbruptStatements(Stmt s, DavaFlowSet input){
   	if(DEBUG)	System.out.println("processing stmt "+s);
   	if(s instanceof ReturnStmt || s instanceof RetStmt || s instanceof ReturnVoidStmt){
   	    //dont need to remember this path
   		UnreachableCodeFlowSet toReturn = new UnreachableCodeFlowSet();
   		toReturn.add(new Boolean(false));
   		toReturn.copyInternalDataFrom(input);
   		//false indicates NOPATH
       	if(DEBUG)	System.out.println("\tstmt is a return stmt. Hence sending forward false");
   	    return toReturn;
   	}
   	else if(s instanceof DAbruptStmt){
   	    DAbruptStmt abStmt = (DAbruptStmt)s;
   	    
   	    //see if its a break or continue
   	    if(!(abStmt.is_Continue()|| abStmt.is_Break())){
   	    	//DAbruptStmt is of only two kinds
   	    	throw new RuntimeException("Found a DAbruptStmt which is neither break nor continue!!");
   	    }		    
   	    
   	    DavaFlowSet temp = new UnreachableCodeFlowSet();
   	    SETNodeLabel nodeLabel = abStmt.getLabel();

   	    //    	  notice we ignore continues for this analysis
   		if (abStmt.is_Break()){
   			if(nodeLabel != null && nodeLabel.toString() != null){
   				//explicit break stmt    	    
   	    		temp.addToBreakList(nodeLabel.toString(),input);			
   			}
   			else{
   				//found implicit break
   	    		temp.addToImplicitBreaks(abStmt,input);    	    	
   			}
   	    }
   	    temp.add(new Boolean(false));
   	    temp.copyInternalDataFrom(input);
       	if(DEBUG)	System.out.println("\tstmt is an abrupt stmt. Hence sending forward false");
   	    return temp;
   	}
   	else{
       	if(DEBUG)	System.out.println("\tstmt is not an abrupt stmt.");
   	    return processStatement(s,input);
   	}
   }
 
Example #8
Source File: StructuredAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Whenever a statement has to be processed the first step is to invoke this
 * method. This is to remove the tedious work of adding code to deal with
 * abrupt control flow from the programmer of the analysis. The method
 * invokes the processStatement method for all other statements
 * 
 * A programmer can decide to override this method if they want to do
 * something specific
 */
public DavaFlowSet processAbruptStatements(Stmt s, DavaFlowSet input) {
	if (s instanceof ReturnStmt || s instanceof RetStmt || s instanceof ReturnVoidStmt) {
		// dont need to remember this path
		return NOPATH;
	} else if (s instanceof DAbruptStmt) {
		DAbruptStmt abStmt = (DAbruptStmt) s;

		// see if its a break or continue
		if (!(abStmt.is_Continue() || abStmt.is_Break())) {
			// DAbruptStmt is of only two kinds
			throw new RuntimeException("Found a DAbruptStmt which is neither break nor continue!!");
		}

		DavaFlowSet temp = NOPATH;
		SETNodeLabel nodeLabel = abStmt.getLabel();
		// System.out.println("here");
		if (nodeLabel != null && nodeLabel.toString() != null) {
			// explicit abrupt stmt
			if (abStmt.is_Continue())
				temp.addToContinueList(nodeLabel.toString(), input);
			else if (abStmt.is_Break())
				temp.addToBreakList(nodeLabel.toString(), input);
			else
				throw new RuntimeException("Found abruptstmt which is neither break nor continue");
		} else {
			// found implicit break/continue
			if (abStmt.is_Continue())
				temp.addToImplicitContinues(abStmt, input);
			else if (abStmt.is_Break())
				temp.addToImplicitBreaks(abStmt, input);
			else
				throw new RuntimeException("Found abruptstmt which is neither break nor continue");
		}
		return temp;
	} else {
		/**************************************************************/
		/****** ALL OTHER STATEMENTS HANDLED BY PROGRAMMER **************/
		/**************************************************************/
		return processStatement(s, input);
	}
}
 
Example #9
Source File: ReturnVoidInstruction.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void jimplify (DexBody body) {
    ReturnVoidStmt returnStmt = Jimple.v().newReturnVoidStmt();
    setUnit(returnStmt);
    addTags(returnStmt);
    body.add(returnStmt);
}
 
Example #10
Source File: DexReturnInliner.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private boolean isInstanceofReturn(Unit u) {
	if (u instanceof ReturnStmt || u instanceof ReturnVoidStmt)
		return true;
	return false;
}
 
Example #11
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
}
 
Example #12
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
}
 
Example #13
Source File: ConstraintChecker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
}
 
Example #14
Source File: StmtTemplatePrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
	printStmt(stmt);
}
 
Example #15
Source File: StmtTranslator.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
	Return r = new Return();
	r.setAssignmentTarget(null);
	addStatement(r);
}
 
Example #16
Source File: JimpleStmtVisitorImpl.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
	//do nothing
	return;
}
 
Example #17
Source File: UseChecker.java    From JAADAS with GNU General Public License v3.0 votes vote down vote up
public void caseReturnVoidStmt(ReturnVoidStmt stmt) { }