soot.jimple.LongConstant Java Examples

The following examples show how to use soot.jimple.LongConstant. 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 Project: FuzzDroid   Author: srasthofer   File: TimingBombTransformer.java    License: 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 Project: JAADAS   Author: flankerhqd   File: BaseEntryPointCreator.java    License: 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 #3
Source Project: JAADAS   Author: flankerhqd   File: FixUndefinedLocals.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static PushInst getPushInitializer(Local l, Type t) {
  if (t instanceof IntegerType) {
    return Baf.v().newPushInst(IntConstant.v(soot.jbco.util.Rand.getInt()));
  } else if (t instanceof RefLikeType || t instanceof StmtAddressType) {
    return Baf.v().newPushInst(NullConstant.v());
  } else if (t instanceof LongType) {
    return Baf.v().newPushInst(LongConstant.v(soot.jbco.util.Rand.getLong()));
  } else if (t instanceof FloatType) {
    return Baf.v().newPushInst(
        FloatConstant.v(soot.jbco.util.Rand.getFloat()));
  } else if (t instanceof DoubleType) {
    return Baf.v().newPushInst(
        DoubleConstant.v(soot.jbco.util.Rand.getDouble()));
  }
  
  return null;
}
 
Example #4
Source Project: JAADAS   Author: flankerhqd   File: Walker.java    License: 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 #5
Source Project: JAADAS   Author: flankerhqd   File: DexNumTransformer.java    License: 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 #6
Source Project: JAADAS   Author: flankerhqd   File: DexNullThrowTransformer.java    License: 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 #7
Source Project: JAADAS   Author: flankerhqd   File: CPHelper.java    License: 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 #8
Source Project: JAADAS   Author: flankerhqd   File: CPHelper.java    License: 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 #9
Source Project: JAADAS   Author: flankerhqd   File: AsmMethodSource.java    License: 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 #10
Source Project: JAADAS   Author: flankerhqd   File: UnitThrowAnalysis.java    License: 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 #11
Source Project: FuzzDroid   Author: srasthofer   File: TimingBombTransformer.java    License: Apache License 2.0 5 votes vote down vote up
private void prepareHandlerPostDelayed(Body body, Stmt invokeStmt, SootMethodRef reportRef) {
	InvokeExpr expr = invokeStmt.getInvokeExpr();
	
	Value oldValue = expr.getArg(1);
	Value newValue = LongConstant.v(2000L);
	
	expr.setArg(1, newValue);

	// Report the change
	InvokeStmt reportStmt = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(
			reportRef, oldValue, newValue));
	reportStmt.addTag(new InstrumentedCodeTag());
	body.getUnits().insertAfter(reportStmt, invokeStmt);
}
 
Example #12
Source Project: JAADAS   Author: flankerhqd   File: Walker.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void outAConstantCaseLabel(AConstantCaseLabel node)
   {
String s = (String) mProductions.removeLast();
       int sign = 1;
       if(node.getMinus() != null)
           sign = -1;
      
       if(s.endsWith("L")) {            
    mProductions.addLast(LongConstant.v(sign * Long.parseLong(s.substring(0, s.length()-1))));
       }
       else if (s.equals("2147483648"))
    mProductions.addLast(IntConstant.v(sign * Integer.MIN_VALUE));
       else
    mProductions.addLast(IntConstant.v(sign * Integer.parseInt(s)));
   }
 
Example #13
Source Project: JAADAS   Author: flankerhqd   File: AbstractNullTransformer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Examine expr if it is a comparison with 0.
 *
 * @param expr
 *            the ConditionExpr to examine
 */
protected boolean isZeroComparison(ConditionExpr expr) {
	if (expr instanceof EqExpr || expr instanceof NeExpr) {
		if (expr.getOp2() instanceof IntConstant
				&& ((IntConstant) expr.getOp2()).value == 0)
			return true;
		if (expr.getOp2() instanceof LongConstant
				&& ((LongConstant) expr.getOp2()).value == 0)
			return true;
	}
	return false;
}
 
