soot.jimple.IfStmt Java Examples

The following examples show how to use soot.jimple.IfStmt. 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: 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 #2
Source File: LocalConstraintFlowAnalysis.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void flowThrough(ConstrainInfo in, Unit s,
		List<ConstrainInfo> fallOut,
		List<ConstrainInfo> branchOuts) {
	//System.out.println("flow through: " + s);
	//System.out.println("in: "+in);
	ConstrainInfo out = new ConstrainInfo(in);
	ConstrainInfo outBranch = new ConstrainInfo(in);
	if (s instanceof IfStmt) {
		IfStmt stmt = (IfStmt)s;
		out.intersect(stmt, false);
		outBranch.intersect(stmt,true);

	}
	for( Iterator<ConstrainInfo> it = fallOut.iterator(); it.hasNext(); ) {
		//System.out.println("copying to fallout in flowthrough");
		copy(out, it.next());
	}
	for( Iterator<ConstrainInfo> it = branchOuts.iterator(); it.hasNext(); ) {
		//System.out.println("copying to branchout in flowthrough");
		copy( outBranch, it.next() );
	}
}
 
Example #3
Source File: DexIfTransformer.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Collect all the if statements comparing two locals with an Eq or Ne
 * expression
 *
 * @param body
 *            the body to analyze
 */
private Set<IfStmt> getNullIfCandidates(Body body) {
	Set<IfStmt> candidates = new HashSet<IfStmt>();
	Iterator<Unit> i = body.getUnits().iterator();
	while (i.hasNext()) {
		Unit u = i.next();
		if (u instanceof IfStmt) {
			ConditionExpr expr = (ConditionExpr) ((IfStmt) u).getCondition();
			boolean isTargetIf = false;
			if (((expr instanceof EqExpr) || (expr instanceof NeExpr))) {
				if (expr.getOp1() instanceof Local && expr.getOp2() instanceof Local) {
					isTargetIf = true;
				}
			}
			if (isTargetIf) {
				candidates.add((IfStmt) u);
				Debug.printDbg("[add if candidate: ", u);
			}

		}
	}

	return candidates;
}
 
Example #4
Source File: IfTestInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected IfStmt ifStatement(DexBody body) {
      Instruction22t i = (Instruction22t) instruction;
      Local one = body.getRegisterLocal(i.getRegisterA());
      Local other = body.getRegisterLocal(i.getRegisterB());
      BinopExpr condition = getComparisonExpr(one, other);
      jif = (JIfStmt)Jimple.v().newIfStmt(condition, targetInstruction.getUnit());
      // setUnit() is called in ConditionalJumpInstruction

if (IDalvikTyper.ENABLE_DVKTYPER) {
    Debug.printDbg(IDalvikTyper.DEBUG, "constraint if: "+ jif +" condition: "+ condition);
    DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box());
      }
      
      
      return jif;
      
  }
 
Example #5
Source File: ConditionalJumpInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify(DexBody body) {
        // check if target instruction has been jimplified
        if (getTargetInstruction(body).getUnit() != null) {
            IfStmt s = ifStatement(body);
            body.add(s);
            setUnit(s);
        } else {
          // set marker unit to swap real gotostmt with otherwise
          body.addDeferredJimplification(this);
          markerUnit = Jimple.v().newNopStmt();
          unit = markerUnit;
//          beginUnit = markerUnit;
//          endUnit = markerUnit;
//          beginUnit = markerUnit;
          body.add(markerUnit);
//          Unit end = Jimple.v().newNopStmt();
//          body.add(end);
//          endUnit = end;
        }
    }
 
Example #6
Source File: ConditionTracking.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;
	
	//important to use snapshotIterator here
	Iterator<Unit> iterator = body.getUnits().snapshotIterator();
	
	while(iterator.hasNext()){
		Unit unit = iterator.next();
		
		if(unit instanceof IfStmt
				&& !unit.hasTag(InstrumentedCodeTag.name)) {
			instrumentEachBranchAccess(body, unit);
		}
	}
	
}
 
Example #7
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);
}
 
Example #8
Source File: ForwardBoomerangSolver.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void computeSuccessor(Node<Statement, Val> node) {
    Statement stmt = node.stmt();
    Optional<Stmt> unit = stmt.getUnit();
    if (unit.isPresent()) {
        Stmt curr = unit.get();
        Val value = node.fact();
        SootMethod method = icfg.getMethodOf(curr);
        if (method == null)
            return;
        if (icfg.isExitStmt(curr)) {
            returnFlow(method, node);
            return;
        }
        for (Unit next : icfg.getSuccsOf(curr)) {
            Stmt nextStmt = (Stmt) next;
            if (query.getType() instanceof NullType && curr instanceof IfStmt
                    && killAtIfStmt((IfStmt) curr, value, next)) {
                continue;
            }
            if (nextStmt.containsInvokeExpr() && (isParameter(value, nextStmt) || value.isStatic())) {
                callFlow(method, node, nextStmt, nextStmt.getInvokeExpr());
            } else if (!killFlow(method, nextStmt, value)) {
                Collection<State> out = computeNormalFlow(method, curr, value, nextStmt);
                for (State s : out) {
                    propagate(node, s);
                }
            }
        }
    }
}
 
