use of soot.ValueBox in project soot by Sable.
the class DArrayInitExpr method getUseBoxes.
/*
* go through the elements array
* return useBoxes of each value plus the valuebox itself
*/
public List<ValueBox> getUseBoxes() {
List<ValueBox> list = new ArrayList<ValueBox>();
for (ValueBox element : elements) {
list.addAll(element.getValue().getUseBoxes());
list.add(element);
}
return list;
}
use of soot.ValueBox in project soot by Sable.
the class TypeAssigner method replaceNullType.
/**
* Replace statements using locals with null_type type and that would
* throw a NullPointerException at runtime by a set of instructions
* throwing a NullPointerException.
*
* This is done to remove locals with null_type type.
*
* @param b
*/
private void replaceNullType(Body b) {
List<Local> localsToRemove = new ArrayList<Local>();
boolean hasNullType = false;
// check if any local has null_type
for (Local l : b.getLocals()) {
if (l.getType() instanceof NullType) {
localsToRemove.add(l);
hasNullType = true;
}
}
// No local with null_type
if (!hasNullType)
return;
// force to propagate null constants
Map<String, String> opts = PhaseOptions.v().getPhaseOptions("jop.cpf");
if (!opts.containsKey("enabled") || !opts.get("enabled").equals("true")) {
logger.warn("Cannot run TypeAssigner.replaceNullType(Body). Try to enable jop.cfg.");
return;
}
ConstantPropagatorAndFolder.v().transform(b);
List<Unit> unitToReplaceByException = new ArrayList<Unit>();
for (Unit u : b.getUnits()) {
for (ValueBox vb : u.getUseBoxes()) {
if (vb.getValue() instanceof Local && ((Local) vb.getValue()).getType() instanceof NullType) {
Local l = (Local) vb.getValue();
Stmt s = (Stmt) u;
boolean replace = false;
if (s.containsArrayRef()) {
ArrayRef r = s.getArrayRef();
if (r.getBase() == l) {
replace = true;
}
} else if (s.containsFieldRef()) {
FieldRef r = s.getFieldRef();
if (r instanceof InstanceFieldRef) {
InstanceFieldRef ir = (InstanceFieldRef) r;
if (ir.getBase() == l) {
replace = true;
}
}
} else if (s.containsInvokeExpr()) {
InvokeExpr ie = s.getInvokeExpr();
if (ie instanceof InstanceInvokeExpr) {
InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
if (iie.getBase() == l) {
replace = true;
}
}
}
if (replace) {
unitToReplaceByException.add(u);
}
}
}
}
for (Unit u : unitToReplaceByException) {
soot.dexpler.Util.addExceptionAfterUnit(b, "java.lang.NullPointerException", u, "This statement would have triggered an Exception: " + u);
b.getUnits().remove(u);
}
// should be done on a separate phase
DeadAssignmentEliminator.v().transform(b);
UnusedLocalEliminator.v().transform(b);
}
use of soot.ValueBox in project soot by Sable.
the class JDynamicInvokeExpr method equivTo.
public boolean equivTo(Object o) {
if (o instanceof JDynamicInvokeExpr) {
JDynamicInvokeExpr ie = (JDynamicInvokeExpr) o;
if (!(getMethod().equals(ie.getMethod()) && bsmArgBoxes.length == ie.bsmArgBoxes.length))
return false;
int i = 0;
for (ValueBox element : bsmArgBoxes) {
if (!(element.getValue().equivTo(ie.getBootstrapArg(i))))
return false;
i++;
}
if (!(getMethod().equals(ie.getMethod()) && (argBoxes == null ? 0 : argBoxes.length) == (ie.argBoxes == null ? 0 : ie.argBoxes.length)))
return false;
if (argBoxes != null) {
i = 0;
for (ValueBox element : argBoxes) {
if (!(element.getValue().equivTo(ie.getArg(i))))
return false;
i++;
}
}
if (!methodRef.equals(ie.methodRef))
return false;
if (!bsmRef.equals(ie.bsmRef))
return false;
return true;
}
return false;
}
use of soot.ValueBox in project soot by Sable.
the class JDynamicInvokeExpr method convertToBaf.
public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
if (argBoxes != null) {
for (ValueBox element : argBoxes) {
((ConvertToBaf) (element.getValue())).convertToBaf(context, out);
}
}
List<Value> bsmArgs = new ArrayList<Value>();
for (ValueBox argBox : bsmArgBoxes) {
bsmArgs.add(argBox.getValue());
}
Unit u = Baf.v().newDynamicInvokeInst(bsmRef, bsmArgs, methodRef, tag);
u.addAllTagsOf(context.getCurrentUnit());
out.add(u);
}
use of soot.ValueBox in project soot by Sable.
the class ArrayIndexLivenessAnalysis method getAllRelatedMaps.
private void getAllRelatedMaps(Body body) {
Iterator unitIt = body.getUnits().iterator();
while (unitIt.hasNext()) {
Stmt stmt = (Stmt) unitIt.next();
if (csin) {
if (stmt instanceof DefinitionStmt) {
Value rhs = ((DefinitionStmt) stmt).getRightOp();
if (rhs instanceof BinopExpr) {
Value op1 = ((BinopExpr) rhs).getOp1();
Value op2 = ((BinopExpr) rhs).getOp2();
if (rhs instanceof AddExpr) {
// op1 + op2 --> a + b
if ((op1 instanceof Local) && (op2 instanceof Local)) {
HashSet<Value> refs = localToExpr.get(op1);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op1, refs);
}
refs.add(rhs);
refs = localToExpr.get(op2);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op2, refs);
}
refs.add(rhs);
}
} else // a * b, a * c, c * a
if (rhs instanceof MulExpr) {
HashSet<Value> refs = localToExpr.get(op1);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op1, refs);
}
refs.add(rhs);
refs = localToExpr.get(op2);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op2, refs);
}
refs.add(rhs);
} else if (rhs instanceof SubExpr) {
if (op2 instanceof Local) {
HashSet<Value> refs = localToExpr.get(op2);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op2, refs);
}
refs.add(rhs);
if (op1 instanceof Local) {
refs = localToExpr.get(op1);
if (refs == null) {
refs = new HashSet<Value>();
localToExpr.put(op1, refs);
}
refs.add(rhs);
}
}
}
}
}
}
for (ValueBox vbox : stmt.getUseAndDefBoxes()) {
Value v = vbox.getValue();
if (fieldin) {
if (v instanceof InstanceFieldRef) {
Value base = ((InstanceFieldRef) v).getBase();
SootField field = ((InstanceFieldRef) v).getField();
HashSet<Value> baseset = localToFieldRef.get(base);
if (baseset == null) {
baseset = new HashSet<Value>();
localToFieldRef.put(base, baseset);
}
baseset.add(v);
HashSet<Value> fieldset = fieldToFieldRef.get(field);
if (fieldset == null) {
fieldset = new HashSet<Value>();
fieldToFieldRef.put(field, fieldset);
}
fieldset.add(v);
}
if (v instanceof FieldRef)
allFieldRefs.add(v);
}
if (arrayin) {
// a = ... --> kill all a[x] nodes.
// a[i] = .. --> kill all array references.
// m(a) --> kill all array references
// i = ... --> kill all array reference with index as i
/*
if (v instanceof ArrayRef)
{
Value base = ((ArrayRef)v).getBase();
Value index = ((ArrayRef)v).getIndex();
HashSet refset = (HashSet)localToArrayRef.get(base);
if (refset == null)
{
refset = new HashSet();
localToArrayRef.put(base, refset);
}
refset.add(v);
if (index instanceof Local)
{
refset = (HashSet)localToArrayRef.get(index);
if (refset == null)
{
refset = new HashSet();
localToArrayRef.put(index, refset);
}
refset.add(v);
}
allArrayRefs.add(v);
}
*/
}
}
}
}
Aggregations