use of soot.jimple.AssignStmt in project soot by Sable.
the class SputInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
int source = ((OneRegisterInstruction) instruction).getRegisterA();
FieldReference f = (FieldReference) ((ReferenceInstruction) instruction).getReference();
StaticFieldRef instanceField = Jimple.v().newStaticFieldRef(getStaticSootFieldRef(f));
Local sourceValue = body.getRegisterLocal(source);
AssignStmt assign = getAssignStmt(body, sourceValue, instanceField);
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
DalvikTyper.v().setType(assign.getRightOpBox(), instanceField.getType(), true);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class UnopInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction12x))
throw new IllegalArgumentException("Expected Instruction12x but got: " + instruction.getClass());
Instruction12x cmpInstr = (Instruction12x) instruction;
int dest = cmpInstr.getRegisterA();
Local source = body.getRegisterLocal(cmpInstr.getRegisterB());
Value expr = getExpression(source);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
assign.addTag(getTag());
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
/*
int op = (int)instruction.getOpcode().value;
//DalvikTyper.v().captureAssign((JAssignStmt)assign, op);
JAssignStmt jass = (JAssignStmt)assign;
DalvikTyper.v().setType((expr instanceof JCastExpr) ? ((JCastExpr) expr).getOpBox() : ((UnopExpr) expr).getOpBox(), opUnType[op - 0x7b], true);
DalvikTyper.v().setType(jass.leftBox, resUnType[op - 0x7b], false);
*/
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class InstanceOfInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
Instruction22c i = (Instruction22c) instruction;
int dest = i.getRegisterA();
int source = i.getRegisterB();
Type t = DexType.toSoot((TypeReference) (i.getReference()));
InstanceOfExpr e = Jimple.v().newInstanceOfExpr(body.getRegisterLocal(source), t);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), e);
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
// DalvikTyper.v().?
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class DalvikTyper method typeUntypedConstrantInDiv.
// this is needed because UnuesedStatementTransformer checks types in the div expressions
public void typeUntypedConstrantInDiv(final Body b) {
for (Unit u : b.getUnits()) {
StmtSwitch sw = new StmtSwitch() {
@Override
public void caseBreakpointStmt(BreakpointStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseInvokeStmt(InvokeStmt stmt) {
changeUntypedConstantsInInvoke(stmt.getInvokeExpr());
}
@Override
public void caseAssignStmt(AssignStmt stmt) {
if (stmt.getRightOp() instanceof NewArrayExpr) {
NewArrayExpr nae = (NewArrayExpr) stmt.getRightOp();
if (nae.getSize() instanceof UntypedConstant) {
UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) nae.getSize();
nae.setSize(uc.defineType(IntType.v()));
}
} else if (stmt.getRightOp() instanceof InvokeExpr) {
changeUntypedConstantsInInvoke((InvokeExpr) stmt.getRightOp());
} else if (stmt.getRightOp() instanceof CastExpr) {
CastExpr ce = (CastExpr) stmt.getRightOp();
if (ce.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) ce.getOp();
// check incoming primitive type
for (Tag t : stmt.getTags()) {
// Debug.printDbg("assign primitive type from stmt tag: ", stmt, t);
if (t instanceof IntOpTag) {
ce.setOp(uc.defineType(IntType.v()));
return;
} else if (t instanceof FloatOpTag) {
ce.setOp(uc.defineType(FloatType.v()));
return;
} else if (t instanceof DoubleOpTag) {
ce.setOp(uc.defineType(DoubleType.v()));
return;
} else if (t instanceof LongOpTag) {
ce.setOp(uc.defineType(LongType.v()));
return;
}
}
// 0 -> null
ce.setOp(uc.defineType(RefType.v("java.lang.Object")));
}
}
if (stmt.containsArrayRef()) {
ArrayRef ar = stmt.getArrayRef();
if ((ar.getIndex() instanceof UntypedConstant)) {
UntypedIntOrFloatConstant uc = (UntypedIntOrFloatConstant) ar.getIndex();
ar.setIndex(uc.toIntConstant());
}
}
Value r = stmt.getRightOp();
if (r instanceof DivExpr || r instanceof RemExpr) {
// DivExpr de = (DivExpr) r;
for (Tag t : stmt.getTags()) {
// Debug.printDbg("div stmt tag: ", stmt, t);
if (t instanceof IntOpTag) {
checkExpr(r, IntType.v());
return;
} else if (t instanceof FloatOpTag) {
checkExpr(r, FloatType.v());
return;
} else if (t instanceof DoubleOpTag) {
checkExpr(r, DoubleType.v());
return;
} else if (t instanceof LongOpTag) {
checkExpr(r, LongType.v());
return;
}
}
}
}
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseGotoStmt(GotoStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseIfStmt(IfStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseNopStmt(NopStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseRetStmt(RetStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseReturnStmt(ReturnStmt stmt) {
if (stmt.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) stmt.getOp();
Type type = b.getMethod().getReturnType();
stmt.setOp(uc.defineType(type));
}
}
@Override
public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseTableSwitchStmt(TableSwitchStmt stmt) {
// TODO Auto-generated method stub
}
@Override
public void caseThrowStmt(ThrowStmt stmt) {
if (stmt.getOp() instanceof UntypedConstant) {
UntypedConstant uc = (UntypedConstant) stmt.getOp();
stmt.setOp(uc.defineType(RefType.v("java.lang.Object")));
}
}
@Override
public void defaultCase(Object obj) {
// TODO Auto-generated method stub
}
};
u.apply(sw);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class EvalResults method checkAliasAnalysis.
/**
* Count how many aliased base pointers appeared in all user's functions.
*/
public void checkAliasAnalysis() {
Set<IVarAbstraction> access_expr = new HashSet<IVarAbstraction>();
ArrayList<IVarAbstraction> al = new ArrayList<IVarAbstraction>();
Value[] values = new Value[2];
for (SootMethod sm : ptsProvider.getAllReachableMethods()) {
if (sm.isJavaLibraryMethod())
continue;
if (!sm.isConcrete())
continue;
if (!sm.hasActiveBody()) {
sm.retrieveActiveBody();
}
if (!ptsProvider.isValidMethod(sm))
continue;
// access_expr.clear();
for (Iterator<Unit> stmts = sm.getActiveBody().getUnits().iterator(); stmts.hasNext(); ) {
Stmt st = (Stmt) stmts.next();
if (st instanceof AssignStmt) {
AssignStmt a = (AssignStmt) st;
values[0] = a.getLeftOp();
values[1] = a.getRightOp();
for (Value v : values) {
// expression: p.f
if (v instanceof InstanceFieldRef) {
InstanceFieldRef ifr = (InstanceFieldRef) v;
final SootField field = ifr.getField();
if (!(field.getType() instanceof RefType))
continue;
LocalVarNode vn = ptsProvider.findLocalVarNode((Local) ifr.getBase());
if (vn == null)
continue;
if (ptsProvider.isExceptionPointer(vn))
continue;
IVarAbstraction pn = ptsProvider.findInternalNode(vn);
if (pn == null)
continue;
pn = pn.getRepresentative();
if (pn.hasPTResult())
access_expr.add(pn);
}
}
}
}
}
access_expr.remove(null);
al.addAll(access_expr);
access_expr = null;
// Next, we pair up all the pointers
Date begin = new Date();
int size = al.size();
for (int i = 0; i < size; ++i) {
IVarAbstraction pn = al.get(i);
VarNode n1 = (VarNode) pn.getWrappedNode();
for (int j = i + 1; j < size; ++j) {
IVarAbstraction qn = al.get(j);
VarNode n2 = (VarNode) qn.getWrappedNode();
if (pn.heap_sensitive_intersection(qn))
evalRes.n_hs_alias++;
// We directly use the SPARK points-to sets
if (n1.getP2Set().hasNonEmptyIntersection(n2.getP2Set()))
evalRes.n_hi_alias++;
}
}
evalRes.n_alias_pairs = size * (size - 1) / 2;
Date end = new Date();
ptsProvider.ps.println();
ptsProvider.ps.println("--------> Alias Pairs Evaluation <---------");
ptsProvider.ps.println("Number of pointer pairs in app code: " + evalRes.n_alias_pairs);
ptsProvider.ps.printf("Heap sensitive alias pairs (by Geom): %d, Percentage = %.3f%%\n", evalRes.n_hs_alias, (double) evalRes.n_hs_alias / evalRes.n_alias_pairs * 100);
ptsProvider.ps.printf("Heap insensitive alias pairs (by SPARK): %d, Percentage = %.3f%%\n", evalRes.n_hi_alias, (double) evalRes.n_hi_alias / evalRes.n_alias_pairs * 100);
ptsProvider.ps.printf("Using time: %dms \n", end.getTime() - begin.getTime());
ptsProvider.ps.println();
}
Aggregations