soot.util.Chain Java Examples

The following examples show how to use soot.util.Chain. 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: ReflectiveCallsInliner.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void insertCastOrBoxingCode(Local lhs, Local rhs, Chain<Unit> newUnits) {
	//if assigning to a primitive type then there's nothing to do
	if(lhs.getType() instanceof RefLikeType) {
		if((rhs.getType() instanceof RefLikeType)) {
			//insert cast
			newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newCastExpr(rhs, lhs.getType())));
		} else {
			//primitive type in rhs; insert boxing code
		    RefType boxedType = ((PrimType)rhs.getType()).boxedType();
			SootMethodRef ref = Scene.v().makeMethodRef(
				      boxedType.getSootClass(),
				      "valueOf",
				      Collections.<Type>singletonList(rhs.getType()),
				      boxedType,
				      true
				    );
			newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newStaticInvokeExpr(ref,rhs)));
		}
	}
}
 
Example #2
Source File: ReflectiveCallsInliner.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void insertCastOrUnboxingCode(Local lhs, Local rhs, Chain<Unit> newUnits) {
	//if assigning to a reference type then there's nothing to do
	if(lhs.getType() instanceof PrimType) {
		if((rhs.getType() instanceof PrimType)) {
			//insert cast
			newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newCastExpr(rhs, lhs.getType())));
		} else {
			//reference type in rhs; insert unboxing code
		    RefType boxedType = (RefType) rhs.getType();
			SootMethodRef ref = Scene.v().makeMethodRef(
				      boxedType.getSootClass(),
				      lhs.getType().toString() + "Value",
				      Collections.<Type>emptyList(),
				      lhs.getType(),
				      false
				    );
			newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newVirtualInvokeExpr(rhs, ref)));
		}
	}
}
 
Example #3
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 #4
Source File: EnhancedUnitGraph.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method adds a STOP node to the graph, if necessary, to make the CFG
 * single-tailed.
 */

protected void handleMultipleReturns()
{

	if(this.getTails().size() > 1)
	{
		Unit stop = new ExitStmt();
	    List<Unit> predsOfstop = new ArrayList<Unit>();

	    
		for(Iterator<Unit> tailItr = this.getTails().iterator(); tailItr.hasNext(); )
		{
			Unit tail = tailItr.next();
			predsOfstop.add(tail);
		
			List<Unit> tailSuccs = this.unitToSuccs.get(tail);
			tailSuccs.add(stop);	
		}
		
	    this.unitToPreds.put(stop, predsOfstop);
	    this.unitToSuccs.put(stop, new ArrayList<Unit>());

	    Chain<Unit> units = body.getUnits().getNonPatchingChain();
	    if(!units.contains(stop))
	    	units.addLast(stop);	    
	}
}
 
Example #5
Source File: SootClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/** Makes this class a phantom class. */
public void setPhantomClass()
{
    Chain<SootClass> c = Scene.v().getContainingChain(this);
    if (c != null)
        c.remove(this);
    Scene.v().getPhantomClasses().add(this);
    isPhantom = true;
}
 
Example #6
Source File: SootClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/** Makes this class a library class. */
public void setLibraryClass()
{
    Chain<SootClass> c = Scene.v().getContainingChain(this);
    if (c != null)
        c.remove(this);
    Scene.v().getLibraryClasses().add(this);

    isPhantom = false;
}
 
Example #7
Source File: SootClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/** Makes this class an application class. */
public void setApplicationClass()
{
    Chain<SootClass> c = Scene.v().getContainingChain(this);
    if (c != null)
        c.remove(this);
    Scene.v().getApplicationClasses().add(this);

    isPhantom = false;
}
 
Example #8
Source File: SootClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a backed Chain of the interfaces that are directly implemented by this class. (see getInterfaceCount())
 */

public Chain<SootClass> getInterfaces()
{
    checkLevel(HIERARCHY);
    return interfaces;
}
 
Example #9
Source File: SootClass.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a backed Chain of fields.
 */

public Chain<SootField> getFields()
{
    checkLevel(SIGNATURES);
    return fields;
}
 
