soot.jimple.IntConstant Java Examples

The following examples show how to use soot.jimple.IntConstant. 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: TimingBombTransformer.java    From FuzzDroid with Apache License 2.0 7 votes vote down vote up
private void prepareAlarmManagerSet(Body body, InvokeStmt setStmt, SootMethodRef reportRef) {
	Value oldVal = setStmt.getInvokeExpr().getArg(1);
	
	Local longLocal = UtilInstrumenter.generateFreshLocal(body, LongType.v());
	SootMethod currentTimeMillis = Scene.v().getMethod("<java.lang.System: long currentTimeMillis()>");		
	StaticInvokeExpr timeInvoke = Jimple.v().newStaticInvokeExpr(currentTimeMillis.makeRef());		
	AssignStmt timeInitalize = Jimple.v().newAssignStmt(longLocal, timeInvoke);
	
	AddExpr addTime = Jimple.v().newAddExpr(longLocal, LongConstant.v(2000L));
	AssignStmt timeAssign = Jimple.v().newAssignStmt(longLocal, addTime);
			
	
	body.getUnits().insertBefore(timeInitalize, setStmt);
	body.getUnits().insertBefore(timeAssign, setStmt);
	
	InvokeExpr expr = setStmt.getInvokeExpr();
	expr.setArg(0, IntConstant.v(0));
	expr.setArg(1, longLocal);
	
	// Report the change
	InvokeStmt reportStmt = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(
			reportRef, oldVal, longLocal));
	reportStmt.addTag(new InstrumentedCodeTag());
	body.getUnits().insertAfter(reportStmt, setStmt);
}
 
Example #2
Source File: SparseSwitchInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected Stmt switchStatement(DexBody body, Instruction targetData, Local key) {
     SparseSwitchPayload i = (SparseSwitchPayload) targetData;
     List<? extends SwitchElement> seList = i.getSwitchElements();

     // the default target always follows the switch statement
     int defaultTargetAddress = codeAddress + instruction.getCodeUnits();
     Unit defaultTarget = body.instructionAtAddress(defaultTargetAddress).getUnit();

     List<IntConstant> lookupValues = new ArrayList<IntConstant>();
     List<Unit> targets = new ArrayList<Unit>();
     for(SwitchElement se: seList) {
       lookupValues.add(IntConstant.v(se.getKey()));
       int offset = se.getOffset();
       targets.add(body.instructionAtAddress(codeAddress + offset).getUnit());
     }
     switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
     setUnit(switchStmt);
     
     if (IDalvikTyper.ENABLE_DVKTYPER) {
Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ switchStmt);
         DalvikTyper.v().setType(switchStmt.getKeyBox(), IntType.v(), true);
     }
     
     return switchStmt;
 }
 
Example #3
Source File: AbstractBoomerangTest.java    From SPDS with Eclipse Public License 2.0 6 votes vote down vote up
public Optional<? extends Query> test(Stmt stmt) {
    if (stmt instanceof AssignStmt) {
        AssignStmt as = (AssignStmt) stmt;
        if (as.getLeftOp().toString().equals("allocation")) {
            Statement statement = new Statement(stmt, staticIcfg.getMethodOf(stmt));
            if (as.getLeftOp() instanceof Local && as.getRightOp() instanceof IntConstant) {
                Local local = (Local) as.getLeftOp();
                ForwardQuery forwardQuery = new ForwardQuery(statement,
                        new AllocVal(local, staticIcfg.getMethodOf(stmt), as.getRightOp(),
                                new Statement(as, staticIcfg.getMethodOf(stmt))));
                return Optional.<Query> of(forwardQuery);
            }

            if (as.containsInvokeExpr()) {
                AtomicReference<Query> returnValue = new AtomicReference<>();
                staticIcfg.addCalleeListener(
                        new IntegerAllocationSiteCalleeListener(returnValue, as, statement, stmt));
                if (returnValue.get() != null) {
                    return Optional.of(returnValue.get());
                }
            }
        }
    }

    return Optional.empty();
}
 
