soot.jimple.JimpleBody Java Examples

The following examples show how to use soot.jimple.JimpleBody. 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: AbstractASMBackend.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the baf body for the given SootMethod. This method will first check
 * whether the method already has a baf body. If not, it will query the local
 * cache. If this fails as well, it will construct a new baf body.
 * @param method The method for which to obtain a baf body
 * @return The baf body for the given method
 */
protected BafBody getBafBody(SootMethod method) {
	final Body activeBody = method.getActiveBody();
	if (activeBody instanceof BafBody)
		return (BafBody) activeBody;

	BafBody body = bafBodyCache.get(method);
	if (body != null)
		return body;
	
	if (activeBody instanceof JimpleBody) {
		body = PackManager.v().convertJimpleBodyToBaf(method);
	} else {
		throw new RuntimeException(
				"ASM-backend can only translate Baf- and JimpleBodies!");
	}
	
	bafBodyCache.put(method, body);
	return body;
}
 
Example #2
Source File: TypeResolverBV.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private TypeResolverBV(JimpleBody stmtBody, Scene scene)
{
  this.stmtBody = stmtBody;
  hierarchy = ClassHierarchy.classHierarchy(scene);

  OBJECT = hierarchy.OBJECT;
  NULL = hierarchy.NULL;
  typeVariable(OBJECT);
  typeVariable(NULL);
  
  // hack for J2ME library, reported by Stephen Cheng 
  if (!Options.v().j2me()) {
    typeVariable(hierarchy.CLONEABLE);
    typeVariable(hierarchy.SERIALIZABLE);
  }
}
 
Example #3
Source File: TypeAssigner.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private boolean typingFailed(JimpleBody b) {
	// Check to see if any locals are untyped
	{
		Iterator<Local> localIt = b.getLocals().iterator();

		while (localIt.hasNext()) {
			Local l = localIt.next();

			if (l.getType().equals(UnknownType.v())
					|| l.getType().equals(ErroneousType.v())) {
				return true;
			}
		}
	}

	return false;
}
 
Example #4
Source File: TypeResolver.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private TypeResolver(JimpleBody stmtBody, Scene scene)
{
  this.stmtBody = stmtBody;
  hierarchy = ClassHierarchy.classHierarchy(scene);

  OBJECT = hierarchy.OBJECT;
  NULL = hierarchy.NULL;
  typeVariable(OBJECT);
  typeVariable(NULL);
  
  // hack for J2ME library, reported by Stephen Cheng 
  if (!Options.v().j2me()) {
    typeVariable(hierarchy.CLONEABLE);
    typeVariable(hierarchy.SERIALIZABLE);
  }
}
 
Example #5
Source File: AbstractTestingFramework.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
private String getTargetClass() {
    SootClass sootClass = new SootClass("dummyClass");
    Type paramType = ArrayType.v(RefType.v("java.lang.String"), 1);
    SootMethod mainMethod = new SootMethod("main", Collections.singletonList(paramType), VoidType.v(),
            Modifier.PUBLIC | Modifier.STATIC);
    sootClass.addMethod(mainMethod);
    JimpleBody body = Jimple.v().newBody(mainMethod);
    mainMethod.setActiveBody(body);
    RefType testCaseType = RefType.v(getTestCaseClassName());
    Local loc = Jimple.v().newLocal("l0", paramType);
    body.getLocals().add(loc);
    body.getUnits().add(Jimple.v().newIdentityStmt(loc, Jimple.v().newParameterRef(paramType, 0)));
    Local allocatedTestObj = Jimple.v().newLocal("dummyObj", testCaseType);
    body.getLocals().add(allocatedTestObj);
    body.getUnits().add(Jimple.v().newAssignStmt(allocatedTestObj, Jimple.v().newNewExpr(testCaseType)));
    body.getUnits().add(
            Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(allocatedTestObj, sootTestMethod.makeRef())));
    body.getUnits().add(Jimple.v().newReturnVoidStmt());

    Scene.v().addClass(sootClass);
    body.validate();
    return sootClass.toString();
}
 