Example #10
Source File: DavaPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void printStatementsInBody(Body body, java.io.PrintWriter out) {
  
  if (Options.v().verbose())
    System.out.println("Printing "+body.getMethod().getName());
  
    Chain<Unit> units = ((DavaBody) body).getUnits();

    if (units.size() != 1) {
        throw new RuntimeException("DavaBody AST doesn't have single root.");
    }

    UnitPrinter up = new DavaUnitPrinter((DavaBody)body);
    ((ASTNode) units.getFirst()).toString(up);
    out.print( up.toString() );
}
 
Example #11
Source File: GraphComparer.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A utility method for determining if a {@link Unit} is among
 * those protected by a particular {@link Trap}..
 *
 * @param unit the {@link Unit} being asked about.
 *
 * @param trap the {@link Trap} being asked about.
 *
 * @return <tt>true</tt> if <tt>unit</tt> is protected by
 * <tt>trap</tt>, false otherwise.
 */
protected boolean amongTrappedUnits(Unit unit, Trap trap) {
    Chain units = exceptional.getBody().getUnits();
    for (Iterator it = units.iterator(trap.getBeginUnit(),
				      units.getPredOf(trap.getEndUnit()));
	 it.hasNext(); ) {
	Unit u = (Unit) it.next();
	if (u == unit) {
	    return true;
	}
    }
    return false;
}
 
Example #12
Source File: AccessPathParser.java    From SPDS with Eclipse Public License 2.0 5 votes vote down vote up
private static Local getLocal(SootMethod m, String baseName) {
    Chain<Local> locals = m.getActiveBody().getLocals();
    for (Local l : locals) {
        if (l.getName().equals(baseName))
            return l;
    }
    throw new RuntimeException("Could not find local with name " + baseName + " in method " + m);
}
 
Example #13
Source File: DavaStaticBlockCleaner.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void staticBlockInlining(SootClass sootClass){
	this.sootClass=sootClass;
	//retrieve the clinit method if any for sootClass
	//the clinit method gets converted into the static block which could initialize the final variable
	if(!sootClass.declaresMethod("void <clinit>()")){
		//System.out.println("no clinit");
		return;
	}

	SootMethod clinit = sootClass.getMethod("void <clinit>()");
	//System.out.println(clinit);

	//retireve the active body
	if (!clinit.hasActiveBody())
		throw new RuntimeException("method "+ clinit.getName()+ " has no active body!");

	
	Body clinitBody = clinit.getActiveBody();	
    Chain units = ((DavaBody) clinitBody).getUnits();

    if (units.size() != 1) {
        throw new RuntimeException("DavaBody AST doesn't have single root.");
    }

    ASTNode AST = (ASTNode) units.getFirst();
    if(! (AST instanceof ASTMethodNode))
    	throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode");

    //running methodCallFinder on the Clinit method 	
    AST.apply(new MethodCallFinder(this));
}
 
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: JimpleReduceStaticFieldsTransformer.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void extractClassesContainStatic()
{
	Chain<SootClass> sootClasses = getAnalyzedClasses();
	
	for (Iterator<SootClass> iter = sootClasses.snapshotIterator(); iter.hasNext(); )
	{
		SootClass sc = iter.next();
		
		if (sc.toString().startsWith("android.support"))
		{
			continue;
		}
		
		Chain<SootField> fields = sc.getFields();
		Iterator<SootField> fieldIter = fields.snapshotIterator();
		while (fieldIter.hasNext())
		{
			SootField sf = fieldIter.next();
			if (sf.isStatic())
			{
				put(sc.getName(), sf);
			}
		}
		
		/*
		List<SootMethod> sms = sc.getMethods();
		for (SootMethod sm : sms)
		{
			try
			{
				Body b = sm.retrieveActiveBody();
				System.out.println(b);
			}
			catch (Exception ex)
			{
				
			}
		}*/
	}
}
 