Example #14
Source Project: JAADAS   Author: flankerhqd   File: DexNullTransformer.java    License: GNU General Public License v3.0 5 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> getNullCandidates(Body body) {
	Set<Local> candidates = null;
	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 && ((IntConstant) r).value == 0)
					|| (r instanceof LongConstant && ((LongConstant) r).value == 0)) {
				if (candidates == null)
					candidates = new HashSet<Local>();
				candidates.add(l);
				Debug.printDbg("[add null candidate: ", u);
			}
		} else if (u instanceof IfStmt) {
			ConditionExpr expr = (ConditionExpr) ((IfStmt) u)
					.getCondition();
			if (isZeroComparison(expr) && expr.getOp1() instanceof Local) {
				if (candidates == null)
					candidates = new HashSet<Local>();
				candidates.add((Local) expr.getOp1());
				Debug.printDbg("[add null candidate if: ", u);
			}
		}
	}

	return candidates == null ? Collections.<Local>emptySet() : candidates;
}
 
Example #15
Source Project: JAADAS   Author: flankerhqd   File: AsmMethodSource.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void convertConstInsn(InsnNode insn) {
	int op = insn.getOpcode();
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Value v;
		if (op == ACONST_NULL)
			v = NullConstant.v();
		else if (op >= ICONST_M1 && op <= ICONST_5)
			v = IntConstant.v(op - ICONST_0);
		else if (op == LCONST_0 || op == LCONST_1)
			v = LongConstant.v(op - LCONST_0);
		else if (op >= FCONST_0 && op <= FCONST_2)
			v = FloatConstant.v(op - FCONST_0);
		else if (op == DCONST_0 || op == DCONST_1)
			v = DoubleConstant.v(op - DCONST_0);
		else
			throw new AssertionError("Unknown constant opcode: " + op);
		opr = new Operand(insn, v);
		frame.out(opr);
	} else {
		opr = out[0];
	}
	if (op == LCONST_0 || op == LCONST_1 ||
			op == DCONST_0 || op == DCONST_1) {
		pushDual(opr);
	} else {
		push(opr);
	}
}
 
Example #16
Source Project: JAADAS   Author: flankerhqd   File: ConstantInitializerToTagTransformer.java    License: GNU General Public License v3.0 5 votes vote down vote up
private ConstantValueTag createConstantTagFromValue(Constant rightOp) {
	if (rightOp instanceof DoubleConstant)
		return new DoubleConstantValueTag(((DoubleConstant) rightOp).value);
	else if (rightOp instanceof FloatConstant)
		return new FloatConstantValueTag(((FloatConstant) rightOp).value);
	else if (rightOp instanceof IntConstant)
		return new IntegerConstantValueTag(((IntConstant) rightOp).value);
	else if (rightOp instanceof LongConstant)
		return new LongConstantValueTag(((LongConstant) rightOp).value);
	else if (rightOp instanceof StringConstant)
		return new StringConstantValueTag(((StringConstant) rightOp).value);
	else
		return null;
}
 
Example #17
Source Project: JAADAS   Author: flankerhqd   File: ConstantInitializerToTagTransformer.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean checkConstantValue(ConstantValueTag t, Constant rightOp) {
	if (t == null || rightOp == null)
		return true;
	
	if (t instanceof DoubleConstantValueTag) {
		if (!(rightOp instanceof DoubleConstant))
			return false;
		return ((DoubleConstantValueTag) t).getDoubleValue() == ((DoubleConstant) rightOp).value;
	}
	else if (t instanceof FloatConstantValueTag) {
		if (!(rightOp instanceof FloatConstant))
			return false;
		return ((FloatConstantValueTag) t).getFloatValue() == ((FloatConstant) rightOp).value;
	}
	else if (t instanceof IntegerConstantValueTag) {
		if (!(rightOp instanceof IntConstant))
			return false;
		return ((IntegerConstantValueTag) t).getIntValue() == ((IntConstant) rightOp).value;
	}
	else if (t instanceof LongConstantValueTag) {
		if (!(rightOp instanceof LongConstant))
			return false;
		return ((LongConstantValueTag) t).getLongValue() == ((LongConstant) rightOp).value;
	}
	else if (t instanceof StringConstantValueTag) {
		if (!(rightOp instanceof StringConstant))
			return false;
		return ((StringConstantValueTag) t).getStringValue().equals(((StringConstant) rightOp).value);
	}
	else
		// We don't know the type, so we assume it's alright
		return true;
}
 