Example #6
Source File: CFGViewer.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
	initialize(options);
	SootMethod meth = b.getMethod();

	if ((methodsToPrint == null) || (meth.getDeclaringClass().getName() == methodsToPrint.get(meth.getName()))) {
		Body body = ir.getBody((JimpleBody) b);
		print_cfg(body);
	}
}
 
Example #7
Source File: PackManager.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public BafBody convertJimpleBodyToBaf(SootMethod m) {
		JimpleBody body = (JimpleBody) m.getActiveBody().clone();
		//Change
//        ConditionalBranchFolder.v().transform(body);
//        UnreachableCodeEliminator.v().transform(body);
//        DeadAssignmentEliminator.v().transform(body);
//        UnusedLocalEliminator.v().transform(body);
		BafBody bafBody = Baf.v().newBody(body);
		PackManager.v().getPack("bop").apply(bafBody);
		PackManager.v().getPack("tag").apply(bafBody);
		if( Options.v().validate() ) {
		    bafBody.validate();
		}
		return bafBody;
	}
 
Example #8
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 #9
Source File: TypeAssigner.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private static int compareTypings(JimpleBody a, JimpleBody b) {
	int r = 0;

	Iterator<Local> ib = b.getLocals().iterator();
	for (Local v : a.getLocals()) {
		Type ta = v.getType(), tb = ib.next().getType();

		if (soot.jimple.toolkits.typing.fast.TypeResolver
				.typesEqual(ta, tb))
			continue;
		/*
		 * Sometimes there is no reason to choose between the char and byte /
		 * short types. Enabling this check allows one algorithm to select
		 * char and the other to select byte / short without returning
		 * incomparable.
		 */
		else if (true && ((ta instanceof CharType && (tb instanceof ByteType || tb instanceof ShortType))
			           || (tb instanceof CharType && (ta instanceof ByteType || ta instanceof ShortType))))
			continue;
		else if (soot.jimple.toolkits.typing.fast.AugHierarchy.ancestor_(
				ta, tb)) {
			if (r == -1)
				return 3;
			else
				r = 1;
		} else if (soot.jimple.toolkits.typing.fast.AugHierarchy.ancestor_(
				tb, ta)) {
			if (r == 1)
				return 3;
			else
				r = -1;
		} else
			return 3;
	}

	return r;
}
 
Example #10
Source File: ICCDummyMainCreator.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SootMethod generateDummyMainMethod(List<String> entryPoints, String sootClassName)
{
	List<String> androidClasses = new ArrayList<String>();
	androidClasses.add(sootClassName);
	
	SootMethod mainMethod = new SootMethod(DUMMY_MAIN_METHOD, 
			new ArrayList<Type>(), 
			VoidType.v(), 
			Modifier.PUBLIC);// | Modifier.STATIC);    //no need be static
	JimpleBody body = Jimple.v().newBody(mainMethod);
	mainMethod.setActiveBody(body);
	
	SootClass compSootClass = Scene.v().getSootClass(sootClassName);
	compSootClass.addMethod(mainMethod);
	
	//this is mandatory, the default dummyMainMethod is static, so they 
	//do not deal thisIdentity. since we don't need static dummyMainMethod, 
	//we should define it explicit
	body.insertIdentityStmts();
	
	Map<String, List<String>> callbackFunctions = new HashMap<String, List<String>>();
	callbackFunctions.put(sootClassName, getCallbackFunctions(compSootClass));
	
	AndroidEntryPointCreator androidEPCreator = new AndroidEntryPointCreator(androidClasses);	
	androidEPCreator.setCallbackFunctions(callbackFunctions);
	
	return androidEPCreator.createDummyMain(mainMethod);
}
 
Example #11
Source File: ConstraintChecker.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void check(Stmt stmt, JimpleBody stmtBody) throws TypeException {
	try {
		this.stmtBody = stmtBody;
		stmt.apply(this);
	} catch (RuntimeTypeException e) {
		StringWriter st = new StringWriter();
		PrintWriter pw = new PrintWriter(st);
		e.printStackTrace(pw);
		pw.close();
		throw new TypeException(st.toString());
	}
}
 