Example #4
Source File: BaseEntryPointCreator.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected Value getSimpleDefaultValue(String t) {
	if (t.equals("java.lang.String"))
		return StringConstant.v("");
	if (t.equals("char"))
		return DIntConstant.v(0, CharType.v());
	if (t.equals("byte"))
		return DIntConstant.v(0, ByteType.v());
	if (t.equals("short"))
		return DIntConstant.v(0, ShortType.v());
	if (t.equals("int"))
		return IntConstant.v(0);
	if (t.equals("float"))
		return FloatConstant.v(0);
	if (t.equals("long"))
		return LongConstant.v(0);
	if (t.equals("double"))
		return DoubleConstant.v(0);
	if (t.equals("boolean"))
		return DIntConstant.v(0, BooleanType.v());

	//also for arrays etc.
	return G.v().soot_jimple_NullConstant();
}
 
Example #5
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Ignore("Fails")
@Test
public void testJReturnStmt() {
    Stmt s = Jimple.v().newReturnStmt(IntConstant.v(1));

    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));

    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #6
Source File: PointsToAnalysis.java    From vasco with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a points-to graph with the locals of main initialised to
 * <tt>null</tt>, except the command-line arguments which are
 * initialised to an array of strings.
 */
@Override
public PointsToGraph boundaryValue(SootMethod entryPoint) {
	// For now we only support entry to the main method
	assert(entryPoint == Scene.v().getMainMethod());
	
	// Ok, start setting up entry value
	PointsToGraph entryValue = new PointsToGraph();		

	// Locals of main... (only reference types)
	SootMethod mainMethod = Scene.v().getMainMethod();
	for (Local local : mainMethod.getActiveBody().getLocals()) {
		if (local.getType() instanceof RefLikeType) {
			entryValue.assign(local, null);
		}
	}		
	
	// Command-line arguments to main...
	Local argsLocal = mainMethod.getActiveBody().getParameterLocal(0);
	NewArrayExpr argsExpr = new JNewArrayExpr(Scene.v().getRefType("java.lang.String"), IntConstant.v(0));
	entryValue.assignNew(argsLocal, argsExpr);
	entryValue.setFieldConstant(argsLocal, PointsToGraph.ARRAY_FIELD, PointsToGraph.STRING_CONST);
	

	return entryValue;
}
 
Example #7
Source File: PolicyEnforcementPoint.java    From DroidForce with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 
 * @param parameter
 * @param body
 * @return
 */
private Pair<Value, List<Unit>> generateParameterArray(List<Value> parameter, Body body){
	List<Unit> generated = new ArrayList<Unit>();
	
	NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(RefType.v("java.lang.Object"), IntConstant.v(parameter.size()));
	
	Value newArrayLocal = generateFreshLocal(body, getParameterArrayType());
	Unit newAssignStmt = Jimple.v().newAssignStmt(newArrayLocal, arrayExpr);
	generated.add(newAssignStmt);
	
	for(int i = 0; i < parameter.size(); i++){
		Value index = IntConstant.v(i);
		ArrayRef leftSide = Jimple.v().newArrayRef(newArrayLocal, index);
		Value rightSide = generateCorrectObject(body, parameter.get(i), generated);
		
		Unit parameterInArray = Jimple.v().newAssignStmt(leftSide, rightSide);
		generated.add(parameterInArray);
	}
	
	return new Pair<Value, List<Unit>>(newArrayLocal, generated);
}
 
Example #8
Source File: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
private boolean hasConstantIndexAtArrayForSplitDataFlow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		Value value = ass.getRightOp();
		if(value instanceof ArrayRef) {
			ArrayRef aRef = (ArrayRef)value;
			Value index = aRef.getIndex();
			
			if(index instanceof IntConstant)
				return true;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return false;
}
 
Example #9
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testJArrayRef() {
    ArrayRef arrayRef = Jimple.v().newArrayRef(
            Jimple.v().newLocal("local1",
                ArrayType.v(RefType.v("java.lang.Object"), 1)), 
            IntConstant.v(0));

    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(arrayRef)));

    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, 
            utility.catchableSubset(unitAnalysis.mightThrow(arrayRef)));
}
 
Example #10
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGArrayRef() {
    ArrayRef arrayRef = Grimp.v().newArrayRef(
            Grimp.v().newLocal("local1",
                ArrayType.v(RefType.v("java.lang.Object"), 1)), 
            IntConstant.v(0));

    Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
    expectedRep.add(utility.NULL_POINTER_EXCEPTION);
    expectedRep.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(arrayRef)));

    Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
    expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
    expectedCatch.add(utility.ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.INDEX_OUT_OF_BOUNDS_EXCEPTION);
    expectedCatch.add(utility.RUNTIME_EXCEPTION);
    expectedCatch.add(utility.EXCEPTION);
    assertEquals(expectedCatch, 
            utility.catchableSubset(unitAnalysis.mightThrow(arrayRef)));
}
 