Example #18
Source Project: JAADAS   Author: flankerhqd   File: UnitThrowAnalysisTest.java    License: 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 #19
Source Project: DroidRA   Author: serval-snt-uni-lu   File: IntValueAnalysis.java    License: 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 #20
Source Project: DroidRA   Author: serval-snt-uni-lu   File: IntValueAnalysis.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return all possible values for an integer local variable.
 * 
 * @param start The statement where the analysis should start.
 * @param local The local variable whose values we are looking for.
 * @param visitedStmts The set of visited statement.
 * @return The set of possible values for the local variable.
 */
private Set<Object> findIntAssignmentsForLocal(Stmt start, Local local, Set<Stmt> visitedStmts) {
  List<DefinitionStmt> assignStmts =
      findAssignmentsForLocal(start, local, true, new HashSet<Pair<Unit, Local>>());
  Set<Object> result = new HashSet<>(assignStmts.size());

  for (DefinitionStmt assignStmt : assignStmts) {
    Value rhsValue = assignStmt.getRightOp();
    if (rhsValue instanceof IntConstant) {
      result.add(((IntConstant) rhsValue).value);
    } else if (rhsValue instanceof LongConstant) {
      result.add(((LongConstant) rhsValue).value);
    } else if (rhsValue instanceof ParameterRef) {
      ParameterRef parameterRef = (ParameterRef) rhsValue;
      Iterator<Edge> edges =
          Scene.v().getCallGraph()
              .edgesInto(AnalysisParameters.v().getIcfg().getMethodOf(assignStmt));
      while (edges.hasNext()) {
        Edge edge = edges.next();
        InvokeExpr invokeExpr = edge.srcStmt().getInvokeExpr();
        Value argValue = invokeExpr.getArg(parameterRef.getIndex());
        if (argValue instanceof IntConstant) {
          result.add(((IntConstant) argValue).value);
        } else if (argValue instanceof LongConstant) {
          result.add(((LongConstant) argValue).value);
        } else if (argValue instanceof Local) {
          Set<Object> newResults =
              findIntAssignmentsForLocal(edge.srcStmt(), (Local) argValue, visitedStmts);
          result.addAll(newResults);
        } else {
          result.add(TOP_VALUE);
        }
      }
    } else {
      return Collections.singleton((Object) TOP_VALUE);
    }
  }

  return result;
}
 
Example #21
Source Project: DroidRA   Author: serval-snt-uni-lu   File: InstrumentationUtils.java    License: 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 #22
Source Project: JAADAS   Author: flankerhqd   File: ValueTemplatePrinter.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void caseLongConstant(LongConstant v) {
	printConstant(v,Long.toString(v.value));
}
 
Example #23
Source Project: JAADAS   Author: flankerhqd   File: ConstraintCollector.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void caseIfStmt(IfStmt stmt) {
	if (uses) {
		ConditionExpr cond = (ConditionExpr) stmt.getCondition();

		BinopExpr expr = cond;
		Value lv = expr.getOp1();
		Value rv = expr.getOp2();

		TypeVariable lop;
		TypeVariable rop;

		// ******** LEFT ********
		if (lv instanceof Local) {
			lop = resolver.typeVariable((Local) lv);
		} else if (lv instanceof DoubleConstant) {
			lop = resolver.typeVariable(DoubleType.v());
		} else if (lv instanceof FloatConstant) {
			lop = resolver.typeVariable(FloatType.v());
		} else if (lv instanceof IntConstant) {
			lop = resolver.typeVariable(IntType.v());
		} else if (lv instanceof LongConstant) {
			lop = resolver.typeVariable(LongType.v());
		} else if (lv instanceof NullConstant) {
			lop = resolver.typeVariable(NullType.v());
		} else if (lv instanceof StringConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (lv instanceof ClassConstant) {
			lop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass());
		}

		// ******** RIGHT ********
		if (rv instanceof Local) {
			rop = resolver.typeVariable((Local) rv);
		} else if (rv instanceof DoubleConstant) {
			rop = resolver.typeVariable(DoubleType.v());
		} else if (rv instanceof FloatConstant) {
			rop = resolver.typeVariable(FloatType.v());
		} else if (rv instanceof IntConstant) {
			rop = resolver.typeVariable(IntType.v());
		} else if (rv instanceof LongConstant) {
			rop = resolver.typeVariable(LongType.v());
		} else if (rv instanceof NullConstant) {
			rop = resolver.typeVariable(NullType.v());
		} else if (rv instanceof StringConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.String"));
		} else if (rv instanceof ClassConstant) {
			rop = resolver.typeVariable(RefType.v("java.lang.Class"));
		} else {
			throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass());
		}

		TypeVariable common = resolver.typeVariable();
		rop.addParent(common);
		lop.addParent(common);
	}
}
 