Example #12
Source File: TypeResolver.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public TypePromotionUseVisitor(JimpleBody jb, Typing tg)
{
	this.jb = jb;
	this.tg = tg;
	
	this.fail = false;
	this.typingChanged = false;
}
 
Example #13
Source File: TypeResolver.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public CastInsertionUseVisitor(boolean countOnly, JimpleBody jb,
	Typing tg, IHierarchy h)
{
	this.jb = jb;
	this.tg = tg;
	this.h = h;
	
	this.countOnly = countOnly;
	this.count = 0;
}
 
Example #14
Source File: TypeResolver.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public TypeResolver(JimpleBody jb)
{
	this.jb = jb;

	this.assignments = new ArrayList<DefinitionStmt>();
	this.depends = new HashMap<Local, BitSet>();
	for ( Local v : this.jb.getLocals() )
		this.addLocal(v);
	this.initAssignments();
}
 
Example #15
Source File: JimpleAST.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void stashBodiesForClass(SootClass sc) 
{          
    methodToParsedBodyMap = new HashMap<SootMethod, JimpleBody>();

    Walker w = new BodyExtractorWalker(sc, SootResolver.v(), methodToParsedBodyMap);

    boolean oldPhantomValue = Scene.v().getPhantomRefs();

    Scene.v().setPhantomRefs(true);
    mTree.apply(w);
    Scene.v().setPhantomRefs(oldPhantomValue);
}
 
Example #16
Source File: PointsToAnalysis.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private static Map/*<Integer,Local>*/ getLocals(SootClass sc, String methodname, String typename) {
	Map res = new HashMap();
	Iterator mi = sc.getMethods().iterator();
	while (mi.hasNext()) {
		SootMethod sm = (SootMethod)mi.next();
		System.err.println(sm.getName());
		if (true && sm.getName().equals(methodname) && sm.isConcrete()) {
			JimpleBody jb = (JimpleBody)sm.retrieveActiveBody();
			Iterator ui = jb.getUnits().iterator();
			while (ui.hasNext()) {
				Stmt s = (Stmt)ui.next();						
				int line = getLineNumber(s);
				// find definitions
				Iterator bi = s.getDefBoxes().iterator();
				while (bi.hasNext()) {
					Object o = bi.next();
					if (o instanceof ValueBox) {
						Value v = ((ValueBox)o).getValue();
						if (v.getType().toString().equals(typename) && v instanceof Local)
							res.put(new Integer(line),v);
					}
				}					
			}
		}
	}
	
	return res;
}
 
Example #17
Source File: CFGIntermediateRep.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Body getBody(JimpleBody b) { 
return Shimple.v().newJimpleBody(Shimple.v().newBody(b)); 
     }
 
Example #18
Source File: Mocker.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static SootMethod mockSootMethod(String clsName, String methodSubSignature, boolean isStatic)
{
	SootClass sc = mockSootClass(clsName);
	
	SootMethod sm = null;

	try
	{
		sm = sc.getMethod(methodSubSignature);
	}
	catch (Exception ex)
	{
		sm = null;
	}

	if (null == sm)
	{
		int m = Modifier.PUBLIC;
		if (isStatic)
		{
			m = m | Modifier.STATIC;
		}
		
		List<Type> paramTypes = new ArrayList<Type>();
		paramTypes.add(ArrayType.v(RefType.v("java.lang.Object"), 1));
		
		String[] strs = methodSubSignature.split(" ");
		String methodName = strs[1].trim().substring(0, strs[1].trim().indexOf("("));
		
		if (null == methodName || methodName.isEmpty())
		{
			return null;
		}
		
		sm = new SootMethod(methodName, paramTypes, RefType.v("java.lang.Object"), m);
		sc.addMethod(sm);
		
		//Add body of sm
		JimpleBody b = Jimple.v().newBody(sm);
        sm.setActiveBody(b);
        //LocalGenerator lg = new LocalGenerator(b);
		{
			b.insertIdentityStmts();
			
			
			
			//Local rtLoc = lg.generateLocal(RefType.v("java.lang.Object"));
			
			//Local param0 = lg.generateLocal(ArrayType.v(RefType.v("java.lang.Object"), 1));
			//Unit param0U = Jimple.v().newIdentityStmt(rtLoc, Jimple.v().newParameterRef(ArrayType.v(RefType.v("java.lang.Object"), 1), 0));
			
			
			//Unit rtLocAssignU = Jimple.v().newAssignStmt(rtLoc, param0);
			
			Unit returnU = Jimple.v().newReturnStmt(b.getParameterLocal(0));
			
			//b.getUnits().add(param0U);
			b.getUnits().add(returnU);
		}
		
		System.out.println("validation:" + b);
		b.validate();
	}	
	
	return sm;
}
 