Example #9
Source File: LocalConstraintFlowAnalysis.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void intersect(IfStmt stmt, boolean bool )
  {
  	if (mapping.get(stmt) == null) {
	mapping.put(stmt, IDX);
	++IDX;
}
      Expression<IfStmt> variable = bool?Variable.of(stmt):Not.of(Variable.of(stmt));
      expression = And.of(expression, variable);
      //expression = RuleSet.simplify(expression);
  }
 
Example #10
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGIfStmt() {
    IfStmt s = Grimp.v().newIfStmt(Grimp.v().newEqExpr(IntConstant.v(1), 
                IntConstant.v(1)),
            (Unit) null);
    s.setTarget(s);		// A very tight infinite loop.
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #11
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testJIfStmt() {
    IfStmt s = Jimple.v().newIfStmt(Jimple.v().newEqExpr(IntConstant.v(1), 
                IntConstant.v(1)),
            (Unit) null);
    s.setTarget(s);		// A very tight infinite loop.
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #12
Source File: DexNullTransformer.java    From JAADAS with 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 #13
Source File: IfTestzInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected IfStmt ifStatement(DexBody body) {
      Instruction21t i = (Instruction21t) instruction;
      BinopExpr condition = getComparisonExpr(body, i.getRegisterA());
      jif = (JIfStmt) Jimple.v().newIfStmt(condition,
                                  targetInstruction.getUnit());
      // setUnit() is called in ConditionalJumpInstruction
      
      
if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ jif);
         int op = instruction.getOpcode().value;
         switch (op) {
         case 0x38:
         case 0x39:
           //DalvikTyper.v().addConstraint(condition.getOp1Box(), condition.getOp2Box());
           break;
         case 0x3a:
         case 0x3b:
         case 0x3c:
         case 0x3d:
           DalvikTyper.v().setType(condition.getOp1Box(), BooleanType.v(), true);
           break;
         default:
           throw new RuntimeException("error: unknown op: 0x"+ Integer.toHexString(op));
         }
      }

return jif;
      
  }
 
Example #14
Source File: NullCheckEliminator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void internalTransform(Body body, String phaseName, Map<String,String> options) {

	// really, the analysis should be able to use its own results to determine
	// that some branches are dead, but since it doesn't we just iterate.
	boolean changed;
	do {
	    changed=false;

	    NullnessAnalysis analysis=analysisFactory.newAnalysis(new ExceptionalUnitGraph(body));
	    
	    Chain<Unit> units=body.getUnits();
	    Stmt s;
	    for(s=(Stmt) units.getFirst();s!=null;s=(Stmt) units.getSuccOf(s)) {
		if(!(s instanceof IfStmt)) continue;
		IfStmt is=(IfStmt) s;
		Value c=is.getCondition();
		if(!(c instanceof EqExpr || c instanceof NeExpr)) continue;
		BinopExpr e=(BinopExpr) c;
		Immediate i=null;
		if(e.getOp1() instanceof NullConstant) i=(Immediate) e.getOp2();
		if(e.getOp2() instanceof NullConstant) i=(Immediate) e.getOp1();
		if(i==null) continue;
		boolean alwaysNull = analysis.isAlwaysNullBefore(s, i);
		boolean alwaysNonNull = analysis.isAlwaysNonNullBefore(s, i);
		int elim=0; // -1 => condition is false, 1 => condition is true
		if(alwaysNonNull) elim=c instanceof EqExpr ? -1 : 1;
		if(alwaysNull) elim=c instanceof EqExpr ? 1 : -1;
		Stmt newstmt=null;
		if(elim==-1) newstmt=Jimple.v().newNopStmt();
		if(elim==1) newstmt=Jimple.v().newGotoStmt(is.getTarget());
		if(newstmt!=null) {
		    units.swapWith(s,newstmt);
		    s=newstmt;
		    changed=true;
		}
	    }
	} while(changed);
    }
 