Example #24
Source Project: JAADAS   Author: flankerhqd   File: RegisterAllocator.java    License: GNU General Public License v3.0 4 votes vote down vote up
private Register asConstant(Value v, ConstantVisitor constantV) {
	Constant c = (Constant) v;
	
	Register constantRegister = null;
	
	List<Register> rArray = null;
	AtomicInteger iI = null;
	if (c instanceof ClassConstant) {
	    rArray = classConstantReg;
	    iI = classI;
	} else if (c instanceof NullConstant) {
           rArray = nullConstantReg;
           iI = nullI;
       } else if (c instanceof FloatConstant) {
           rArray = floatConstantReg;
           iI = floatI;
       } else if (c instanceof IntConstant) {
           rArray = intConstantReg;
           iI = intI;
       } else if (c instanceof LongConstant) {
           rArray = longConstantReg;
           iI = longI;
       } else if (c instanceof DoubleConstant) {
           rArray = doubleConstantReg;
           iI = doubleI;
       } else if (c instanceof StringConstant) {
           rArray = stringConstantReg;
           iI = stringI;
       } else {
           throw new RuntimeException("Error. Unknown constant type: '"+ c.getType() +"'");
       }
	
	if (rArray.size() == 0 || iI.intValue() >= rArray.size()) {
	    rArray.add(new Register(c.getType(), nextRegNum));
	    nextRegNum += SootToDexUtils.getDexWords(c.getType());
	}
	
	constantRegister = rArray.get(iI.intValue()).clone();
	iI.set(iI.intValue() + 1);

	// "load" constant into the register...
	constantV.setDestination(constantRegister);
	c.apply(constantV);
	// ...but return an independent register object
	return constantRegister.clone();
}
 
Example #25
Source Project: JAADAS   Author: flankerhqd   File: ConstantVisitor.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void caseLongConstant(LongConstant l) {
	long constant = l.value;
       stmtV.addInsn(buildConstWideInsn(constant), origStmt);
}
 
Example #26
Source Project: JAADAS   Author: flankerhqd   File: UntypedLongOrDoubleConstant.java    License: GNU General Public License v3.0 4 votes vote down vote up
public LongConstant toLongConstant() {
    return LongConstant.v(value);
}
 
Example #27
Source Project: JAADAS   Author: flankerhqd   File: ConstInstruction.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Return the literal constant for this instruction.
 *
 * @param register the register number to fill
 * @param body the body containing the instruction
 */
private Constant getConstant(int dest, DexBody body) {

    long literal = 0;

    if (instruction instanceof WideLiteralInstruction) {
        literal = ((WideLiteralInstruction)instruction).getWideLiteral();
    } else if (instruction instanceof NarrowLiteralInstruction) {
        literal = ((NarrowLiteralInstruction)instruction).getNarrowLiteral();
    } else {
        throw new RuntimeException("literal error: expected narrow or wide literal.");
    }
    

    // floats are handled later in DexBody by calling DexNumtransformer
    Opcode opcode = instruction.getOpcode();
    switch (opcode) {
    case CONST:
    case CONST_4:
    case CONST_16:
        if (IDalvikTyper.ENABLE_DVKTYPER) {
            return UntypedIntOrFloatConstant.v((int)literal);
        } else {
            return IntConstant.v((int) literal);
        }

    case CONST_HIGH16:
        if (IDalvikTyper.ENABLE_DVKTYPER) {
            //
            //return UntypedIntOrFloatConstant.v((int)literal<<16).toFloatConstant();
            // seems that dexlib correctly puts the 16bits into the topmost bits.
            //
            return UntypedIntOrFloatConstant.v((int)literal);//.toFloatConstant();
        } else {
            return IntConstant.v((int) literal);
        }

    case CONST_WIDE_HIGH16:
        if (IDalvikTyper.ENABLE_DVKTYPER) {
            //return UntypedLongOrDoubleConstant.v((long)literal<<48).toDoubleConstant();
            // seems that dexlib correctly puts the 16bits into the topmost bits.
            //
            return UntypedLongOrDoubleConstant.v((long)literal);//.toDoubleConstant();
        } else {
        	return LongConstant.v(literal);
        }

    case CONST_WIDE:
    case CONST_WIDE_16:
    case CONST_WIDE_32:
        if (IDalvikTyper.ENABLE_DVKTYPER) {
            return UntypedLongOrDoubleConstant.v(literal);
        } else {
        	return LongConstant.v(literal);
        }
    default:
        throw new IllegalArgumentException("Expected a const or a const-wide instruction, got neither.");
    }
}
 