Example #16
Source File: SootUtil.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public static boolean hasRecursiveField(SootClass sootClass) {
  Chain fields = sootClass.getFields();
  for (Iterator iter = fields.iterator(); iter.hasNext();) {
    SootField sootField = (SootField) iter.next();
    Type type = sootField.getType();
    if (type instanceof RefType) {
      RefType refType = (RefType) type;
      SootClass sootClass2 = refType.getSootClass();
      if (sootClass == sootClass2) {
        return true;
      }
    }
  }
  return false;
}
 
Example #17
Source File: RemoveRedundantPushStores.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void fixJumps(Unit from, Unit to, Chain<Trap> t) {
  from.redirectJumpsToThisTo(to);
  for (Trap trap : t) {
    if (trap.getBeginUnit() == from)
      trap.setBeginUnit(to);
    if (trap.getEndUnit() == from)
      trap.setEndUnit(to);
    if (trap.getHandlerUnit() == from)
      trap.setHandlerUnit(to);
  }
}
 
Example #18
Source File: JimpleBodyUpdater.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void updateJimple(boolean excludeAndroidSupportJar) 
{
	Chain<SootClass> sootClasses = Scene.v().getClasses();
	for (SootClass sc : sootClasses)
	{	
		if (sc.getName().startsWith("android.support") && excludeAndroidSupportJar)
		{
			continue;
		}
		
		List<SootMethod> sootMethods = sc.getMethods();
		for (SootMethod sm : sootMethods)
		{
			Body b = null;
			try
			{
				b = sm.retrieveActiveBody();
			}
			catch (Exception ex) {
				continue;
			}
			
			this.updateBodyJimple(b);
		}
	}
	
}
 
Example #19
Source File: StackTypeHeightCalculator.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private static RefType isHandlerUnit(Chain<Trap> traps, Unit h) {
  Iterator<Trap> it = traps.iterator();
  while (it.hasNext()) {
    Trap t = (Trap)it.next();
    if (t.getHandlerUnit() == h)
      return t.getException().getType();
  }
  return null;
}
 
Example #20
Source File: Scene.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
Chain<SootClass> getContainingChain(SootClass c)
{
    if (c.isApplicationClass())
        return getApplicationClasses();
    else if (c.isLibraryClass())
        return getLibraryClasses();
    else if (c.isPhantomClass())
        return getPhantomClasses();

    return null;
}
 
Example #21
Source File: IndirectIfJumpsToCaughtGotos.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private Unit findNonTrappedUnit(PatchingChain<Unit> units, Chain<Trap> traps) {
  int intrap = 0;
  ArrayList<Unit> untrapped = new ArrayList<Unit>();
  Iterator<Unit> it = units.snapshotIterator();
  while (it.hasNext()) {
    Unit u = it.next();
    Iterator<Trap> tit = traps.iterator();
    while (tit.hasNext()) {
      Trap t = tit.next();
      if (u == t.getBeginUnit()) intrap++;
      if (u == t.getEndUnit()) intrap--;
    }
    
    if (intrap == 0) untrapped.add(u);
  }
  
  Unit result = null;
  if (untrapped.size() > 0) {
    int count = 0;
    while (result == null && count <10) {
      count++;
      result = untrapped.get(Rand.getInt(999999) % untrapped.size());
      if (!result.fallsThrough() || units.getSuccOf(result) == null || units.getSuccOf(result) instanceof ThrowInst) 
        result = null;
    }
  }
  
  return result;
}
 
Example #22
Source File: BodyBuilder.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isExceptionCaughtAt(Chain<Unit> units, Unit u, Iterator<Trap> trapsIt)
{
  while (trapsIt.hasNext())
  {
    Trap t = trapsIt.next();
    Iterator<Unit> it = units.iterator(t.getBeginUnit(),units.getPredOf(t.getEndUnit()));
    while (it.hasNext())
      if (u.equals(it.next()))
        return true;
  }
  
  return false;
}
 