Example #19
Source File: ICCRedirectionCreator.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod generateRedirectMethodForContentProvider(Stmt iccStmt, SootClass destProvider) {
    System.out.println("create method to call dest class: "+ destProvider);
    
    SootMethod iccMethod = iccStmt.getInvokeExpr().getMethod();
    
    String newSM_name = "redirector" + num++;
    List<Type> newSM_parameters = iccMethod.getParameterTypes();
    Type newSM_return_type = iccMethod.getReturnType();
    int modifiers = Modifier.STATIC | Modifier.PUBLIC;
            
    SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers);
    ipcSC.addMethod(newSM);
    JimpleBody b = Jimple.v().newBody(newSM);
    newSM.setActiveBody(b);
    
    LocalGenerator lg = new LocalGenerator(b);
    
    // all parameters
    List<Unit> units = new ArrayList<Unit>();
    List<Local> locals = new ArrayList<Local>();
    for (int i = 0; i < newSM_parameters.size(); i++)
    {
    	Type type = newSM_parameters.get(i);
    	Local local = lg.generateLocal(type);
    	Unit localU = Jimple.v().newIdentityStmt(local, Jimple.v().newParameterRef(type, i));
    	
    	locals.add(local);
    	units.add(localU);
    }
    
    // new
    Local al = lg.generateLocal(destProvider.getType());
    Unit newU = (Unit) Jimple.v().newAssignStmt(al, 
            Jimple.v().newNewExpr(destProvider.getType())
            );
    
    // init
    List<Type> parameters = new ArrayList<Type>();
    List<Value> args = new ArrayList<Value>();
    SootMethod method = destProvider.getMethod("<init>", parameters, VoidType.v());
    Unit initU = (Unit) Jimple.v().newInvokeStmt(
            Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args));
    
    Local rtLocal = lg.generateLocal(newSM_return_type);
    
    
    // call related method and assign the result to return local, may optimize it to dummyMain method as well
    parameters = iccMethod.getParameterTypes();
    method = destProvider.getMethodByName(iccMethod.getName());
       InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef(), locals);
       //Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke);
       Unit assignU = (Unit) Jimple.v().newAssignStmt(rtLocal, invoke);
       
       // return statement
       Unit returnU = (Unit) Jimple.v().newReturnStmt(rtLocal);
    
       for (Unit unit : units)
       {
       	b.getUnits().add(unit);
       }
    b.getUnits().add(newU);
    b.getUnits().add(initU);
    b.getUnits().add(assignU);
    b.getUnits().add(returnU);
    
    System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody());
    
    return newSM;
    
}
 
Example #20
Source File: CFGIntermediateRep.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Body getBody(JimpleBody b) { 
return Shimple.v().newBody(b); 
     }
 
