当前位置: 首页>>代码示例>>Java>>正文


Java IfStmt类代码示例

本文整理汇总了Java中soot.jimple.IfStmt的典型用法代码示例。如果您正苦于以下问题:Java IfStmt类的具体用法?Java IfStmt怎么用?Java IfStmt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IfStmt类属于soot.jimple包,在下文中一共展示了IfStmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: internalTransform

import soot.jimple.IfStmt; //导入依赖的package包/类
@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);
	}				
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:21,代码来源:PathExecutionTransformer.java

示例2: internalTransform

import soot.jimple.IfStmt; //导入依赖的package包/类
@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);
		}
	}
	
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:20,代码来源:ConditionTracking.java

示例3: jimplify

import soot.jimple.IfStmt; //导入依赖的package包/类
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;
        }
    }
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:21,代码来源:ConditionalJumpInstruction.java

示例4: ifStatement

import soot.jimple.IfStmt; //导入依赖的package包/类
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;
      
  }
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:18,代码来源:IfTestInstruction.java

示例5: getNullIfCandidates

import soot.jimple.IfStmt; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:31,代码来源:DexIfTransformer.java

示例6: flowThrough

import soot.jimple.IfStmt; //导入依赖的package包/类
@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() );
	}
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:24,代码来源:LocalConstraintFlowAnalysis.java

示例7: toString

import soot.jimple.IfStmt; //导入依赖的package包/类
@Override
public String toString(){
	String ret = "(";
	Object[] listStmt = reachedStmt.toArray();
	int size = listStmt.length;
	int i = 0;
	while(i < size -1){
		Object stmt = listStmt[i];
		ret +=stmt;
		if(stmt instanceof IfStmt){
			ret += "{" + condToExpr.get(stmt) + "}, ";
		} else {
			ret +=", ";
		}
		i++;
	}
	//last element if any
	if(size > 0){
		ret +=listStmt[i];
		if(listStmt[i] instanceof IfStmt){
			ret += "{" + condToExpr.get(listStmt[i]) + "}";
		}
	}
	ret += ")";
	return ret;
}
 
开发者ID:BoiseState,项目名称:Disjoint-Domains,代码行数:27,代码来源:SymbolicState.java

示例8: instrumentEachBranchAccess

import soot.jimple.IfStmt; //导入依赖的package包/类
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);
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:34,代码来源:ConditionTracking.java

示例9: instrumentEachBranchAccess

import soot.jimple.IfStmt; //导入依赖的package包/类
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);
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:37,代码来源:PathExecutionTransformer.java

示例10: findConditionalStatementForBooleanUnit

import soot.jimple.IfStmt; //导入依赖的package包/类
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;
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:37,代码来源:UtilSMT.java

示例11: eliminateSelfLoops

import soot.jimple.IfStmt; //导入依赖的package包/类
/**
 * 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();
		}
	}
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:16,代码来源:BaseEntryPointCreator.java

示例12: caseIfStmt

import soot.jimple.IfStmt; //导入依赖的package包/类
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);
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:12,代码来源:StmtTemplatePrinter.java

示例13: internalTransform

import soot.jimple.IfStmt; //导入依赖的package包/类
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);
    }
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:39,代码来源:NullCheckEliminator.java

示例14: caseIfStmt

import soot.jimple.IfStmt; //导入依赖的package包/类
@Override
public void caseIfStmt(IfStmt stmt) {
	Stmt target = stmt.getTarget();
       exprV.setOrigStmt(stmt);
	exprV.setTargetForOffset(target);
	stmt.getCondition().apply(exprV);
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:8,代码来源:StmtVisitor.java

示例15: ifStatement

import soot.jimple.IfStmt; //导入依赖的package包/类
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;
      
  }
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:31,代码来源:IfTestzInstruction.java


注:本文中的soot.jimple.IfStmt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。