Example #11
Source File: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
private int getConstantArrayIndexForSplitDataFlow(Stmt[] dataflow) {
	Stmt firstAssign = dataflow[0];
	if(firstAssign instanceof AssignStmt) {
		AssignStmt ass = (AssignStmt)firstAssign;
		Value value = ass.getRightOp();
		if(value instanceof ArrayRef) {
			ArrayRef aRef = (ArrayRef)value;
			Value index = aRef.getIndex();
			
			if(index instanceof IntConstant)
				return ((IntConstant) index).value;
		}
	}
	else
		throw new RuntimeException("this should not happen - wrong assumption");
	
	return -1;
}
 
Example #12
Source File: BaseEntryPointCreator.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs an array of the given type with a single element of this type
 * in the given method
 * @param body The body of the method in which to create the array
 * @param gen The local generator
 * @param tp The type of which to create the array
 * @param constructionStack Set of classes currently being built to avoid
 * constructor loops
 * @param parentClasses If a requested type is compatible with one of the
 * types in this list, the already-created object is used instead of
 * creating a new one.
 * @return The local referencing the newly created array, or null if the
 * array generation failed
 */
private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp,
		Set<SootClass> constructionStack, Set<SootClass> parentClasses) {
	Local local = gen.generateLocal(tp);

	// Generate a new single-element array
	NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(),
			IntConstant.v(1));
	AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr);
	body.getUnits().add(assignArray);
	
	// Generate a single element in the array
	AssignStmt assign = Jimple.v().newAssignStmt
			(Jimple.v().newArrayRef(local, IntConstant.v(0)),
			getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses));
	body.getUnits().add(assign);
	return local;
}
 
Example #13
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGLookupSwitchStmt() {
    Stmt target = Grimp.v().newAssignStmt(Grimp.v().newLocal("local0",
                IntType.v()),
            IntConstant.v(0));
    Stmt s = Grimp.v().newLookupSwitchStmt(IntConstant.v(1),
            Arrays.asList(new Value[] {
                IntConstant.v(1)
            }),
            Arrays.asList(new Unit[] {
                target
            }),
            target);
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(s)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES, 
            utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
 
Example #14
Source File: Walker.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void outAIntegerConstant(AIntegerConstant node)
   {
String s = (String) mProductions.removeLast();
       
       StringBuffer buf = new StringBuffer();
       if(node.getMinus() != null)
           buf.append('-');
       buf.append(s);
       
       s = buf.toString();
       if(s.endsWith("L")) {                        
    mProductions.addLast(LongConstant.v(Long.parseLong(s.substring(0, s.length()-1))));
       } 
       else if (s.equals("2147483648"))
    mProductions.addLast(IntConstant.v(Integer.MIN_VALUE));
       else
    mProductions.addLast(IntConstant.v(Integer.parseInt(s)));
   }
 
Example #15
Source File: UnitThrowAnalysis.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void caseBinopDivExpr(BinopExpr expr) {
    // Factors out code common to caseDivExpr and caseRemExpr.
    // The checks against constant divisors would perhaps be
    // better performed in a later pass, post-constant-propagation.
    Value divisor = expr.getOp2();
    Type divisorType = divisor.getType();
    if (divisorType instanceof UnknownType) {
	result = result.add(mgr.ARITHMETIC_EXCEPTION);
    } else if ((divisorType instanceof IntegerType) &&
	((! (divisor instanceof IntConstant)) ||
	 (((IntConstant) divisor).equals(INT_CONSTANT_ZERO)))) {
	result = result.add(mgr.ARITHMETIC_EXCEPTION);
    } else if ((divisorType == LongType.v()) &&
	       ((! (divisor instanceof LongConstant)) ||
		(((LongConstant) divisor).equals(LONG_CONSTANT_ZERO)))) {
	result = result.add(mgr.ARITHMETIC_EXCEPTION);
    }
    caseBinopExpr(expr);
}
 
Example #16
Source File: DummyMainGenerator.java    From DroidRA with GNU Lesser General Public License v2.1 6 votes vote down vote up
public SootMethod generateFuzzyMethod(SootClass sootClass)
{
   	String name = "fuzzyMe";
    List<Type> parameters = new ArrayList<Type>();
    Type returnType = IntType.v();
    int modifiers = Modifier.PUBLIC;
    SootMethod fuzzyMeMethod = new SootMethod(name, parameters, returnType, modifiers);
    sootClass.addMethod(fuzzyMeMethod);
    
    {
    	Body b = Jimple.v().newBody(fuzzyMeMethod);
    	fuzzyMeMethod.setActiveBody(b);
    	LocalGenerator lg = new LocalGenerator(b);
        Local thisLocal = lg.generateLocal(sootClass.getType());
        Unit thisU = Jimple.v().newIdentityStmt(thisLocal, 
                Jimple.v().newThisRef(sootClass.getType()));
        Unit returnU = Jimple.v().newReturnStmt(IntConstant.v(1));
        b.getUnits().add(thisU);
        b.getUnits().add(returnU);
    }
        
    return fuzzyMeMethod;
}
 
Example #17
Source File: StmtVisitor.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
       exprV.setOrigStmt(stmt);
       constantV.setOrigStmt(stmt);
	// create payload that references the switch's targets
	List<IntConstant> keyValues = stmt.getLookupValues();
	int[] keys = new int[keyValues.size()];
	for (int i = 0; i < keys.length; i++) {
		keys[i] = keyValues.get(i).value;
	}
	List<Unit> targets = stmt.getTargets();
	SparseSwitchPayload payload = new SparseSwitchPayload(keys, targets);
	switchPayloads.add(payload);
	// create sparse-switch instruction that references the payload
	Value key = stmt.getKey();
	Stmt defaultTarget = (Stmt) stmt.getDefaultTarget();
	if (defaultTarget == stmt)
		throw new RuntimeException("Looping switch block detected");
       addInsn(buildSwitchInsn(Opcode.SPARSE_SWITCH, key, defaultTarget,
       		payload, stmt), stmt);
}
 