Example #21
Source File: DummyMainGenerator.java    From DroidRA with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod generateMain(Set<String> components)
{
	SootMethod mainMethod = new SootMethod(DUMMY_METHOD_NAME, 
			Arrays.asList(new Type[] {ArrayType.v(RefType.v("java.lang.String"), 1)}), 
   			VoidType.v(), 
   			Modifier.PUBLIC | Modifier.STATIC);
   	JimpleBody body = Jimple.v().newBody(mainMethod);
   	mainMethod.setActiveBody(body);
   	
   	SootClass sootClass = new SootClass(DUMMY_CLASS_NAME);
   	sootClass.setSuperclass(Scene.v().getSootClass("java.lang.Object"));
   	sootClass.setPhantom(false);
   	sootClass.setApplicationClass();
   	sootClass.setInScene(true);
   	
   	sootClass.addMethod(mainMethod);
	
   	LocalGenerator generator = new LocalGenerator(body);
	
   	body.insertIdentityStmts();
   	
	for (String str : components)
	{
		SootClass sc = Scene.v().getSootClass(str);
		if (sc.isPhantom())
		{
			continue;
		}
		
		SootMethod method = ICCDummyMainCreator.v().generateDummyMainMethod(str);
		instrumentDummyMainMethod(method);
		
		SootClass cls = method.getDeclaringClass();
		SootMethod sootMethod = cls.getMethod("<init>", new ArrayList<Type>());
		
		if (null == sootMethod)
		{
			throw new RuntimeException("No default constructor for comp " + cls.getName());
		}
		
		Local al = generator.generateLocal(cls.getType());
		Unit newU = (Unit) Jimple.v().newAssignStmt(al, Jimple.v().newNewExpr(cls.getType()));
		
		Unit initU = (Unit) Jimple.v().newInvokeStmt(
				Jimple.v().newSpecialInvokeExpr(al, sootMethod.makeRef()));
		
		Unit callU = (Unit) Jimple.v().newInvokeStmt(
				Jimple.v().newSpecialInvokeExpr(al, method.makeRef()));
		
		body.getUnits().add(newU);
		body.getUnits().add(initU);
		body.getUnits().add(callU);
	}
	
	body.getUnits().add(Jimple.v().newReturnVoidStmt());
	
	if (fullMethodCover)
	{
		mainMethod = appendNonComponents(mainMethod);
	}
	
	System.out.println(body);
	
	body.validate();
	
	return mainMethod;
}
 
Example #22
Source File: JimpleReduceStaticFieldsTransformer.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void createNonParameterConstruct()
{
	for (String cls : classesContainStatic.keySet())
	{
		SootClass sc = Scene.v().getSootClass(cls);
		
		boolean noConstructMethod = true;
		boolean existNonParameterConstructMethod = false;
		
		List<SootMethod> methods = sc.getMethods();
		for (SootMethod sm : methods)
		{
			String methodName = sm.getName();
			
			if (methodName.equals("<init>"))
			{
				noConstructMethod = false;
				
				if (0 == sm.getParameterCount())
				{
					existNonParameterConstructMethod = true;
				}
			}
		}
		
		//Exist construct methods but all of them containing at least one parameter
		//So we need to create a default non parameter construct method for this class
		if (! noConstructMethod && !existNonParameterConstructMethod)
		{
			SootMethod npc = new SootMethod("<init>", 
	    			new ArrayList<Type>(), 
	    			VoidType.v(), 
	    			Modifier.PUBLIC);
	    	JimpleBody body = Jimple.v().newBody(npc);
	    	npc.setActiveBody(body);
	    	sc.addMethod(npc);
	    	
	    	{
	    		try
	    		{
	    			LocalGenerator lg = new LocalGenerator(body);
		            Local thisLocal = lg.generateLocal(sc.getType());
		            Unit thisU = Jimple.v().newIdentityStmt(thisLocal, 
		                    Jimple.v().newThisRef(sc.getType()));
		            body.getUnits().add(thisU);
		            
		            SootClass supperC = sc.getSuperclass();
		                       
		            InvokeExpr expr = Jimple.v().newSpecialInvokeExpr(thisLocal, supperC.getMethod("<init>", new ArrayList<Type>()).makeRef());
		            Unit specialCallU = Jimple.v().newInvokeStmt(expr);
		            body.getUnits().add(specialCallU);
		            
		            Unit returnVoidU = Jimple.v().newReturnVoidStmt();
		            body.getUnits().add(returnVoidU);
		            
		            System.out.println("Create non parameter construct method: " + body);
	    		}
	    		catch (Exception ex)
	    		{
	    			//couldn't find method <init>([]) in XXX.XXX
	    			//some supper classes do not have a <init>() construment methods
	    		}
	    		
	    	}
		}
	}
}
 