Example #23
Source File: Scene.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void prepareClasses() {
    // Remove/add all classes from packageInclusionMask as per -i option
    Chain<SootClass> processedClasses = new HashChain<SootClass>();
    while(true) {
        Chain<SootClass> unprocessedClasses = new HashChain<SootClass>(getClasses());
        unprocessedClasses.removeAll(processedClasses);
        if( unprocessedClasses.isEmpty() ) break;
        processedClasses.addAll(unprocessedClasses);
        for (SootClass s : unprocessedClasses) {
            if( s.isPhantom() ) continue;
            if(Options.v().app()) {
                s.setApplicationClass();
            }
            if (Options.v().classes().contains(s.getName())) {
                s.setApplicationClass();
                continue;
            }
            if(s.isApplicationClass() && isExcluded(s)){
                s.setLibraryClass();
            }
            if(isIncluded(s)){
                s.setApplicationClass();
            }
            if(s.isApplicationClass()) {
                // make sure we have the support
                loadClassAndSupport(s.getName());
            }
        }
    }
}
 
Example #24
Source File: BodyBuilder.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public static void updateTraps(Unit oldu, Unit newu, Chain<Trap> traps) {
  int size = traps.size();
  if (size == 0) return;
  
  Trap t = traps.getFirst();
  do {
    if (t.getBeginUnit() == oldu)
      t.setBeginUnit(newu);
    if (t.getEndUnit() == oldu)
      t.setEndUnit(newu);
    if (t.getHandlerUnit() == oldu)
      t.setHandlerUnit(newu);
  } while ((--size > 0) && (t = traps.getSuccOf(t)) != null);
}
 
Example #25
Source File: UtilDecisionMaker.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
public static Set<Unit> extractAllTargetLocations() {
	//extract all logging points from file
	Set<String> targetLocationsTmp = new HashSet<String>();
	
	Set<String> targetMethods = new HashSet<String>();		
	Set<Unit> allTargetLocations = new HashSet<Unit>();
	
	try{
		BufferedReader br = new BufferedReader(new FileReader(TARGET_METHODS_FILENAME));
	    try {
	        String line;
	        while ((line = br.readLine()) != null) {
	        	targetLocationsTmp.add(line);
	        }
	    } finally {
	        br.close();
	    }
	}catch(Exception ex) {
		LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, ex.getMessage());
		ex.printStackTrace();
		System.exit(-1);
	}
	
	targetMethods.addAll(targetLocationsTmp);
	
	if(!targetLocationsTmp.isEmpty()) {
		
		Chain<SootClass> applicationClasses = Scene.v().getApplicationClasses();
		for(SootClass clazz : applicationClasses) {				
			//no need to look into our code
			if (!UtilInstrumenter.isAppDeveloperCode(clazz)) 
				continue;
			
			for(SootMethod method : clazz.getMethods()) {
				if(method.hasActiveBody()) {
					Body body = method.retrieveActiveBody();
					for (Iterator<Unit> unitIt = body.getUnits().iterator(); unitIt.hasNext(); ) {
						Unit curUnit = unitIt.next();
						if(curUnit instanceof Stmt) {
							Stmt statement = (Stmt)curUnit;
							
							if(statement.containsInvokeExpr()){
								InvokeExpr invExpr = statement.getInvokeExpr();
								String invokeExprMethodSignature = invExpr.getMethod().getSignature();
								
								for(String targetLocation : targetLocationsTmp) {
									//we accept all classes
									if(targetLocation.startsWith("<*:")) {
										String pattern = "<.:\\s(.*)\\s(.*)\\((.*)\\)>";
									      Pattern r = Pattern.compile(pattern);

									      Matcher m = r.matcher(targetLocation);
									      if (m.find()) {
									    	  if(m.group(1).equals(invExpr.getMethod().getReturnType().toString()) &&
									    		  m.group(2).equals(invExpr.getMethod().getName()))
									    		  allTargetLocations.add(curUnit);
									      }
									}
									else if(targetLocation.equals(invokeExprMethodSignature))
										allTargetLocations.add(curUnit);
								}
							}
						}
					}
				}
			}
		}
	}
	
	return allTargetLocations;		
}
 