Example #28
Source Project: JAADAS   Author: flankerhqd   File: CONSTANT_Long_info.java    License: GNU General Public License v3.0 4 votes vote down vote up
public Value createJimpleConstantValue(cp_info[] constant_pool) {
	return LongConstant.v(convert());
}
 
Example #29
Source Project: JAADAS   Author: flankerhqd   File: SimplifyExpressions.java    License: GNU General Public License v3.0 4 votes vote down vote up
public NumericConstant getResult(BinopExpr binop){
	if(DEBUG)
		System.out.println("Binop expr"+binop);
	Value leftOp = binop.getOp1();
	Value rightOp = binop.getOp2();
	
	int op = 0;
	if(binop instanceof AddExpr){
		op=1;
	}
	else if(binop instanceof SubExpr || 
			binop instanceof DCmpExpr || binop instanceof DCmpgExpr
			|| binop instanceof DCmplExpr){
		op=2;
	}
	else if(binop instanceof MulExpr){
		op=3;
	}

	if(op == 0){
		if(DEBUG){
			System.out.println("not add sub or mult");
			System.out.println(binop.getClass().getName());
		}			
		return null;
	}
	NumericConstant constant = null;
	if(leftOp instanceof LongConstant  && rightOp instanceof LongConstant){
		if(DEBUG)
			System.out.println("long constants!!");
		if(op ==1)
			constant = ((LongConstant)leftOp).add((LongConstant)rightOp);
		else if(op ==2)
			constant = ((LongConstant)leftOp).subtract((LongConstant)rightOp);
		else if (op ==3)
			constant = ((LongConstant)leftOp).multiply((LongConstant)rightOp);
	}
	else if(leftOp instanceof DoubleConstant  && rightOp instanceof DoubleConstant){
		if(DEBUG)
			System.out.println("double constants!!");
		if(op ==1)
			constant = ((DoubleConstant)leftOp).add((DoubleConstant)rightOp);
		else if(op ==2)
			constant = ((DoubleConstant)leftOp).subtract((DoubleConstant)rightOp);
		else if (op ==3)
			constant = ((DoubleConstant)leftOp).multiply((DoubleConstant)rightOp);

	}
	else if(leftOp instanceof FloatConstant  && rightOp instanceof FloatConstant){
		if(DEBUG)
			System.out.println("Float constants!!");
		if(op ==1)
			constant = ((FloatConstant)leftOp).add((FloatConstant)rightOp);
		else if(op ==2)
			constant = ((FloatConstant)leftOp).subtract((FloatConstant)rightOp);
		else if (op ==3)
			constant = ((FloatConstant)leftOp).multiply((FloatConstant)rightOp);
	}
	else if(leftOp instanceof IntConstant  && rightOp instanceof IntConstant){
		if(DEBUG)
			System.out.println("Integer constants!!");
		if(op ==1)
			constant = ((IntConstant)leftOp).add((IntConstant)rightOp);
		else if(op ==2)
			constant = ((IntConstant)leftOp).subtract((IntConstant)rightOp);
		else if (op ==3)
			constant = ((IntConstant)leftOp).multiply((IntConstant)rightOp);
	}
	
	return constant;
}
 
Example #30
Source Project: JAADAS   Author: flankerhqd   File: UnitThrowAnalysis.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void caseLongConstant(LongConstant c) {
}