Example #15
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 #16
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 #17
Source File: UtilSMT.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private static IfStmt findConditionalStatementForBooleanUnit(IInfoflowCFG cfg, Unit booleanUnit) {
	Stack<Unit> worklist = new Stack<Unit>();
	Set<Unit> processedUnits = new HashSet<Unit>();
	worklist.add(booleanUnit);	
		
	while(!worklist.isEmpty()) {
		Unit currentUnit = worklist.pop();
		//in case of a loop or recursion
		if(processedUnits.contains(currentUnit))
			continue;
		processedUnits.add(currentUnit);
		
		//skip our own instrumented code
		if(currentUnit.hasTag(InstrumentedCodeTag.name))
			continue;
		
		
		//we reached the condition
		if(currentUnit instanceof IfStmt) {
			return (IfStmt)currentUnit;		 	
		}
		
		SootMethod methodOfBooleanUnit = cfg.getMethodOf(booleanUnit);		
		DirectedGraph<Unit> graph = cfg.getOrCreateUnitGraph(methodOfBooleanUnit);
		//Comment: Steven said it should always be a UnitGraph + he will implement a more convenient way in the near future :-)
		UnitGraph unitGraph = (UnitGraph)graph;

		SimpleLocalDefs defs = new SimpleLocalDefs(unitGraph);
        SimpleLocalUses uses = new SimpleLocalUses(unitGraph, defs);	        
        List<UnitValueBoxPair> usesOfCurrentUnit = uses.getUsesOf(booleanUnit);
        for(UnitValueBoxPair valueBoxPair : usesOfCurrentUnit)
        	worklist.add(valueBoxPair.getUnit());
		
	}
	return null;
}
 