Example #26
Source File: EnhancedUnitGraph.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method removes all the heads in the CFG except the one
 * that corresponds to the first unit in the method. 
 */

protected void removeBogusHeads()
{
	Chain<Unit> units = body.getUnits();
	Unit trueHead = units.getFirst();
	
	while(this.getHeads().size() > 1)
	{
		for(Iterator<Unit> headItr = this.getHeads().iterator(); headItr.hasNext(); )
		{
			Unit head = headItr.next();
			if(trueHead == head)
				continue;
			
			this.unitToPreds.remove(head);
			List<Unit> succs = this.unitToSuccs.get(head);
			for(Iterator<Unit> succsItr = succs.iterator(); succsItr.hasNext(); )
			{
				List<Unit> tobeRemoved = new ArrayList<Unit>();
				
				Unit succ = succsItr.next();
				List<Unit> predOfSuccs = this.unitToPreds.get(succ);
				

				for(Iterator<Unit> predItr = predOfSuccs.iterator(); predItr.hasNext(); )
				{
					Unit pred = predItr.next();
					if(pred == head)
						tobeRemoved.add(pred);	
					
				}
				
				predOfSuccs.removeAll(tobeRemoved);
			}
			
			this.unitToSuccs.remove(head);
			
			if(units.contains(head))
				units.remove(head);
		}
		
		this.buildHeadsAndTails();
	}
}
 
Example #27
Source File: ConstructorFolder.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/** This method change all new Obj/<init>(args) pairs to new Obj(args) idioms. */
protected void internalTransform(Body b, String phaseName, Map options)
{
    GrimpBody body = (GrimpBody)b;

    if(Options.v().verbose())
        G.v().out.println("[" + body.getMethod().getName() +
            "] Folding constructors...");

  Chain units = body.getUnits();
  List<Unit> stmtList = new ArrayList<Unit>();
  stmtList.addAll(units);

  Iterator<Unit> it = stmtList.iterator();
  
  LocalUses localUses = LocalUses.Factory.newLocalUses(b);

  /* fold in NewExpr's with specialinvoke's */
  while (it.hasNext())
    {
      Stmt s = (Stmt)it.next();
        
      if (!(s instanceof AssignStmt))
        continue;
        
      /* this should be generalized to ArrayRefs */
      Value lhs = ((AssignStmt)s).getLeftOp();
      if (!(lhs instanceof Local))
        continue;
        
      Value rhs = ((AssignStmt)s).getRightOp();
      if (!(rhs instanceof NewExpr))
        continue;

      /* TO BE IMPLEMENTED LATER: move any copy of the object reference
         for lhs down beyond the NewInvokeExpr, with the rationale
         being that you can't modify the object before the constructor
         call in any case.

         Also, do note that any new's (object creation) without
         corresponding constructors must be dead. */
       
      List lu = localUses.getUsesOf(s);
      Iterator luIter = lu.iterator();
      boolean MadeNewInvokeExpr = false;
       
      while (luIter.hasNext())
        {
          Unit use = ((UnitValueBoxPair)(luIter.next())).unit;
          if (!(use instanceof InvokeStmt))
            continue;
          InvokeStmt is = (InvokeStmt)use;
          if (!(is.getInvokeExpr() instanceof SpecialInvokeExpr) ||
              lhs != ((SpecialInvokeExpr)is.getInvokeExpr()).getBase())
            continue;
          
          SpecialInvokeExpr oldInvoke = 
            ((SpecialInvokeExpr)is.getInvokeExpr());
          LinkedList invokeArgs = new LinkedList();
          for (int i = 0; i < oldInvoke.getArgCount(); i++)
            invokeArgs.add(oldInvoke.getArg(i));
          
          AssignStmt constructStmt = Grimp.v().newAssignStmt
            ((AssignStmt)s);
          constructStmt.setRightOp
            (Grimp.v().newNewInvokeExpr
             (((NewExpr)rhs).getBaseType(), oldInvoke.getMethodRef(), invokeArgs));
          MadeNewInvokeExpr = true;
          
          use.redirectJumpsToThisTo(constructStmt);
          units.insertBefore(constructStmt, use);
          units.remove(use);
        }
      if (MadeNewInvokeExpr)
        {
          units.remove(s);
        }
    }
}
 
