Search in sources :

Example 76 with AssignStmt

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);
    }
}
Also used : OneRegisterInstruction(org.jf.dexlib2.iface.instruction.OneRegisterInstruction) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) AssignStmt(soot.jimple.AssignStmt) Local(soot.Local) StaticFieldRef(soot.jimple.StaticFieldRef)

Example 77 with AssignStmt

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);
          */
    }
}
Also used : AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) Local(soot.Local) Instruction12x(org.jf.dexlib2.iface.instruction.formats.Instruction12x)

Example 78 with AssignStmt

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().?
    }
}
Also used : Instruction22c(org.jf.dexlib2.iface.instruction.formats.Instruction22c) Type(soot.Type) DexType(soot.dexpler.DexType) AssignStmt(soot.jimple.AssignStmt) InstanceOfExpr(soot.jimple.InstanceOfExpr)

Example 79 with AssignStmt

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);
    }
}
Also used : ExitMonitorStmt(soot.jimple.ExitMonitorStmt) InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) ReturnVoidStmt(soot.jimple.ReturnVoidStmt) IntOpTag(soot.dexpler.tags.IntOpTag) RetStmt(soot.jimple.RetStmt) Unit(soot.Unit) LongOpTag(soot.dexpler.tags.LongOpTag) BreakpointStmt(soot.jimple.BreakpointStmt) FloatOpTag(soot.dexpler.tags.FloatOpTag) ArrayRef(soot.jimple.ArrayRef) DoubleOpTag(soot.dexpler.tags.DoubleOpTag) TableSwitchStmt(soot.jimple.TableSwitchStmt) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) GotoStmt(soot.jimple.GotoStmt) CastExpr(soot.jimple.CastExpr) StmtSwitch(soot.jimple.StmtSwitch) IdentityStmt(soot.jimple.IdentityStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) LookupSwitchStmt(soot.jimple.LookupSwitchStmt) DivExpr(soot.jimple.DivExpr) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) ArrayType(soot.ArrayType) PrimType(soot.PrimType) IfStmt(soot.jimple.IfStmt) NewArrayExpr(soot.jimple.NewArrayExpr) RemExpr(soot.jimple.RemExpr) NopStmt(soot.jimple.NopStmt) Value(soot.Value) LongOpTag(soot.dexpler.tags.LongOpTag) Tag(soot.tagkit.Tag) DoubleOpTag(soot.dexpler.tags.DoubleOpTag) IntOpTag(soot.dexpler.tags.IntOpTag) FloatOpTag(soot.dexpler.tags.FloatOpTag) ReturnStmt(soot.jimple.ReturnStmt) ThrowStmt(soot.jimple.ThrowStmt)

Example 80 with AssignStmt

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();
}
Also used : LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) AssignStmt(soot.jimple.AssignStmt) ArrayList(java.util.ArrayList) Unit(soot.Unit) Date(java.util.Date) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) RefType(soot.RefType) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) Value(soot.Value) InstanceFieldRef(soot.jimple.InstanceFieldRef) SootMethod(soot.SootMethod) SootField(soot.SootField) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) HashSet(java.util.HashSet)

Aggregations

AssignStmt (soot.jimple.AssignStmt)83 Local (soot.Local)50 Value (soot.Value)44 Unit (soot.Unit)40 Type (soot.Type)28 Stmt (soot.jimple.Stmt)24 InvokeExpr (soot.jimple.InvokeExpr)20 RefType (soot.RefType)19 ArrayRef (soot.jimple.ArrayRef)19 ArrayType (soot.ArrayType)17 CastExpr (soot.jimple.CastExpr)17 InvokeStmt (soot.jimple.InvokeStmt)17 ArrayList (java.util.ArrayList)15 IdentityStmt (soot.jimple.IdentityStmt)15 DefinitionStmt (soot.jimple.DefinitionStmt)13 FieldRef (soot.jimple.FieldRef)13 InstanceFieldRef (soot.jimple.InstanceFieldRef)13 IntConstant (soot.jimple.IntConstant)13 ReturnStmt (soot.jimple.ReturnStmt)13 HashSet (java.util.HashSet)12