Example #18
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 #19
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 #20
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseIfStmt(IfStmt stmt) {
	if (uses) {
		ConditionExpr cond = (ConditionExpr) stmt.getCondition();

		BinopExpr expr = cond;
		Value lv = expr.getOp1();
		Value rv = expr.getOp2();

		TypeVariable lop;
		TypeVariable rop;

		// ******** LEFT ********
		if (lv instanceof Local) {
			lop = resolver.typeVariable((Local) lv);
		} else if (lv instanceof DoubleConstant) {
			lop = resolver.typeVariable(DoubleType.v());
		} else if (lv instanceof FloatConstant) {
			lop = resolver.typeVariable(FloatType.v());
		} else if (lv instanceof IntConstant) {
			lop = resolver.typeVariable(IntType.v());
		} else if (lv instanceof LongConstant) {
			lop = resolver.typeVariable(LongType.v());
		} else if (lv instanceof NullConstant) {
			lop = resolver.typeVariable(NullType.v());
		} else if (lv instanceof StringConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (lv instanceof ClassConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
		}

		// ******** RIGHT ********
		if (rv instanceof Local) {
			rop = resolver.typeVariable((Local) rv);
		} else if (rv instanceof DoubleConstant) {
			rop = resolver.typeVariable(DoubleType.v());
		} else if (rv instanceof FloatConstant) {
			rop = resolver.typeVariable(FloatType.v());
		} else if (rv instanceof IntConstant) {
			rop = resolver.typeVariable(IntType.v());
		} else if (rv instanceof LongConstant) {
			rop = resolver.typeVariable(LongType.v());
		} else if (rv instanceof NullConstant) {
			rop = resolver.typeVariable(NullType.v());
		} else if (rv instanceof StringConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (rv instanceof ClassConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
		}

		TypeVariable common = resolver.typeVariable();
		rop.addParent(common);
		lop.addParent(common);
	}
}
 
Example #21
Source File: UseChecker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseIfStmt(IfStmt stmt)
{
	this.handleBinopExpr((BinopExpr)stmt.getCondition(), stmt,
		BooleanType.v());
}
 
Example #22
Source File: ConditionalJumpInstruction.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void deferredJimplify(DexBody body) {
    IfStmt s = ifStatement(body);
    body.getBody().getUnits().swapWith(markerUnit, s); //insertAfter(s, markerUnit);
    setUnit(s);
}
 
Example #23
Source File: ArrayIndexLivenessAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void getGenAndKillSet(Body body, HashMap<Stmt, HashSet<Value>> absgen, HashMap<Stmt, HashSet<Object>> gen, HashMap<Stmt, HashSet<Value>> kill, HashMap<Stmt, HashSet<Value>> condition)
{
    for (Unit u : body.getUnits())
    {
        Stmt stmt = (Stmt)u;

        HashSet<Object> genset = new HashSet<Object>();
        HashSet<Value> absgenset = new HashSet<Value>();
        HashSet<Value> killset = new HashSet<Value>();
        HashSet<Value> condset = new HashSet<Value>();
        
        if (stmt instanceof DefinitionStmt)
        {
            getGenAndKillSetForDefnStmt((DefinitionStmt)stmt, absgen,
                                        genset, absgenset, 
                                        killset, condset);

        }
        else if (stmt instanceof IfStmt)
        {
            /* if one of condition is living, than other one is live. */
            Value cmpcond = ((IfStmt)stmt).getCondition();
            
            if (cmpcond instanceof ConditionExpr)
            {
                Value op1 = ((ConditionExpr)cmpcond).getOp1();
                Value op2 = ((ConditionExpr)cmpcond).getOp2();
                
                if (fullSet.contains(op1) && fullSet.contains(op2))
                {
                    condset.add(op1);
                    condset.add(op2);
                    
                    genset.add(op1);
                    genset.add(op2);
                }
            }
        }
        
        if (genset.size() != 0)
            gen.put(stmt, genset);
        if (absgenset.size() != 0)
            absgen.put(stmt, absgenset);
        if (killset.size() != 0)
            kill.put(stmt, killset);
        if (condset.size() != 0)
            condition.put(stmt, condset);
    }
}
 
Example #24
Source File: InterproceduralConstantValuePropagator.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void fixExceptions(SootMethod caller, Unit callSite, Set<SootClass> doneSet) {
	ThrowAnalysis ta = Options.v().src_prec() == Options.src_prec_apk
			? DalvikThrowAnalysis.v() : UnitThrowAnalysis.v();
	ThrowableSet throwSet = ta.mightThrow(callSite);
	
	for (final Trap t : caller.getActiveBody().getTraps())
		if (doneSet.add(t.getException())
				&& throwSet.catchableAs(t.getException().getType())) {
			SootMethod thrower = exceptionThrowers.get(t.getException());
			if (thrower == null) {
				if (exceptionClass == null) {
					exceptionClass = new SootClass("FLOWDROID_EXCEPTIONS", Modifier.PUBLIC);
					Scene.v().addClass(exceptionClass);
				}
				
				// Create the new method
				thrower = new SootMethod("throw" + exceptionThrowers.size(),
						Collections.<Type>emptyList(), VoidType.v());
				thrower.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
				
				final Body body = Jimple.v().newBody(thrower);
				thrower.setActiveBody(body);
				final SootMethod meth = thrower;
				
				IEntryPointCreator epc = new BaseEntryPointCreator() {
	
					@Override
					public Collection<String> getRequiredClasses() {
						return Collections.emptySet();
					}
	
					@Override
					protected SootMethod createDummyMainInternal(SootMethod emptySootMethod) {
				 		LocalGenerator generator = new LocalGenerator(body);
						
				 		// Create the counter used for the opaque predicate
						int conditionCounter = 0;
						Value intCounter = generator.generateLocal(IntType.v());
						AssignStmt assignStmt = new JAssignStmt(intCounter, IntConstant.v(conditionCounter));
						body.getUnits().add(assignStmt);
						
						Stmt afterEx = Jimple.v().newNopStmt();
						IfStmt ifStmt = Jimple.v().newIfStmt(Jimple.v().newEqExpr(intCounter,
								IntConstant.v(conditionCounter)), afterEx);
						body.getUnits().add(ifStmt);
						conditionCounter++;
						
						Local lcEx = generator.generateLocal(t.getException().getType());
						AssignStmt assignNewEx = Jimple.v().newAssignStmt(lcEx,
								Jimple.v().newNewExpr(t.getException().getType()));
						body.getUnits().add(assignNewEx);

						InvokeStmt consNewEx = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(lcEx,
								Scene.v().makeConstructorRef(exceptionClass, Collections.<Type>emptyList())));
						body.getUnits().add(consNewEx);
						
						ThrowStmt throwNewEx = Jimple.v().newThrowStmt(lcEx);
						body.getUnits().add(throwNewEx);
						
						body.getUnits().add(afterEx);
						return meth;
					}
									
				};
				epc.createDummyMain(thrower);
				exceptionThrowers.put(t.getException(), thrower);
				exceptionClass.addMethod(thrower);
			}
			
			// Call the exception thrower after the old call site
			Stmt throwCall = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(thrower.makeRef()));
			caller.getActiveBody().getUnits().insertBefore(throwCall, callSite);
		}
}
 
Example #25
Source File: UnitThrowAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void caseIfStmt(IfStmt s) {
    result = result.add(mightThrow(s.getCondition()));
}
 
Example #26
Source File: JimpleStmtVisitorImpl.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void caseIfStmt(IfStmt stmt) {
	throw new RuntimeException("todo");
	
}
 
Example #27
Source File: ConditionalJumpInstruction.java    From JAADAS with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Return an if statement depending on the instruction.
 */
protected abstract IfStmt ifStatement(DexBody body);