Java 类soot.jimple.ReturnStmt 实例源码

项目:FuzzDroid    文件:PathExecutionTransformer.java   
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
    // Do not instrument methods in framework classes
    if (!canInstrumentMethod(body.getMethod()))
        return;

    instrumentInfoAboutNonAPICall(body);

    //important to use snapshotIterator here
    Iterator<Unit> iterator = body.getUnits().snapshotIterator();
    while(iterator.hasNext()){
        Unit unit = iterator.next();
        if(unit instanceof ReturnStmt || unit instanceof ReturnVoidStmt)
            instrumentInfoAboutReturnStmt(body, unit);
        else if(unit instanceof DefinitionStmt || unit instanceof InvokeStmt)
            instrumentInfoAboutNonApiCaller(body, unit);
        else if(unit instanceof IfStmt)
            instrumentEachBranchAccess(body, (IfStmt)unit);
    }               
}
项目:FuzzDroid    文件:JimpleStmtVisitorImpl.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    //in case of return CONSTANT, we do nothing; unfortunately, this is part of FlowDroid's path
    if(stmt.getOp() instanceof Constant)
        return;
    int index = jimpleDataFlowStatements.indexOf(stmt);
    AccessPath ap = accessPathPath.get(index);
    Local local = ap.getPlainValue();

    SMTBinding lhs = createNewBindingForValue(local);
    addValueBindingToVariableDeclaration(local, lhs);

    if(!hasBindingForValue(stmt.getOp()))
        throw new RuntimeException("There has to be a tainted value");
    SMTBinding rhs = getLatestBindingForValue(stmt.getOp());

    SMTSimpleAssignment simpleAss = new SMTSimpleAssignment(lhs, new SMTBindingValue(rhs));
    SMTAssertStatement assertStmt = new SMTAssertStatement(simpleAss);
    addAssertStmtToAllPrograms(assertStmt); 
}
项目:boomerang    文件:PreparationTransformer.java   
private Map<Unit, Body> getStmtsWithConstants() {
  Map<Unit, Body> retMap = new LinkedHashMap<Unit, Body>();
  for (SootClass sc : Scene.v().getClasses()) {
    for (SootMethod sm : sc.getMethods()) {
      if (!sm.hasActiveBody())
        continue;
      Body methodBody = sm.retrieveActiveBody();
      for (Unit u : methodBody.getUnits()) {
        if (u instanceof ReturnStmt) {
          if (((ReturnStmt) u).getOp() instanceof Constant) {
            retMap.put(u, methodBody);
          }
        } else if (((Stmt) u).containsInvokeExpr()) {
          InvokeExpr ie = ((Stmt) u).getInvokeExpr();
          for (Value arg : ie.getArgs()) {
            if (arg instanceof StringConstant || arg instanceof NumericConstant) {
              retMap.put(u, methodBody);
              break;
            }
          }
        }
      }
    }
  }
  return retMap;
}
项目:JAADAS    文件:DefaultSourceSinkManager.java   
@Override
public boolean isSink(Stmt sCallSite, InterproceduralCFG<Unit, SootMethod> cfg,
        AccessPath ap) {
    // Check whether values returned by the current method are to be
    // considered as sinks
    if (this.returnTaintMethods != null
            && sCallSite instanceof ReturnStmt
            && this.returnTaintMethods.contains(cfg.getMethodOf(sCallSite).getSignature()))
        return true;

    // Check whether the callee is a sink
    if (this.sinks != null
            && sCallSite.containsInvokeExpr()
            && this.sinks.contains(sCallSite.getInvokeExpr().getMethod().getSignature()))
        return true;

    return false;
}
项目:JAADAS    文件:ConstraintChecker.java   
public void caseReturnStmt(ReturnStmt stmt) {
    if (stmt.getOp() instanceof Local) {
        if (((Local) stmt.getOp()).getType() instanceof IntegerType) {
            if (!ClassHierarchy
                    .v()
                    .typeNode(((Local) stmt.getOp()).getType())
                    .hasAncestor_1(
                            ClassHierarchy.v().typeNode(
                                    stmtBody.getMethod().getReturnType()))) {
                if (fix) {
                    stmt.setOp(insertCast((Local) stmt.getOp(), stmtBody
                            .getMethod().getReturnType(), stmt));
                } else {
                    error("Type Error(19)");
                }
            }
        }
    }
}
项目:JAADAS    文件:StmtVisitor.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    Value returnValue = stmt.getOp();
    constantV.setOrigStmt(stmt);
    Register returnReg = regAlloc.asImmediate(returnValue, constantV);
    Opcode opc;
    Type retType = returnValue.getType();
    if (SootToDexUtils.isObject(retType)) {
        opc = Opcode.RETURN_OBJECT;
    } else if (SootToDexUtils.isWide(retType)) {
        opc = Opcode.RETURN_WIDE;
    } else {
        opc = Opcode.RETURN;
    }
       addInsn(new Insn11x(opc, returnReg), stmt);
}
项目:JAADAS    文件:IfElseSplitter.java   
public boolean tryBodyPattern(List<Object> body,SETNodeLabel label, List<Object> otherBody){
    Stmt lastStmt = getLastStmt(body);
    if(lastStmt == null){
        //dont have a last stmt so cant match pattern
        return false;
    }

    if(! (lastStmt instanceof ReturnStmt || lastStmt instanceof ReturnVoidStmt || lastStmt instanceof DAbruptStmt)){
        //lastStmt is not an abrupt stmt
        return false;
    }

    if(bodyTargetsLabel(label,body) || bodyTargetsLabel(label,otherBody)){
        //one of the bodies targets the label on the ifelse cant match pattern
        return false;
    }

    //pattern matched
    return true;
}
项目:petablox    文件:SootUtilities.java   
public static Local getReturnLocal(SootMethod m){
    try{
        Body body = m.retrieveActiveBody();
        for(Unit unit : body.getUnits()){
            Stmt s = (Stmt) unit;
            if(s instanceof ReturnStmt){
                Immediate retOp = (Immediate) ((ReturnStmt) s).getOp();
                if(retOp instanceof Local)
                    return (Local)retOp;
            }
        }
    }catch(RuntimeException e){
        System.out.println("Method body not found for method: "+m.getSignature());
    };
    return null;
}
项目:soot-infoflow-android-iccta    文件:SootHelper.java   
public static Stmt getReturnStmt(SootMethod sootMethod)
{
    Stmt rtVal = null;

    Body b = sootMethod.retrieveActiveBody();
    PatchingChain<Unit> units = b.getUnits();

    for (Iterator<Unit> iter = units.iterator(); iter.hasNext(); )
    {
        Stmt stmt = (Stmt) iter.next();

        if (stmt instanceof ReturnStmt || stmt instanceof ReturnVoidStmt)
        {
            rtVal = stmt;
        }
    }

    return rtVal;
}
项目:FlowTwist    文件:ReturnValuePropagator.java   
@Override
public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) {
    if (curr instanceof ReturnStmt) {
        Value retValue = getBase(((ReturnStmt) curr).getOp());
        if (retValue instanceof Constant) {
            return kill();
        } else {
            ReturnValueTaint retValTaint = (ReturnValueTaint) trackable;
            if (AnalysisUtil.isAssignable(retValTaint.type, retValue.getType()))
                return propagate(new Taint(curr, trackable, retValue, retValTaint.type));
            else
                return kill();
        }
    } else if (curr instanceof ThrowStmt)
        return kill();

    throw new IllegalStateException();
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
@Override
public KillGenInfo propagateCallFlow(Trackable trackable, Unit callStmt, SootMethod destinationMethod) {
    Taint taint = (Taint) trackable;

    if (callStmt instanceof AssignStmt) {
        AssignStmt assignStmt = (AssignStmt) callStmt;
        if (taint.value.equals(assignStmt.getLeftOp())) {
            if (AnalysisUtil.isAssignable(taint.type, destinationMethod.getReturnType())) {
                for (Unit u : context.icfg.getStartPointsOf(destinationMethod)) {
                    if (u instanceof ReturnStmt) {
                        ReturnStmt returnStmt = (ReturnStmt) u;
                        Value retValue = returnStmt.getOp();

                        if (retValue instanceof Constant)
                            continue;

                        // There is at least one non constant return stmt
                        return propagate(new ReturnValueTaint(callStmt, trackable, taint.type));
                    }
                }
            }
        }
    }

    return kill();
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
@Override
public KillGenInfo propagateReturnFlow(Trackable trackable, Unit callSite, SootMethod calleeMethod, Unit exitStmt, Unit returnSite) {
    Taint taint = (Taint) trackable;

    if (!(exitStmt instanceof ReturnStmt))
        return kill();

    if (!(callSite instanceof AssignStmt))
        return kill();

    ReturnStmt returnStmt = (ReturnStmt) exitStmt;
    AssignStmt assignStmt = (AssignStmt) callSite;

    if (!returnStmt.getOp().equivTo(taint.value))
        return kill();

    Value left = AnalysisUtil.getForwardsBase(assignStmt.getLeftOp());
    // return propagate(taint.createAlias(left, callSite));
    // return propagate(taint.createAlias(left, exitStmt));
    return propagate(new ReturnEdgeTaint(callSite, exitStmt, taint, left, -1, taint.type));
}
项目:FlowTwist    文件:I2OSourceRecognizer.java   
@Override
public KillGenInfo propagateReturnFlow(Trackable trackable, Unit callSite, SootMethod calleeMethod, Unit exitStmt, Unit returnSite) {
    if (!(exitStmt instanceof ReturnStmt))
        return identity();

    Taint taint = (Taint) trackable;

    ReturnStmt returnStmt = (ReturnStmt) exitStmt;
    Value retVal = AnalysisUtil.getForwardsBase(returnStmt.getOp());
    if (AnalysisUtil.maybeSameLocation(taint.value, retVal)) {
        SootMethod m = context.icfg.getMethodOf(returnStmt);
        if (AnalysisUtil.methodMayBeCallableFromApplication(m) && transitiveSinkCaller.isTransitiveCallerOfAnySink(m)) {
            context.reporter.reportTrackable(new Report(context, taint, exitStmt));
        }
    }
    return identity();
}
项目:FlowTwist    文件:PayloadSourceRecognizer.java   
@Override
public KillGenInfo propagateReturnFlow(Trackable trackable, Unit callSite, SootMethod calleeMethod, Unit exitStmt, Unit returnSite) {
    boolean isSeedMethod = seedMethods.contains(context.icfg.getMethodOf(exitStmt));

    if (!(exitStmt instanceof ReturnStmt))
        return new KillGenInfo(isSeedMethod, Collections.<Trackable> emptyList());

    Taint taint = (Taint) trackable;
    ReturnStmt returnStmt = (ReturnStmt) exitStmt;
    Value retVal = AnalysisUtil.getForwardsBase(returnStmt.getOp());
    if (isSeedMethod && AnalysisUtil.maybeSameLocation(taint.value, retVal)) {
        SootMethod m = context.icfg.getMethodOf(returnStmt);
        if (AnalysisUtil.methodMayBeCallableFromApplication(m)) {
            if (!trackable.getPayload().isEmpty()) {
                context.reporter.reportTrackable(new Report(context, taint, exitStmt));
            }
        }
    }
    return new KillGenInfo(isSeedMethod, Collections.<Trackable> emptyList());
}
项目:jgs    文件:SecurityConstraintStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    returnStmt = stmt;
    SecurityConstraintValueReadSwitch readSwitch =
        getReadSwitch(stmt.getOp());
    addInheritedWriteEffects(readSwitch);
    Set<LEQConstraint> constraints =
        new HashSet<LEQConstraint>(readSwitch.getConstraints());
    ComponentReturnRef returnRef =
        new ComponentReturnRef(getAnalyzedSignature());
    for (IComponent read : readSwitch.getReadComponents()) {
        constraints.add(new LEQConstraint(read, returnRef));
    }
    for (int j = 0; j < readSwitch.getEqualComponents().size(); j++) {
        IComponent equalComponent = readSwitch.getEqualComponents().get(j);
        ComponentArrayRef arrayRef =
            new ComponentArrayRef(returnRef, j + 1);
        constraints.add(new LEQConstraint(arrayRef, equalComponent));
        constraints.add(new LEQConstraint(equalComponent, arrayRef));
    }
    addConstraints(constraints);
}
项目:boomerang    文件:BoomerangContext.java   
public boolean isReturnValue(SootMethod method, Local base) {
  Collection<Unit> endPointsOf = icfg.getEndPointsOf(method);

  for (Unit eP : endPointsOf) {
    if (eP instanceof ReturnStmt) {
      ReturnStmt returnStmt = (ReturnStmt) eP;
      Value op = returnStmt.getOp();
      if (op.equals(base))
        return true;
    }
  }
  return false;
}
项目:JAADAS    文件:ConstraintCollector.java   
public void caseReturnStmt(ReturnStmt stmt) {
    if (uses) {
        if (stmt.getOp() instanceof Local) {
            if (((Local) stmt.getOp()).getType() instanceof IntegerType) {
                resolver.typeVariable((Local) stmt.getOp()).addParent(
                        resolver.typeVariable(stmtBody.getMethod().getReturnType()));
            }
        }
    }
}
项目:JAADAS    文件:ConstraintCollector.java   
public void caseReturnStmt(ReturnStmt stmt) {
    if (uses) {
        if (stmt.getOp() instanceof Local) {
            resolver.typeVariable((Local) stmt.getOp()).addParent(
                    resolver.typeVariable(stmtBody.getMethod().getReturnType()));
        }
    }
}
项目:JAADAS    文件:CastAndReturnInliner.java   
@Override
protected void internalTransform(Body body, String phaseName,
        Map<String, String> options) {
    Iterator<Unit> it = body.getUnits().snapshotIterator();
    while (it.hasNext()) {
        Unit u = it.next();
        if (u instanceof GotoStmt) {
            GotoStmt gtStmt = (GotoStmt) u;
            if (gtStmt.getTarget() instanceof AssignStmt) {
                AssignStmt assign = (AssignStmt) gtStmt.getTarget();
                if (assign.getRightOp() instanceof CastExpr) {
                    CastExpr ce = (CastExpr) assign.getRightOp();
                    // We have goto that ends up at a cast statement
                    Unit nextStmt = body.getUnits().getSuccOf(assign);
                    if (nextStmt instanceof ReturnStmt) {
                        ReturnStmt retStmt = (ReturnStmt) nextStmt;
                        if (retStmt.getOp() == assign.getLeftOp()) {
                            // We need to replace the GOTO with the return
                            ReturnStmt newStmt = (ReturnStmt) retStmt.clone();
                            newStmt.setOp(ce.getOp());

                            for (Trap t : body.getTraps())
                                for (UnitBox ubox : t.getUnitBoxes())
                                    if (ubox.getUnit() == gtStmt)
                                        ubox.setUnit(newStmt);

                            while (!gtStmt.getBoxesPointingToThis().isEmpty())
                                gtStmt.getBoxesPointingToThis().get(0).setUnit(newStmt);
                            body.getUnits().swapWith(gtStmt, newStmt);
                        }
                    }
                }
            }
        }
    }
}
项目:JAADAS    文件:AsmMethodSource.java   
private void convertReturnInsn(InsnNode insn) {
    int op = insn.getOpcode();
    boolean dword = op == LRETURN || op == DRETURN;
    StackFrame frame = getFrame(insn);
    if (!units.containsKey(insn)) {
        Operand val = dword ? popImmediateDual() : popImmediate();
        ReturnStmt ret = Jimple.v().newReturnStmt(val.stackOrValue());
        val.addBox(ret.getOpBox());
        frame.in(val);
        frame.boxes(ret.getOpBox());
        setUnit(insn, ret);
    } else {
        frame.mergeIn(dword ? popDual() : pop());
    }
}
项目:pipegen    文件:ReturnStatementSink.java   
@Override
public void propagateTaint(UnitGraph graph, Set<Unit> input, Unit node, Set<Unit> output,
                           Set<Value> taintedValues, Queue<MethodAnalysis> queue, Set<MethodAnalysis> processed) {
    assert(isApplicable(graph, input, node, output, taintedValues, queue, processed));

    taintedValues.add(((ReturnStmt)node).getOp());
}
项目:bixie    文件:SootStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt arg0) {
    injectLabelStatements(arg0);
    if (this.procInfo.getReturnVariable() != null) {
        Expression lhs = this.procInfo.getReturnVariable();
        arg0.getOp().apply(this.valueswitch);
        Expression rhs = this.valueswitch.getExpression();
        AssignmentTranslation.translateAssignment(this, lhs, rhs);
    }
    this.boogieStatements.add(this.pf.mkReturnStatement());
}
项目:petablox    文件:FGStmtSwitch.java   
public final void caseReturnStmt(ReturnStmt s) {
statement = s; 
Value op = s.getOp();
if( op.getType() instanceof RefType 
|| op.getType() instanceof ArrayType ) { 
    if( op instanceof Constant ) {
    caseReturnConstStmt( (Constant) op );
    } else {
    caseReturnStmt( (Local) op );
    }
} else {
    caseReturnStmt( (Local) null );
}
  }