Example #23
Source File: ICCRedirectionCreator.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod generateRedirectMethodForStartActivityForResult(SootClass originActivity, SootClass destComp)
{
	String newSM_name = "redirector" + num++;
	
    List<Type> newSM_parameters = new ArrayList<Type>();
    newSM_parameters.add(originActivity.getType());
    newSM_parameters.add(INTENT_TYPE);
    Type newSM_return_type = VoidType.v();
    int modifiers = Modifier.STATIC | Modifier.PUBLIC;
            
    SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers);
    ipcSC.addMethod(newSM);
    JimpleBody b = Jimple.v().newBody(newSM);
    newSM.setActiveBody(b);
    
    LocalGenerator lg = new LocalGenerator(b);
	
    Local originActivityParameterLocal = lg.generateLocal(originActivity.getType());
    Unit originActivityParameterU = Jimple.v().newIdentityStmt(
    		originActivityParameterLocal, 
    		Jimple.v().newParameterRef(originActivity.getType(), 0));
    
    Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
    Unit intentParameterU = Jimple.v().newIdentityStmt(
            intentParameterLocal,
            Jimple.v().newParameterRef(INTENT_TYPE, 1));
    
    // new dest component
    Local destCompLocal = lg.generateLocal(destComp.getType());
    Unit newU = (Unit) Jimple.v().newAssignStmt(destCompLocal, 
            Jimple.v().newNewExpr(destComp.getType())
            );
    
    //call <init> method
    List<Type> parameters = new ArrayList<Type>();
    parameters.add(INTENT_TYPE);
    SootMethod method = destComp.getMethod("<init>", parameters, VoidType.v());
    List<Value> args = new ArrayList<Value>();
    args.add(intentParameterLocal);
    Unit initU = (Unit) Jimple.v().newInvokeStmt(
            Jimple.v().newSpecialInvokeExpr(destCompLocal, method.makeRef(), args));
    
    List<SootMethod> sms = destComp.getMethods();
    for (SootMethod sm : sms)
    {
    	System.out.println(sm);
    }
    
    // call onCreate
    method = destComp.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD);
    InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(destCompLocal, method.makeRef());
    Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke);
    
    
    //call sc.getIntentForActivityResult
    Local arIntentLocal = lg.generateLocal(INTENT_TYPE);
    Unit nullarIntentLocalParamU = (Unit) Jimple.v().newAssignStmt(
    		arIntentLocal, NullConstant.v());
    method = destComp.getMethodByName("getIntentForActivityResult");
    invoke = Jimple.v().newVirtualInvokeExpr(destCompLocal, method.makeRef());
    Unit destCompCallU = (Unit) Jimple.v().newAssignStmt(arIntentLocal, invoke);
    
    //some apps do not have an onActivityResult method even they use startActivityForResult to communicate with other components.
    try
    {
    	method = originActivity.getMethodByName("onActivityResult");
    }
    catch (Exception ex)
    {
    	method = generateFakeOnActivityResult(originActivity);
    }
    
    Local iLocal1 = lg.generateLocal(IntType.v());
    Local iLocal2 = lg.generateLocal(IntType.v());
    Unit defaultValueParamU1 = (Unit) Jimple.v().newAssignStmt(iLocal1, IntConstant.v(-1));
    Unit defaultValueParamU2 = (Unit) Jimple.v().newAssignStmt(iLocal2, IntConstant.v(-1));
    args = new ArrayList<Value>();
    args.add(iLocal1);
    args.add(iLocal2);
    args.add(arIntentLocal);
    invoke = Jimple.v().newVirtualInvokeExpr(originActivityParameterLocal, method.makeRef(), args);
    Unit onActivityResultCall = (Unit) Jimple.v().newInvokeStmt(invoke);
    
    b.getUnits().add(originActivityParameterU);
    b.getUnits().add(intentParameterU);
    b.getUnits().add(newU);
    b.getUnits().add(initU);
    //b.getUnits().add(nullParamU);
    b.getUnits().add(callU);
    b.getUnits().add(nullarIntentLocalParamU);
    b.getUnits().add(destCompCallU); 
    b.getUnits().add(defaultValueParamU1);
    b.getUnits().add(defaultValueParamU2);
    b.getUnits().add(onActivityResultCall);
    b.getUnits().add(Jimple.v().newReturnVoidStmt());
    
    System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody());
    
	return newSM;
}
 
