soot.jimple.NopStmt Java Examples

The following examples show how to use soot.jimple.NopStmt. 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: NopEliminator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/** Removes {@link NopStmt}s from the passed body (which must be
a {@link JimpleBody}).  Complexity is linear 
       with respect to the statements.
   */
   
   protected void internalTransform(Body b, String phaseName, Map<String, String> options)
   {
       JimpleBody body = (JimpleBody)b;
       
       if(Options.v().verbose())
           G.v().out.println("[" + body.getMethod().getName() +
               "] Removing nops...");
               
       Chain<Unit> units = body.getUnits();
       
       // Just do one trivial pass.
       {
           Iterator<Unit> stmtIt = units.snapshotIterator();
           
           while(stmtIt.hasNext()) 
           {
               Unit u = stmtIt.next();
			if (u instanceof NopStmt) {
				// Hack: do not remove nop, if is is used for a Trap which
				// is at the very end of the code.
				boolean keepNop = false;
				if (b.getUnits().getLast() == u) {
					for (Trap t : b.getTraps()) {
						if (t.getEndUnit() == u) {
							keepNop = true;
						}
					}
				}
				if (!keepNop) {
					units.remove(u);
				}
			}
           }
       }
   }
 
Example #3
Source File: JimpleStmtVisitorImpl.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void caseNopStmt(NopStmt stmt) {
	throw new RuntimeException("todo");
	
}
 
Example #4
Source File: StmtTemplatePrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseNopStmt(NopStmt stmt) {
	printStmt(stmt);
}
 
Example #5
Source File: ConstraintChecker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseNopStmt(NopStmt stmt) {
}
 
Example #6
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseNopStmt(NopStmt stmt) {
}
 
Example #7
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void caseNopStmt(NopStmt stmt) {
}
 
Example #8
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void caseNopStmt(NopStmt stmt) {
       addInsn(new Insn10x(Opcode.NOP), stmt);
}
 
Example #9
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates an intermediate jump instruction between the original jump
 * instruction and its target
 * @param targetInsPos The jump target index
 * @param jumpInsPos The position of the jump instruction
 * @param stmtV The statement visitor used for constructing the instructions
 * @param instructions The list of Dalvik instructions
 * @param labelAssigner The label assigner to be used for creating new labels
 */
private void insertIntermediateJump(int targetInsPos, int jumpInsPos,
		StmtVisitor stmtV, List<BuilderInstruction> instructions,
		LabelAssigner labelAssigner) {
	// Get the original jump instruction
	BuilderInstruction originalJumpInstruction = instructions.get(jumpInsPos);
	Insn originalJumpInsn = stmtV.getInsnForInstruction(originalJumpInstruction);
	if (originalJumpInsn == null)
		return;
	if (!(originalJumpInsn instanceof InsnWithOffset))
		throw new RuntimeException("Unexpected jump instruction target");
	InsnWithOffset offsetInsn = (InsnWithOffset) originalJumpInsn;
	
	// Find a position where we can jump to
	int distance = Math.max(targetInsPos, jumpInsPos) - Math.min(targetInsPos, jumpInsPos);
	if (distance == 0)
		return;
	int newJumpIdx = Math.min(targetInsPos, jumpInsPos) + (distance / 2);
	int sign = (int) Math.signum(targetInsPos - jumpInsPos);
	if (distance > offsetInsn.getMaxJumpOffset())
		newJumpIdx = jumpInsPos + sign;
	
	// There must be a statement at the instruction after the jump target
	while (stmtV.getStmtForInstruction(instructions.get(newJumpIdx)) == null) {
		 newJumpIdx += sign;
		 if (newJumpIdx < 0 || newJumpIdx >= instructions.size())
			 throw new RuntimeException("No position for inserting intermediate "
					 + "jump instruction found");
	}
	
	// Create a jump instruction from the middle to the end
	NopStmt nop = Jimple.v().newNopStmt();
	Insn30t newJump = new Insn30t(Opcode.GOTO_32);
	newJump.setTarget(stmtV.getStmtForInstruction(instructions.get(targetInsPos)));
	BuilderInstruction newJumpInstruction = newJump.getRealInsn(labelAssigner);
	instructions.add(newJumpIdx, newJumpInstruction);
	stmtV.fakeNewInsn(nop, newJump, newJumpInstruction);
	
	// We have added something, so we need to fix indices
	if (newJumpIdx < jumpInsPos)
		jumpInsPos++;
	if (newJumpIdx < targetInsPos)
		targetInsPos++;
	
	// Jump from the original instruction to the new one in the middle
	offsetInsn.setTarget(nop);
	BuilderInstruction replacementJumpInstruction = offsetInsn.getRealInsn(labelAssigner);
	instructions.add(jumpInsPos, replacementJumpInstruction);
	instructions.remove(originalJumpInstruction);
	stmtV.fakeNewInsn(stmtV.getStmtForInstruction(originalJumpInstruction),
			originalJumpInsn, replacementJumpInstruction);
	
	// Our indices are still fine, because we just replaced something
	Stmt afterNewJump = stmtV.getStmtForInstruction(instructions.get(newJumpIdx + 1));
	
	// Make the original control flow jump around the new artificial jump instruction
	Insn10t jumpAround = new Insn10t(Opcode.GOTO);
	jumpAround.setTarget(afterNewJump);
	BuilderInstruction jumpAroundInstruction = jumpAround.getRealInsn(labelAssigner);
	instructions.add(newJumpIdx, jumpAroundInstruction);
}
 
Example #10
Source File: NopInstruction.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void jimplify (DexBody body) {
    NopStmt nop = Jimple.v().newNopStmt();
    setUnit(nop);
    addTags(nop);
    body.add(nop);
}
 
Example #11
Source File: UnitThrowAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void caseNopStmt(NopStmt s) {
}
 
Example #12
Source File: UseChecker.java    From JAADAS with GNU General Public License v3.0 votes vote down vote up
public void caseNopStmt(NopStmt stmt) { }