Example #18
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private Value toSootValue(Object val) throws AssertionError {
	Value v;
	if (val instanceof Integer)
		v = IntConstant.v((Integer) val);
	else if (val instanceof Float)
		v = FloatConstant.v((Float) val);
	else if (val instanceof Long)
		v = LongConstant.v((Long) val);
	else if (val instanceof Double)
		v = DoubleConstant.v((Double) val);
	else if (val instanceof String)
		v = StringConstant.v(val.toString());
	else if (val instanceof org.objectweb.asm.Type)
		v = ClassConstant.v(((org.objectweb.asm.Type) val).getInternalName());
	else if (val instanceof Handle)
		v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle)val).getTag());
	else
		throw new AssertionError("Unknown constant type: " + val.getClass());
	return v;
}
 
Example #19
Source File: DexNumTransformer.java    From JAADAS with GNU General Public License v3.0 6 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> getNumCandidates(Body body) {
	Set<Local> candidates = new HashSet<Local>();
	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 || r instanceof LongConstant)) {
				candidates.add(l);
				Debug.printDbg("[add null candidate: ", u);
			}
		}
	}

	return candidates;
}
 
Example #20
Source File: CPHelper.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public static Value createConstant(Object toConvert){
	if(toConvert instanceof Long){
		return LongConstant.v( ((Long)toConvert).longValue() );
	}
	else if(toConvert instanceof Double){
		return DoubleConstant.v( ((Double)toConvert).doubleValue());
	}
	else if(toConvert instanceof Boolean){
		boolean val = ((Boolean)toConvert).booleanValue();
		if(val)
			return DIntConstant.v(1,BooleanType.v());
		else
			return DIntConstant.v(0,BooleanType.v());
	}	
	else if(toConvert instanceof Float){
		return FloatConstant.v( ((Float)toConvert).floatValue());
	}
	else if(toConvert instanceof Integer){
		return IntConstant.v( ((Integer)toConvert).intValue());
	}
	else
		return null;
}
 