Example #24
Source File: ICCRedirectionCreator.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod generateRedirectMethod(SootClass wrapper) {
    System.out.println("create method to call wrapper class: "+ wrapper);
    String newSM_name = "redirector" + num++;
    List<Type> newSM_parameters = new ArrayList<Type>();
    newSM_parameters.add(INTENT_TYPE);
    Type newSM_return_type = VoidType.v();
    int modifiers = Modifier.STATIC | Modifier.PUBLIC;
            
    SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers);
    ipcSC.addMethod(newSM);
    JimpleBody b = Jimple.v().newBody(newSM);
    newSM.setActiveBody(b);
    
    LocalGenerator lg = new LocalGenerator(b);
    
    // identity
    Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
    Unit intentParameterU = Jimple.v().newIdentityStmt(
            intentParameterLocal,
            Jimple.v().newParameterRef(INTENT_TYPE, 0));
    
    // new
    Local al = lg.generateLocal(wrapper.getType());
    Unit newU = (Unit) Jimple.v().newAssignStmt(al, 
            Jimple.v().newNewExpr(wrapper.getType())
            );
    // init
    List<Type> parameters = new ArrayList<Type>();
    parameters.add(INTENT_TYPE);
    SootMethod method = wrapper.getMethod("<init>", parameters, VoidType.v());
    List<Value> args = new ArrayList<Value>();
    args.add(intentParameterLocal);
    Unit initU = (Unit) Jimple.v().newInvokeStmt(
            Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args));
    
    // call dummyMainMethod
    method = wrapper.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD);
    //args = new ArrayList<Value>();
    //Local pLocal = lg.generateLocal(RefType.v("android.os.Bundle"));
    //Unit nullParamU = (Unit) Jimple.v().newAssignStmt(pLocal, NullConstant.v());
    //args.add(pLocal);
    InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef());
    Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke);
    
    b.getUnits().add(intentParameterU);
    b.getUnits().add(newU);
    b.getUnits().add(initU);
    //b.getUnits().add(nullParamU);
    b.getUnits().add(callU);
    b.getUnits().add(Jimple.v().newReturnVoidStmt());
    
    System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody());
    
    return newSM;
    
}
 