项目:petablox    文件:SootUtilities.java   
public static boolean isBranch(Unit u){
    if(u instanceof IfStmt ||
            u instanceof GotoStmt ||
            u instanceof SwitchStmt ||
            u instanceof ThrowStmt ||
            u instanceof ReturnStmt ||
            u instanceof ReturnVoidStmt)
        return true;
    return false;
}
项目:soot-infoflow-android-iccta    文件:ICCInstrumentDestination.java   
public void instrumentOnBindMethod(SootClass sootClass, SootField ibinder_for_ipc)
{
    SootMethod onBindMethod = null;
    try
    {
        onBindMethod = sootClass.getMethodByName("onBind");
    }
    catch (RuntimeException ex)
    {
    }


    if (null == onBindMethod)
    {
        return;
    }

    Body body = onBindMethod.retrieveActiveBody();
    PatchingChain<Unit> units = body.getUnits();
    for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); )
    {
        Stmt stmt = (Stmt) iter.next();

        if (stmt instanceof ReturnStmt)
        {
            ReturnStmt rtStmt = (ReturnStmt) stmt;
            Value rtValue = rtStmt.getOp();

            Unit setIBinderU = Jimple.v().newAssignStmt(
                    Jimple.v().newStaticFieldRef(ibinder_for_ipc.makeRef()), 
                    rtValue);

            units.insertBefore(setIBinderU, rtStmt);
        }

    }


}
项目:jar2bpl    文件:SootStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt arg0) {
    injectLabelStatements(arg0);
    if (this.procInfo.getReturnVariable() != null) {
        Expression lhs = this.procInfo.getReturnVariable();
        arg0.getOp().apply(this.valueswitch);
        Expression rhs = this.valueswitch.getExpression();
        AssignmentTranslation.translateAssignment(this, lhs, rhs);
    }
    this.boogieStatements.add(this.pf.mkReturnStatement());
}
项目:soot-inflow    文件:DefaultSourceSinkManager.java   
@Override
public boolean isSink(Stmt sCallSite, InterproceduralCFG<Unit, SootMethod> cfg) {
    if (super.isSink(sCallSite, cfg))
        return true;

    if (sCallSite instanceof ReturnStmt)
        if (this.returnTaintMethods != null && this.returnTaintMethods.contains
                (cfg.getMethodOf(sCallSite).getSignature()))
            return true;

    return false;
}
项目:android-ssl    文件:FlowGraphUtils.java   
public static boolean allExitsReturnTrue(UnitGraph graph) {
    for (Unit unit : graph.getTails()) {
        if (unit instanceof ReturnStmt) {
            ReturnStmt stmt = (ReturnStmt) unit;
            if (!stmt.getOp().equals(IntConstant.v(1))) {
                return false;
            }
        }
    }

    return true;
}
项目:jgs    文件:AnnotationStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    logger.fine("\n > > > Return statement identified < < <");
    valueSwitch.callingStmt = stmt;
    logger.finer("Use boxes: " + stmt.getUseBoxes().toString());
    Value val = stmt.getUseBoxes().get(0).getValue();
    if (val instanceof Constant) {
        JimpleInjector.returnConstant(stmt);
    } else if (val instanceof Local) {
        JimpleInjector.returnLocal((Local) val, stmt);
    }
}
项目:jgs    文件:AnnotationStmtSwitch.java   
@Override
public void caseReturnStmt(ReturnStmt stmt) {
    logger.fine("\n > > > Return statement identified < < <");
    logger.finer("Use boxes: " + stmt.getUseBoxes().toString());
    Value val = stmt.getUseBoxes().get(0).getValue();
    // JimpleInjector.popGlobalPC();
    if (val instanceof Constant) {
        JimpleInjector.returnConstant(stmt);
    } else if (val instanceof Local) {

        JimpleInjector.returnLocal((Local) val, stmt);
    }
}
项目:boomerang    文件:ForwardFlowFunctions.java   
@Override
public FlowFunction<AccessGraph> getReturnFlowFunction(IPathEdge<Unit, AccessGraph> edge,
    final Unit callStmt, final SootMethod callee, final Unit returnSite) {
  final Local[] paramLocals = new Local[callee.getParameterCount()];
  for (int i = 0; i < callee.getParameterCount(); i++)
    paramLocals[i] = callee.getActiveBody().getParameterLocal(i);
  final Unit exitStmt = edge.getTarget();
  final Local thisLocal = callee.isStatic() ? null : callee.getActiveBody().getThisLocal();
  return new FlowFunction<AccessGraph>() {
    @Override
    public Set<AccessGraph> computeTargets(AccessGraph source) {
      HashSet<AccessGraph> out = new HashSet<AccessGraph>();

      // mapping of fields of AccessPath those will be killed in
      // callToReturn
      if (context.trackStaticFields() && source.isStatic())
        return Collections.singleton(source);

      if (callStmt instanceof Stmt) {
        Stmt is = (Stmt) callStmt;

        if (is.containsInvokeExpr()) {
          InvokeExpr ie = is.getInvokeExpr();
          for (int i = 0; i < paramLocals.length; i++) {

            if (paramLocals[i] == source.getBase()) {
              Value arg = ie.getArg(i);
              if (arg instanceof Local) {
                if (typeCompatible(((Local) arg).getType(), source.getBaseType())) {
                  AccessGraph deriveWithNewLocal =
                      source.deriveWithNewLocal((Local) arg, source.getBaseType());
                  out.add(deriveWithNewLocal);
                }
              }

            }
          }
          if (!callee.isStatic() && ie instanceof InstanceInvokeExpr) {
            if (source.baseMatches(thisLocal)) {

              InstanceInvokeExpr iIExpr = (InstanceInvokeExpr) is.getInvokeExpr();
              Local newBase = (Local) iIExpr.getBase();
              if (typeCompatible(newBase.getType(), source.getBaseType())) {
                AccessGraph possibleAccessPath =
                    source.deriveWithNewLocal((Local) iIExpr.getBase(), source.getBaseType());
                out.add(possibleAccessPath);
              }
            }
          }
        }
      }

      if (callStmt instanceof AssignStmt && exitStmt instanceof ReturnStmt) {
        AssignStmt as = (AssignStmt) callStmt;
        Value leftOp = as.getLeftOp();
        // mapping of return value


        ReturnStmt returnStmt = (ReturnStmt) exitStmt;
        Value returns = returnStmt.getOp();
        // d = return out;
        if (leftOp instanceof Local) {
          if (returns instanceof Local && source.getBase() == returns) {
            out.add(source.deriveWithNewLocal((Local) leftOp, source.getBaseType()));
          }
        }
      }
      return out;
    }

  };
}
项目:JAADAS    文件:StmtTranslator.java   
public void caseReturnStmt(ReturnStmt stmt) {
    Variable rvar = jt.makeVariable(stmt.getOp());
    Return r = new Return();
    r.setAssignmentTarget(rvar);
    addStatement(r);
}
项目:JAADAS    文件:StmtTemplatePrinter.java   
public void caseReturnStmt(ReturnStmt stmt) {
    String varName = printValueAssignment(stmt.getOp(), "retVal");
    printStmt(stmt,varName);
}
项目:JAADAS    文件:UseChecker.java   
public void caseReturnStmt(ReturnStmt stmt)
{
    stmt.setOp(this.uv.visit(
        stmt.getOp(), this.jb.getMethod().getReturnType(), stmt));
}
项目:JAADAS    文件:DexReturnInliner.java   
private boolean isInstanceofReturn(Unit u) {
    if (u instanceof ReturnStmt || u instanceof ReturnVoidStmt)
        return true;
    return false;
}
项目:JAADAS    文件:DexReturnValuePropagator.java   
@Override
protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
       ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v(), true);
       LocalDefs localDefs = LocalDefs.Factory.newLocalDefs(graph);
       LocalUses localUses = null;
       LocalCreation localCreation = null;

    // If a return statement's operand has only one definition and this is
    // a copy statement, we take the original operand
    for (Unit u : body.getUnits())
        if (u instanceof ReturnStmt) {
            ReturnStmt retStmt = (ReturnStmt) u;
            if (retStmt.getOp() instanceof Local) {
                List<Unit> defs = localDefs.getDefsOfAt((Local) retStmt.getOp(), retStmt);
                if (defs.size() == 1 && defs.get(0) instanceof AssignStmt) {
                    AssignStmt assign = (AssignStmt) defs.get(0);
                    final Value rightOp = assign.getRightOp();
                    final Value leftOp = assign.getLeftOp();

                    // Copy over the left side if it is a local
                    if (rightOp instanceof Local) {
                        // We must make sure that the definition we propagate to
                        // the return statement is not overwritten in between
                        // a = 1; b = a; a = 3; return b; may not be translated
                        // to return a;
                        if (!isRedefined((Local) rightOp, u, assign, graph))
                            retStmt.setOp(rightOp);
                    }
                    else if (rightOp instanceof Constant) {
                        retStmt.setOp(rightOp);
                    }
                    // If this is a field access which has no other uses,
                    // we rename the local to help splitting
                    else if (rightOp instanceof FieldRef) {
                        if (localUses == null)
                            localUses = LocalUses.Factory.newLocalUses(body, localDefs);
                        if (localUses.getUsesOf(assign).size() == 1) {
                            if (localCreation == null)
                                localCreation = new LocalCreation(body.getLocals(), "ret");
                            Local newLocal = localCreation.newLocal(leftOp.getType());
                            assign.setLeftOp(newLocal);
                            retStmt.setOp(newLocal);
                        }
                    }
                }
            }
        }
}
项目:JAADAS    文件:StructuredAnalysis.java   
/**
 * Whenever a statement has to be processed the first step is to invoke this
 * method. This is to remove the tedious work of adding code to deal with
 * abrupt control flow from the programmer of the analysis. The method
 * invokes the processStatement method for all other statements
 * 
 * A programmer can decide to override this method if they want to do
 * something specific
 */
