Search in sources :

Example 1 with Transfer

use of heros.flowfunc.Transfer in project soot by Sable.

the class IFDSLocalInfoFlow method createFlowFunctionsFactory.

public FlowFunctions<Unit, Local, SootMethod> createFlowFunctionsFactory() {
    return new FlowFunctions<Unit, Local, SootMethod>() {

        @Override
        public FlowFunction<Local> getNormalFlowFunction(Unit src, Unit dest) {
            if (src instanceof IdentityStmt && interproceduralCFG().getMethodOf(src) == Scene.v().getMainMethod()) {
                IdentityStmt is = (IdentityStmt) src;
                Local leftLocal = (Local) is.getLeftOp();
                Value right = is.getRightOp();
                if (right instanceof ParameterRef) {
                    return new Gen<Local>(leftLocal, zeroValue());
                }
            }
            if (src instanceof AssignStmt) {
                AssignStmt assignStmt = (AssignStmt) src;
                Value right = assignStmt.getRightOp();
                if (assignStmt.getLeftOp() instanceof Local) {
                    final Local leftLocal = (Local) assignStmt.getLeftOp();
                    if (right instanceof Local) {
                        final Local rightLocal = (Local) right;
                        return new Transfer<Local>(leftLocal, rightLocal);
                    } else {
                        return new Kill<Local>(leftLocal);
                    }
                }
            }
            return Identity.v();
        }

        @Override
        public FlowFunction<Local> getCallFlowFunction(Unit src, final SootMethod dest) {
            Stmt s = (Stmt) src;
            InvokeExpr ie = s.getInvokeExpr();
            final List<Value> callArgs = ie.getArgs();
            final List<Local> paramLocals = new ArrayList<Local>();
            for (int i = 0; i < dest.getParameterCount(); i++) {
                paramLocals.add(dest.getActiveBody().getParameterLocal(i));
            }
            return new FlowFunction<Local>() {

                public Set<Local> computeTargets(Local source) {
                    // ignore implicit calls to static initializers
                    if (dest.getName().equals(SootMethod.staticInitializerName) && dest.getParameterCount() == 0)
                        return Collections.emptySet();
                    Set<Local> taintsInCaller = new HashSet<Local>();
                    for (int i = 0; i < callArgs.size(); i++) {
                        if (callArgs.get(i).equivTo(source)) {
                            taintsInCaller.add(paramLocals.get(i));
                        }
                    }
                    return taintsInCaller;
                }
            };
        }

        @Override
        public FlowFunction<Local> getReturnFlowFunction(Unit callSite, SootMethod callee, Unit exitStmt, Unit retSite) {
            if (exitStmt instanceof ReturnStmt) {
                ReturnStmt returnStmt = (ReturnStmt) exitStmt;
                Value op = returnStmt.getOp();
                if (op instanceof Local) {
                    if (callSite instanceof DefinitionStmt) {
                        DefinitionStmt defnStmt = (DefinitionStmt) callSite;
                        Value leftOp = defnStmt.getLeftOp();
                        if (leftOp instanceof Local) {
                            final Local tgtLocal = (Local) leftOp;
                            final Local retLocal = (Local) op;
                            return new FlowFunction<Local>() {

                                public Set<Local> computeTargets(Local source) {
                                    if (source == retLocal)
                                        return Collections.singleton(tgtLocal);
                                    return Collections.emptySet();
                                }
                            };
                        }
                    }
                }
            }
            return KillAll.v();
        }

        @Override
        public FlowFunction<Local> getCallToReturnFlowFunction(Unit call, Unit returnSite) {
            return Identity.v();
        }
    };
}
Also used : AssignStmt(soot.jimple.AssignStmt) FlowFunction(heros.FlowFunction) ArrayList(java.util.ArrayList) JimpleLocal(soot.jimple.internal.JimpleLocal) Local(soot.Local) Unit(soot.Unit) FlowFunctions(heros.FlowFunctions) IdentityStmt(soot.jimple.IdentityStmt) ReturnStmt(soot.jimple.ReturnStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) DefinitionStmt(soot.jimple.DefinitionStmt) Gen(heros.flowfunc.Gen) ParameterRef(soot.jimple.ParameterRef) InvokeExpr(soot.jimple.InvokeExpr) Value(soot.Value) Transfer(heros.flowfunc.Transfer) SootMethod(soot.SootMethod) Kill(heros.flowfunc.Kill) ReturnStmt(soot.jimple.ReturnStmt) DefinitionStmt(soot.jimple.DefinitionStmt) IdentityStmt(soot.jimple.IdentityStmt) HashSet(java.util.HashSet)

Aggregations

FlowFunction (heros.FlowFunction)1 FlowFunctions (heros.FlowFunctions)1 Gen (heros.flowfunc.Gen)1 Kill (heros.flowfunc.Kill)1 Transfer (heros.flowfunc.Transfer)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Local (soot.Local)1 SootMethod (soot.SootMethod)1 Unit (soot.Unit)1 Value (soot.Value)1 AssignStmt (soot.jimple.AssignStmt)1 DefinitionStmt (soot.jimple.DefinitionStmt)1 IdentityStmt (soot.jimple.IdentityStmt)1 InvokeExpr (soot.jimple.InvokeExpr)1 ParameterRef (soot.jimple.ParameterRef)1 ReturnStmt (soot.jimple.ReturnStmt)1 Stmt (soot.jimple.Stmt)1 JimpleLocal (soot.jimple.internal.JimpleLocal)1