Example #21
Source File: ICCInstrumentDestination.java    From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 6 votes vote down vote up
public SootMethod generateFuzzyMethod(SootClass sootClass)
{
   	String name = "fuzzyMe";
    List<Type> parameters = new ArrayList<Type>();
    Type returnType = IntType.v();
    int modifiers = Modifier.PUBLIC;
    SootMethod fuzzyMeMethod = new SootMethod(name, parameters, returnType, modifiers);
    sootClass.addMethod(fuzzyMeMethod);
    
    {
    	Body b = Jimple.v().newBody(fuzzyMeMethod);
    	fuzzyMeMethod.setActiveBody(b);
    	LocalGenerator lg = new LocalGenerator(b);
        Local thisLocal = lg.generateLocal(sootClass.getType());
        Unit thisU = Jimple.v().newIdentityStmt(thisLocal, 
                Jimple.v().newThisRef(sootClass.getType()));
        Unit returnU = Jimple.v().newReturnStmt(IntConstant.v(1));
        b.getUnits().add(thisU);
        b.getUnits().add(returnU);
    }
        
    return fuzzyMeMethod;
}
 
Example #22
Source File: CPHelper.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public static Object isAConstantValue(Value toCheck){
	Object value=null;
	
	if(toCheck instanceof LongConstant){
		value = new Long(((LongConstant)toCheck).value);
	}
	else if(toCheck instanceof DoubleConstant){
		value = new Double(((DoubleConstant)toCheck).value);
	}
	else if(toCheck instanceof FloatConstant){
		value = new Float(((FloatConstant)toCheck).value);
	}
	else if(toCheck instanceof IntConstant){
		int val = ((IntConstant)toCheck).value;
		value = new Integer(val);			
	}
	return value;
}
 
Example #23
Source File: DexNullThrowTransformer.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
	LocalCreation lc = new LocalCreation(b.getLocals(), "ex");
	
	for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext(); ) {
		Unit u = unitIt.next();
		
		// Check for a null exception
		if (u instanceof ThrowStmt) {
			ThrowStmt throwStmt = (ThrowStmt) u;
			if (throwStmt.getOp() == NullConstant.v()
					|| throwStmt.getOp().equals(IntConstant.v(0))
					|| throwStmt.getOp().equals(LongConstant.v(0))) {
				createThrowStmt(b, throwStmt, lc);
			}
		}
	}
}
 
Example #24
Source File: PackedSwitchInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected Stmt switchStatement(DexBody body, Instruction targetData, Local key) {
     PackedSwitchPayload i = (PackedSwitchPayload) targetData;
     List<? extends SwitchElement> seList = i.getSwitchElements();

     // the default target always follows the switch statement
     int defaultTargetAddress = codeAddress + instruction.getCodeUnits();
     Unit defaultTarget = body.instructionAtAddress(defaultTargetAddress).getUnit();

     List<IntConstant> lookupValues = new ArrayList<IntConstant>();
     List<Unit> targets = new ArrayList<Unit>();
     for(SwitchElement se: seList) {
       lookupValues.add(IntConstant.v(se.getKey()));
       int offset = se.getOffset();
       targets.add(body.instructionAtAddress(codeAddress + offset).getUnit());
     }
     switchStmt = Jimple.v().newLookupSwitchStmt(key, lookupValues, targets, defaultTarget);
     setUnit(switchStmt);
     
     if (IDalvikTyper.ENABLE_DVKTYPER) {
Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ switchStmt);
         DalvikTyper.v().setType(switchStmt.getKeyBox(), IntType.v(), true);
     }
     
     return switchStmt;
 }
 
Example #25
Source File: UtilInstrumenter.java    From FuzzDroid with Apache License 2.0 6 votes vote down vote up
public static Pair<Value, List<Unit>> generateParameterArray(List<Value> parameterList, Body body){
	List<Unit> generated = new ArrayList<Unit>();
	
	NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(RefType.v("java.lang.Object"), IntConstant.v(parameterList.size()));
	
	Value newArrayLocal = generateFreshLocal(body, getParameterArrayType());
	Unit newAssignStmt = Jimple.v().newAssignStmt(newArrayLocal, arrayExpr);
	generated.add(newAssignStmt);
	
	for(int i = 0; i < parameterList.size(); i++){
		Value index = IntConstant.v(i);
		ArrayRef leftSide = Jimple.v().newArrayRef(newArrayLocal, index);
		Value rightSide = generateCorrectObject(body, parameterList.get(i), generated);
		
		Unit parameterInArray = Jimple.v().newAssignStmt(leftSide, rightSide);
		generated.add(parameterInArray);
	}
	
	return new Pair<Value, List<Unit>>(newArrayLocal, generated);
}
 