Example #25
Source File: ICCRedirectionCreator.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SootMethod generateRedirectMethodForStartActivity(SootClass wrapper) {
    System.out.println("create method to call wrapper class: "+ wrapper);
    String newSM_name = "redirector" + num++;
    List<Type> newSM_parameters = new ArrayList<Type>();
    newSM_parameters.add(INTENT_TYPE);
    Type newSM_return_type = VoidType.v();
    int modifiers = Modifier.STATIC | Modifier.PUBLIC;

    SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers);
    ipcSC.addMethod(newSM);
    JimpleBody b = Jimple.v().newBody(newSM);
    newSM.setActiveBody(b);

    LocalGenerator lg = new LocalGenerator(b);

    // identity
    Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
    Unit intentParameterU = Jimple.v().newIdentityStmt(
            intentParameterLocal,
            Jimple.v().newParameterRef(INTENT_TYPE, 0));

    // new
    Local al = lg.generateLocal(wrapper.getType());
    Unit newU = (Unit) Jimple.v().newAssignStmt(al,
            Jimple.v().newNewExpr(wrapper.getType())
            );
    // init
    List<Type> parameters = new ArrayList<Type>();
    parameters.add(INTENT_TYPE);
    SootMethod method = wrapper.getMethod("<init>", parameters, VoidType.v());
    List<Value> args = new ArrayList<Value>();
    args.add(intentParameterLocal);
    Unit initU = (Unit) Jimple.v().newInvokeStmt(
            Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args));

    // call dummyMainMethod
    //method = wrapper.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD);
    method = wrapper.getMethodByName("onCreate");
    args = new ArrayList<Value>();
    Local pLocal = lg.generateLocal(RefType.v("android.os.Bundle"));
    Unit nullParamU = (Unit) Jimple.v().newAssignStmt(pLocal, NullConstant.v());
    args.add(pLocal);
    InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef(), args);
    Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke);

    b.getUnits().add(intentParameterU);
    b.getUnits().add(newU);
    b.getUnits().add(initU);
    b.getUnits().add(nullParamU);
    b.getUnits().add(callU);
    b.getUnits().add(Jimple.v().newReturnVoidStmt());

    System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody());

    return newSM;

}
 
Example #26
Source File: CFGIntermediateRep.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Body getBody(JimpleBody b) { 
return Grimp.v().newBody(b, "gb"); 
     }
 
Example #27
Source File: CFGIntermediateRep.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Body getBody(JimpleBody b) { 
return Baf.v().newBody(b); 
     }
 
Example #28
Source File: CFGIntermediateRep.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public Body getBody(JimpleBody b) { 
return b; 
     }
 
Example #29
Source File: TypeAssigner.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/** Assign types to local variables. * */
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
	if (b == null) {
		throw new NullPointerException();
	}

	Date start = new Date();

	if (Options.v().verbose())
		G.v().out.println("[TypeAssigner] typing system started on "
				+ start);

	JBTROptions opt = new JBTROptions(options);
	
	ignoreWrongStaticNess = opt.ignore_wrong_staticness();
	
	/*
	 * Setting this guard to true enables comparison of the original and new
	 * type assigners. This will be slow since type assignment will always
	 * happen twice. The actual types used for Jimple are determined by the
	 * use-old-type-assigner option.
	 * 
	 * Each comparison is written as a separate semicolon-delimited line to
	 * the standard output, and the first field is always 'cmp' for use in
	 * grep. The format is:
	 * 
	 * cmp;Method Name;Stmt Count;Old Inference Time (ms); New Inference
	 * Time (ms);Typing Comparison
	 * 
	 * The Typing Comparison field compares the old and new typings: -2 -
	 * Old typing contains fewer variables (BAD!) -1 - Old typing is tighter
	 * (BAD!) 0 - Typings are equal 1 - New typing is tighter 2 - New typing
	 * contains fewer variables 3 - Typings are incomparable (inspect
	 * manually)
	 * 
	 * In a final release this guard, and anything in the first branch,
	 * would probably be removed.
	 */
	if (opt.compare_type_assigners()) {
		compareTypeAssigners(b,opt.use_older_type_assigner());
	} else {
		if (opt.use_older_type_assigner())
			TypeResolver.resolve((JimpleBody) b, Scene.v());
		else
			(new soot.jimple.toolkits.typing.fast.TypeResolver(
					(JimpleBody) b)).inferTypes();
	}

	Date finish = new Date();
	if (Options.v().verbose()) {
		long runtime = finish.getTime() - start.getTime();
		long mins = runtime / 60000;
		long secs = (runtime % 60000) / 1000;
		G.v().out.println("[TypeAssigner] typing system ended. It took "
				+ mins + " mins and " + secs + " secs.");
	}
	
	replaceNullType(b);

	if (typingFailed((JimpleBody) b))
		throw new RuntimeException("type inference failed!");
}
 
Example #30
Source File: ConstraintCollector.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public void collect(Stmt stmt, JimpleBody stmtBody) {
	this.stmtBody = stmtBody;
	stmt.apply(this);
}