Example #28
Source File: ICCInstrumentDestination.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void assignIntent(SootClass hostComponent, SootMethod method, int indexOfArgs)
  {
  	Body body = method.getActiveBody();

  	PatchingChain<Unit> units = body.getUnits();
  	Chain<Local> locals = body.getLocals();
  	Value intentV = null;
int identityStmtIndex = 0;

  	for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); )
  	{
  		Stmt stmt = (Stmt) iter.next();
	if (! method.isStatic())
	{
   		if (stmt instanceof IdentityStmt)
   		{			
   			if (identityStmtIndex == indexOfArgs)
   			{
   				intentV = ((IdentityStmt) stmt).getLeftOp();
   			}
   			
   			identityStmtIndex++;
   		}
   		else
   		{
   	 		Local thisLocal = locals.getFirst();
   			
   	 		/*
   			Unit setIntentU = Jimple.v().newAssignStmt(     
   					intentV,
   					Jimple.v().newVirtualInvokeExpr(thisLocal, method.getDeclaringClass().getMethodByName("getIntent").makeRef()));
			*/
   	 		
   	 		/* Using the component that the dummyMain() belongs to, as in some cases the invoked method is only available in its superclass.
   	 		 * and its superclass does not contain getIntent() and consequently cause an runtime exception of couldn't find getIntent(). 
   	 		 * 
   	 		 * RuntimeException: couldn't find method getIntent(*) in com.google.android.gcm.GCMBroadcastReceiver
   	 		*/
   	 		Unit setIntentU = Jimple.v().newAssignStmt(     
   					intentV,
   					Jimple.v().newVirtualInvokeExpr(thisLocal, hostComponent.getMethodByName("getIntent").makeRef()));
   	 		
    		units.insertBefore(setIntentU, stmt);
    		
    		System.out.println(body);
    		
    		return;
   		}
	}
	
  		
  	}
  }
 
Example #29
Source File: InfoStatistic.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void updateJimple() 
{
	numberOfClass = 0;
	numberOfComponent = 0;
	numberOfLine = 0;
	numberOfMethod = 0;
	
	Chain<SootClass> sootClasses = Scene.v().getClasses();
	
	for (Iterator<SootClass> iter = sootClasses.snapshotIterator(); iter.hasNext(); )
	{
		SootClass sc = iter.next();
		
		if (sc.getName().startsWith("android.support."))
		{
			continue;
		}
		
		numberOfClass++;

		if (isAndroidComponent(sc))
		{
			numberOfComponent++;
		}
		
		List<SootMethod> sootMethods = sc.getMethods();
		for (SootMethod sm : sootMethods)
		{
			numberOfMethod++;
			
			try
			{
				Body b = sm.retrieveActiveBody();
				
				if (sc.getName().equals("de.ecspride.MainActivity"))
				{
					System.out.println(b);
				}
				
				
				PatchingChain<Unit> units = b.getUnits();
				for (Iterator<Unit> iter2 = units.snapshotIterator(); iter2.hasNext(); )
				{
					numberOfLine++;
					
					iter2.next();
				}
			}
			catch (Exception ex)
			{
				//ex.printStackTrace();
			}
		}
	}
	
	StringBuilder sb = new StringBuilder();
	sb.append("In step " + step + ", " + "The number of Jimple line is " + numberOfLine + "\n");
	sb.append("In step " + step + ", " + "The number of Jimple method is " + numberOfMethod + "\n");
	sb.append("In step " + step + ", " + "The number of Jimple class is " + numberOfClass + "\n");
	sb.append("In step " + step + ", " + "The number of Jimple component is " + numberOfComponent + "\n");
	System.out.println(sb.toString());
}
 
Example #30
Source File: PatchingChain.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/** Constructs a PatchingChain from the given Chain. */
public PatchingChain(Chain<E> aChain)
{
    innerChain = aChain;
}