Example #26
Source File: UnitThrowAnalysisTest.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testJBinOpExp() {
    Value v = Jimple.v().newAddExpr(IntConstant.v(456), 
            Jimple.v().newLocal("local", IntType.v()));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES,
            utility.catchableSubset(unitAnalysis.mightThrow(v)));

    v = Jimple.v().newOrExpr(Jimple.v().newLocal("local", LongType.v()),
            LongConstant.v(33));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES,
            utility.catchableSubset(unitAnalysis.mightThrow(v)));

    v = Jimple.v().newLeExpr(Jimple.v().newLocal("local", FloatType.v()),
            FloatConstant.v(33.42f));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES,
            utility.catchableSubset(unitAnalysis.mightThrow(v)));

    v = Jimple.v().newEqExpr(DoubleConstant.v(-33.45e-3),
            Jimple.v().newLocal("local", DoubleType.v()));
    assertTrue(ExceptionTestUtility.sameMembers(utility.VM_ERRORS, Collections.EMPTY_SET,
                unitAnalysis.mightThrow(v)));
    assertEquals(utility.VM_ERRORS_PLUS_SUPERTYPES,
            utility.catchableSubset(unitAnalysis.mightThrow(v)));
}
 
Example #27
Source File: IntValueAnalysis.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the possible values for an integer variable.
 * 
 * @param value The variable whose value we are looking for.
 * @param start The statement where the variable is used.
 * @return The set of possible values for the variable.
 */
@Override
public Set<Object> computeVariableValues(Value value, Stmt start) {
  if (value instanceof IntConstant) {
    return Collections.singleton((Object) ((IntConstant) value).value);
  } else if (value instanceof LongConstant) {
    return Collections.singleton((Object) ((LongConstant) value).value);
  } else if (value instanceof Local) {
    return findIntAssignmentsForLocal(start, (Local) value, new HashSet<Stmt>());
  } else {
    return Collections.singleton((Object) TOP_VALUE);
  }
}
 
Example #28
Source File: InstrumentationUtils.java    From DroidRA with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Value toDefaultSootTypeValue(Type sootType)
{
	String type = sootType.toString();
	
	if ("boolean".equals(type))
	{
		IntConstant.v(0);
	}
	else if ("byte".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("char".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("short".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("int".equals(type))
	{
		return IntConstant.v(0);
	}
	else if ("long".equals(type))
	{
		return LongConstant.v(0);
	}
	else if ("float".equals(type))
	{
		return FloatConstant.v(0);
	}
	else if ("double".equals(type))
	{
		return DoubleConstant.v(0);
	}

	return NullConstant.v();
}
 
Example #29
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertIincInsn(IincInsnNode insn) {
	Local local = getLocal(insn.var);
	assignReadOps(local);
	if (!units.containsKey(insn)) {
		AddExpr add = Jimple.v().newAddExpr(local, IntConstant.v(insn.incr));
		setUnit(insn, Jimple.v().newAssignStmt(local, add));
	}
}
 
Example #30
Source File: ShortcutArrayInit.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public boolean isInSequenceAssignment(Stmt s, Value leftOp, int index){
	//DEBUG=false;
	if(!(s instanceof DefinitionStmt))
		return false;
	
	DefinitionStmt ds = (DefinitionStmt)s;
	Value leftValue = ds.getLeftOp();
	if(! (leftValue instanceof ArrayRef))
		return false;
	
	if(DEBUG){
		System.out.println("Stmt number "+index + " is an array ref assignment"+leftValue);
		System.out.println("Array is"+leftOp);
	}

	ArrayRef leftRef = (ArrayRef)leftValue;
	if(! (leftOp.equals(leftRef.getBase()))){
		if(DEBUG)
			System.out.println("Not assigning to same array");
		return false;
	}
		
	if( ! (leftRef.getIndex() instanceof IntConstant)){
		if(DEBUG)
			System.out.println("Cant determine index of assignment");
		return false;
	}
	
	IntConstant leftIndex = (IntConstant)leftRef.getIndex();
	if(leftIndex.value != index){
		if(DEBUG)
			System.out.println("Out of order assignment");
		return false;
	}
	
	return true;
}