public DavaFlowSet processAbruptStatements(Stmt s, DavaFlowSet input) {
    if (s instanceof ReturnStmt || s instanceof RetStmt || s instanceof ReturnVoidStmt) {
        // dont need to remember this path
        return NOPATH;
    } else if (s instanceof DAbruptStmt) {
        DAbruptStmt abStmt = (DAbruptStmt) s;

        // see if its a break or continue
        if (!(abStmt.is_Continue() || abStmt.is_Break())) {
            // DAbruptStmt is of only two kinds
            throw new RuntimeException("Found a DAbruptStmt which is neither break nor continue!!");
        }

        DavaFlowSet temp = NOPATH;
        SETNodeLabel nodeLabel = abStmt.getLabel();
        // System.out.println("here");
        if (nodeLabel != null && nodeLabel.toString() != null) {
            // explicit abrupt stmt
            if (abStmt.is_Continue())
                temp.addToContinueList(nodeLabel.toString(), input);
            else if (abStmt.is_Break())
                temp.addToBreakList(nodeLabel.toString(), input);
            else
                throw new RuntimeException("Found abruptstmt which is neither break nor continue");
        } else {
            // found implicit break/continue
            if (abStmt.is_Continue())
                temp.addToImplicitContinues(abStmt, input);
            else if (abStmt.is_Break())
                temp.addToImplicitBreaks(abStmt, input);
            else
                throw new RuntimeException("Found abruptstmt which is neither break nor continue");
        }
        return temp;
    } else {
        /**************************************************************/
        /****** ALL OTHER STATEMENTS HANDLED BY PROGRAMMER **************/
        /**************************************************************/
        return processStatement(s, input);
    }
}
项目:JAADAS    文件:UnreachableCodeFinder.java   
@Override
public DavaFlowSet processAbruptStatements(Stmt s, DavaFlowSet input){
    if(DEBUG)   System.out.println("processing stmt "+s);
    if(s instanceof ReturnStmt || s instanceof RetStmt || s instanceof ReturnVoidStmt){
        //dont need to remember this path
        UnreachableCodeFlowSet toReturn = new UnreachableCodeFlowSet();
        toReturn.add(new Boolean(false));
        toReturn.copyInternalDataFrom(input);
        //false indicates NOPATH
        if(DEBUG)   System.out.println("\tstmt is a return stmt. Hence sending forward false");
        return toReturn;
    }
    else if(s instanceof DAbruptStmt){
        DAbruptStmt abStmt = (DAbruptStmt)s;

        //see if its a break or continue
        if(!(abStmt.is_Continue()|| abStmt.is_Break())){
            //DAbruptStmt is of only two kinds
            throw new RuntimeException("Found a DAbruptStmt which is neither break nor continue!!");
        }           

        DavaFlowSet temp = new UnreachableCodeFlowSet();
        SETNodeLabel nodeLabel = abStmt.getLabel();

        //        notice we ignore continues for this analysis
        if (abStmt.is_Break()){
            if(nodeLabel != null && nodeLabel.toString() != null){
                //explicit break stmt           
                temp.addToBreakList(nodeLabel.toString(),input);            
            }
            else{
                //found implicit break
                temp.addToImplicitBreaks(abStmt,input);             
            }
        }
        temp.add(new Boolean(false));
        temp.copyInternalDataFrom(input);
        if(DEBUG)   System.out.println("\tstmt is an abrupt stmt. Hence sending forward false");
        return temp;
    }
    else{
        if(DEBUG)   System.out.println("\tstmt is not an abrupt stmt.");
        return processStatement(s,input);
    }
   }
项目:JAADAS    文件:UnitThrowAnalysis.java   
@Override
    public void caseReturnStmt(ReturnStmt s) {
//      result = result.add(mgr.ILLEGAL_MONITOR_STATE_EXCEPTION);
//      result = result.add(mightThrow(s.getOp()));
    }
项目:pipegen    文件:ReturnStatementSink.java   
@Override
public boolean isApplicable(UnitGraph graph, Set<Unit> input, Unit node, Set<Unit> output,
                            Set<Value> taintedValues, Queue<MethodAnalysis> queue, Set<MethodAnalysis> processed) {
    return node instanceof ReturnStmt &&
           isApplicable(graph, input, (ReturnStmt)node, output, queue, processed);
}