Java 类soot.jimple.IdentityStmt 实例源码

项目:JAADAS    文件:ConstraintChecker.java   
public void caseIdentityStmt(IdentityStmt stmt) {
    Value l = stmt.getLeftOp();
    Value r = stmt.getRightOp();

    if (l instanceof Local) {
        if (((Local) l).getType() instanceof IntegerType) {
            TypeNode left = ClassHierarchy.v().typeNode(
                    (((Local) l).getType()));
            TypeNode right = ClassHierarchy.v().typeNode(r.getType());

            if (!right.hasAncestor_1(left)) {
                if (fix) {
                    ((soot.jimple.internal.JIdentityStmt) stmt)
                            .setLeftOp(insertCastAfter((Local) l,
                                    getTypeForCast(left),
                                    getTypeForCast(right), stmt));
                } else {
                    error("Type Error(16)");
                }
            }
        }
    }
}
项目:JAADAS    文件:ConstraintCollector.java   
public void caseIdentityStmt(IdentityStmt stmt) {
    Value l = stmt.getLeftOp();
    Value r = stmt.getRightOp();

    if (l instanceof Local) {
        TypeVariable left = resolver.typeVariable((Local) l);

        if (!(r instanceof CaughtExceptionRef)) {
            TypeVariable right = resolver.typeVariable(r.getType());
            right.addParent(left);
        } else {
            List<RefType> exceptionTypes = TrapManager.getExceptionTypesOf(stmt, stmtBody);
            Iterator<RefType> typeIt = exceptionTypes.iterator();

            while (typeIt.hasNext()) {
                Type t = typeIt.next();

                resolver.typeVariable(t).addParent(left);
            }

            if (uses) {
                left.addParent(resolver.typeVariable(RefType.v("java.lang.Throwable")));
            }
        }
    }
}
项目:JAADAS    文件:StmtVisitor.java   
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
    Value lhs = stmt.getLeftOp();
    Value rhs = stmt.getRightOp();
    if (rhs instanceof CaughtExceptionRef) {
        // save the caught exception with move-exception
        Register localReg = regAlloc.asLocal(lhs);

           addInsn(new Insn11x(Opcode.MOVE_EXCEPTION, localReg), stmt);

           this.insnRegisterMap.put(insns.get(insns.size() - 1), LocalRegisterAssignmentInformation.v(localReg, (Local)lhs));
    } else if (rhs instanceof ThisRef || rhs instanceof ParameterRef) {
        /* 
         * do not save the ThisRef or ParameterRef in a local, because it always has a parameter register already.
         * at least use the local for further reference in the statements
         */
        Local localForThis = (Local) lhs;
        regAlloc.asParameter(belongingMethod, localForThis);

        parameterInstructionsList.add(LocalRegisterAssignmentInformation.v(regAlloc.asLocal(localForThis).clone(), localForThis));
    } else {
        throw new Error("unknown Value as right-hand side of IdentityStmt: " + rhs);
    }
}
项目:JAADAS    文件:SynchronizedMethodTransformer.java   
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
    if (!b.getMethod().isSynchronized() || b.getMethod().isStatic())
        return;

    Iterator<Unit> it = b.getUnits().snapshotIterator();
    while (it.hasNext()) {
        Unit u = it.next();
        if (u instanceof IdentityStmt)
            continue;

        // This the first real statement. If it is not a MonitorEnter
        // instruction, we generate one
        if (!(u instanceof EnterMonitorStmt)) {
            b.getUnits().insertBeforeNoRedirect(Jimple.v().newEnterMonitorStmt(b.getThisLocal()), u);

            // We also need to leave the monitor when the method terminates
            UnitGraph graph = new ExceptionalUnitGraph(b);
            for (Unit tail : graph.getTails())
                b.getUnits().insertBefore(Jimple.v().newExitMonitorStmt(b.getThisLocal()), tail);
        }
        break;
    }
}
项目:JAADAS    文件:Body.java   
/** Return LHS of the first identity stmt assigning from \@parameter i. **/
public Local getParameterLocal(int i)
{
    for (Unit s : getUnits())
    {
        if (s instanceof IdentityStmt &&
            ((IdentityStmt)s).getRightOp() instanceof ParameterRef)
        {
            IdentityStmt is = (IdentityStmt)s;
            ParameterRef pr = (ParameterRef)is.getRightOp();
            if (pr.getIndex() == i)
                return (Local)is.getLeftOp();
        }
    }

    throw new RuntimeException("couldn't find parameterref" + i +"! in "+getMethod());
}
项目:JAADAS    文件:Body.java   
/**
 * Get all the LHS of the identity statements assigning from parameter references.
 *
 * @return a list of size as per <code>getMethod().getParameterCount()</code> with all elements ordered as per the parameter index.
 * @throws RuntimeException if a parameterref is missing
 */
public List<Local> getParameterLocals(){
    final int numParams = getMethod().getParameterCount();
    final List<Local> retVal = new ArrayList<Local>(numParams);

    //Parameters are zero-indexed, so the keeping of the index is safe
    for (Unit u : getUnits()){
        if (u instanceof IdentityStmt){
            IdentityStmt is = ((IdentityStmt)u);
            if (is.getRightOp() instanceof ParameterRef){
                ParameterRef pr = (ParameterRef) is.getRightOp();
                retVal.add(pr.getIndex(), (Local) is.getLeftOp());
            }
        }
    }
    if (retVal.size() != numParams){
        //FLANKER FIX BEGIN
        //throw new RuntimeException("couldn't find parameterref! in " + getMethod());
        return retVal;
        //FLANKER FIX END
    }
    return retVal;
}
项目:DroidRA    文件:DummyMainGenerator.java   
public void instrumentDummyMainMethod(SootMethod mainMethod)
{
    Body body = mainMethod.getActiveBody();

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

        if (stmt instanceof IdentityStmt)
        {
            continue;
        }

        //For the purpose of confusion dex optimization (because of the strategy of generating dummyMain method)
        AssignStmt aStmt = (AssignStmt) stmt;
        SootMethod fuzzyMe = generateFuzzyMethod(mainMethod.getDeclaringClass());
        InvokeExpr invokeExpr = Jimple.v().newVirtualInvokeExpr(body.getThisLocal(), fuzzyMe.makeRef());
        Unit assignU = Jimple.v().newAssignStmt(aStmt.getLeftOp(), invokeExpr);
        units.insertAfter(assignU, aStmt);

        break;
    }
}
项目:petablox    文件:SSAUtilities.java   
public static void removeMoves(SootMethod m) {
    List<Unit> moves = new ArrayList<Unit>();
    Body b = m.retrieveActiveBody();
    PatchingChain<Unit> upc = b.getUnits();
    Iterator<Unit> uit = upc.iterator();
    while (uit.hasNext()) {
        Unit u = (Unit)uit.next();
        if (!(u instanceof IdentityStmt) && (u instanceof JAssignStmt) && SootUtilities.isMoveInst((JAssignStmt)u))
            moves.add(u);       
    }

    for (int i = 0; i < moves.size(); i++) {
        JAssignStmt curr = (JAssignStmt)moves.get(i);
        Local left = (Local)curr.leftBox.getValue();
        Local right = (Local)curr.rightBox.getValue();
        Unit currSucc = upc.getSuccOf(curr);
            moveLabel(m, curr, currSucc);
            upc.remove(curr);
            List<ValueBox> useList = b.getUseBoxes();
            for (int j = 0; j < useList.size(); j++) {
                if (useList.get(j).getValue() == left)
                    useList.get(j).setValue(right);
            }
    }   
}
项目:petablox    文件:FGStmtSwitch.java   
public final void caseIdentityStmt(IdentityStmt s) {
statement = s;
Value lhs = s.getLeftOp();
Value rhs = s.getRightOp();
if( !( lhs.getType() instanceof RefType ) 
&& !(lhs.getType() instanceof ArrayType ) ) {
     caseUninterestingStmt( s );
     return;
}
Local llhs = (Local) lhs;
if( rhs instanceof CaughtExceptionRef ) {
    caseCatchStmt( llhs, (CaughtExceptionRef) rhs );
} else {
    IdentityRef rrhs = (IdentityRef) rhs;
    caseIdentityStmt( llhs, rrhs );
}
  }
项目:soot-infoflow-android-iccta    文件:SootHelper.java   
public static Stmt getFirstNonIdentityStmt(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 IdentityStmt) )
        {
            rtVal = stmt;
        }
    }

    return rtVal;
}
项目:FlowTwist    文件:SeedFactory.java   
@Override
public Set<Unit> initialSeeds(AnalysisContext config) {
    Set<Unit> res = Sets.newHashSet();
    for (Iterator<MethodOrMethodContext> iter = Scene.v().getReachableMethods().listener(); iter.hasNext();) {
        SootMethod m = iter.next().method();
        if (AnalysisUtil.methodMayBeCallableFromApplication(m) && m.hasActiveBody()) {
            ActiveBodyVerifier.assertActive(m);
            PatchingChain<Unit> units = m.getActiveBody().getUnits();
            for (Unit u : units) {
                if (u instanceof IdentityStmt) {
                    IdentityStmt idStmt = (IdentityStmt) u;

                    if (idStmt.getRightOp().toString().contains("@parameter"))
                        res.add(u);
                }
            }
        }
    }
    System.out.println("forwards from all parameters initial seeds: " + res.size());
    return res;
}
项目:FlowTwist    文件:SeedFactory.java   
@Override
public Set<Unit> initialSeeds(AnalysisContext config) {
    Set<Unit> res = Sets.newHashSet();
    for (Iterator<MethodOrMethodContext> iter = Scene.v().getReachableMethods().listener(); iter.hasNext();) {
        SootMethod m = iter.next().method();
        if (AnalysisUtil.methodMayBeCallableFromApplication(m) && m.hasActiveBody()) {
            ActiveBodyVerifier.assertActive(m);
            PatchingChain<Unit> units = m.getActiveBody().getUnits();
            for (Unit u : units) {
                if (u instanceof IdentityStmt) {
                    IdentityStmt idStmt = (IdentityStmt) u;

                    if (idStmt.getRightOp().toString().contains("@parameter")
                            && idStmt.getRightOp().getType().toString().equals("java.lang.String"))
                        res.add(u);
                }
            }
        }
    }
    System.out.println("forwards from string parameters initial seeds: " + res.size());
    return res;
}
项目:FlowTwist    文件:ArgumentSourceHandler.java   
@Override
public KillGenInfo propagateNormalFlow(Trackable taint, Unit curr, Unit succ) {
    if (!(curr instanceof IdentityStmt))
        return identity();
    IdentityStmt idStmt = (IdentityStmt) curr;
    Value left = AnalysisUtil.getBackwardsBase(idStmt.getLeftOp());

    Taint t = (Taint) taint;

    if (!AnalysisUtil.maybeSameLocation(t.value, left))
        return identity();

    if (idStmt.getRightOp() instanceof ParameterRef) {
        if (t.value instanceof Local) {
            SootMethod m = context.icfg.getMethodOf(idStmt);
            if (AnalysisUtil.methodMayBeCallableFromApplication(m) && transitiveSinkCaller.isTransitiveCallerOfAnySink(m)) {
                context.reporter.reportTrackable(new Report(context, taint, curr));
            }
        }
    }
    return identity();
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
private Value[] getParameterValues(SootMethod destinationMethod) {
    int paramsFound = 0;
    Value[] result = new Value[destinationMethod.getParameterCount()];
    for (Unit unit : destinationMethod.getActiveBody().getUnits()) {
        if (!(unit instanceof IdentityStmt))
            continue;

        Value rightOp = ((IdentityStmt) unit).getRightOp();
        if (!(rightOp instanceof ParameterRef))
            continue;

        ParameterRef paramRef = (ParameterRef) rightOp;
        result[paramRef.getIndex()] = paramRef;
        paramsFound++;

        if (paramsFound == result.length)
            break;
    }
    return result;
}
项目:bladedroid    文件:Util.java   
public static Local findparamlocal(PatchingChain<Unit> units) {
    // TODO HACK! assume the second identity stmt is always for the required
    // parameter
    boolean thislocalseen = false;
    for (Unit unit : units)
    {
        if (unit instanceof IdentityStmt)
        {
            if (thislocalseen)
            {
                IdentityStmt istmt = (IdentityStmt) unit;
                return (Local) istmt.getLeftOp();
            }
            else
            {
                thislocalseen = true;
            }
        }
    }
    throw new RuntimeException("Parameter Local not found (maybe method has no parameters?)");
}
项目:bladedroid    文件:Util.java   
public static Local findsecondparamlocal(PatchingChain<Unit> units)
{
    // TODO HACK! assume the second identity stmts are in the order
    // "this","param1","param2"...
    int localsseen = 0;
    for (Unit unit : units)
    {
        if (unit instanceof IdentityStmt)
        {
            if (localsseen == 2)
            {
                IdentityStmt istmt = (IdentityStmt) unit;
                return (Local) istmt.getLeftOp();
            }

            localsseen++;
        }
    }
    throw new RuntimeException("Parameter Local not found (maybe method has no parameters?)");
}
项目:jgs    文件:AnnotationStmtSwitch.java   
@Override
public void caseIdentityStmt(IdentityStmt stmt) {

    AnnotationValueSwitch valueSwitch = new AnnotationValueSwitch(stmt, StmtContext.IDENTITY);

    logger.fine("\n > > > Identity statement identified < < <");

    // for all statements i = parameter[0]
    if (stmt.getRightOp() instanceof ParameterRef) {
        if (!body.getMethod().isMain()) {
            int posInArgList = ((ParameterRef) stmt.getRightOp())
                    .getIndex();
            JimpleInjector.assignArgumentToLocal(posInArgList,
                       (Local) stmt.getLeftOp());
        }
    } else if (stmt.getRightOp() instanceof ThisRef) {
        // TODO im Grunde nicht nötig...
    } else if (stmt.getRightOp() instanceof CaughtExceptionRef) {
        logger.fine("Right operand in IdentityStmt is a CaughtException");
        throw new InternalAnalyzerException("Catching exceptions is not supported");
    } else {
        throw new InternalAnalyzerException(
                "Unexpected type of right value "
                        + stmt.getRightOp().toString() + " in IdentityStmt");
    }
}
项目:FuzzDroid    文件:CodePositionTracking.java   
@Override
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {       
    // Do not instrument methods in framework classes
    if (!canInstrumentMethod(b.getMethod()))
        return;

    // Make a reference to the tracker method
    SootMethodRef ref = Scene.v().makeMethodRef(
            Scene.v().getSootClass(UtilInstrumenter.JAVA_CLASS_FOR_CODE_POSITIONS),
            "setLastExecutedStatement",
            Collections.<Type>singletonList(IntType.v()),
            VoidType.v(),
            true);
    final String methodSig = b.getMethod().getSignature();

    // Iterate over all the units and add a unit that sets the current
    // execution pointer
    int curLineNum = 0;
    for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext(); ) {
        Unit curUnit = unitIt.next();

        // If we're still inside the IdentityStmt block, there's nothing to
        // instrument
        if (curUnit instanceof IdentityStmt ||
                // If this unit was instrumented by another transformer, there's nothing to instrument
                curUnit.hasTag(InstrumentedCodeTag.name))
            continue;

        // Get the current code positions
        CodePosition codePos = codePositionManager.getCodePositionForUnit(curUnit,
                methodSig, curLineNum++, ((Stmt) curUnit).getJavaSourceStartLineNumber());

        Stmt setCodePosStmt = Jimple.v().newInvokeStmt(
                Jimple.v().newStaticInvokeExpr(ref, IntConstant.v(codePos.getID())));
        setCodePosStmt.addTag(new InstrumentedCodeTag());

        b.getUnits().insertAfter(setCodePosStmt, curUnit);
    }
}
项目:FuzzDroid    文件:CrashReporterInjection.java   
@Override
protected void internalTransform(String phaseName,
        Map<String, String> options) {
    // Make a reference to the registration method
    SootMethodRef ref = Scene.v().makeMethodRef(
            Scene.v().getSootClass(UtilInstrumenter.JAVA_CLASS_FOR_CRASH_REPORTING),
            "registerExceptionHandler",
            Collections.<Type>emptyList(),
            VoidType.v(),
            true);

    for (String sig : methodsToInstrument) {
        try{
            SootMethod sm = Scene.v().grabMethod(sig);
            if(sm == null)
                continue;

            for (Iterator<Unit> unitIt = sm.getActiveBody().getUnits()
                    .snapshotIterator(); unitIt.hasNext(); ) {
                Unit curUnit = unitIt.next();

                // If we're still inside the IdentityStmt block, there's nothing to
                // instrument
                if (curUnit instanceof IdentityStmt)
                    continue;

                // Put the registration in
                Stmt stmt = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(ref));
                stmt.addTag(new InstrumentedCodeTag());                 
                sm.getActiveBody().getUnits().insertAfter(stmt, curUnit);
                break;
            }
        }catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
项目:visuflow-plugin    文件:IdentityStmtFormatter.java   
@Override
public String format(Unit u, int maxLength) {
    IdentityStmt identityStmt = (IdentityStmt) u;
    String s = ValueFormatter.format(identityStmt.getLeftOp()) + " := " + ValueFormatter.format(identityStmt.getRightOp());

    if(s.length() > maxLength) {
        s = s.substring(0, maxLength) + "\u2026";
    }

    return s;
}
项目:permission-map    文件:HandleContentProviders.java   
private String findUriDef(Body b, Unit u, Local l) {
    final UnitGraph g = new ExceptionalUnitGraph(b);
    final SmartLocalDefs localDefs = new SmartLocalDefs(g, new SimpleLiveLocals(g));
    final SimpleLocalUses localUses = new SimpleLocalUses(g, localDefs);

    List<Unit> defs = localDefs.getDefsOfAt((Local) l, u);
    if (defs.size() == 0) {
        System.out.println("warning: uri def empty!");
        return null;
    }
    Unit def = defs.get(0);
    logger.debug("uri def: " + def);
    if (def instanceof IdentityStmt) {
        System.out.println("warning: do not handle uri from identity stmt");
        return null;
    } else if (def instanceof AssignStmt) {
        AssignStmt ass = (AssignStmt) def;
        Value r = ass.getRightOp();
        if (r instanceof FieldRef) {
            FieldRef fr = (FieldRef) r;
            SootField sf = fr.getField();
            if (sf.getName().contains("URI")) {
                String auth = getFieldFromClass(sf);
                return auth;
            }
        } else {
            System.out.println("warning: uri: do not handle def '" + def + "'");
            return null;
        }
    }
    return null;
}
项目:permission-map    文件:HandleThreads.java   
private void insertAfter(Body b, Unit newU, Unit u) {
    Unit afterThisU = u;
    // we suppose there is at least one instruction after
    // the identity statements
    while (afterThisU instanceof IdentityStmt) {
        u = afterThisU;
        afterThisU = b.getUnits().getSuccOf(afterThisU);
    }
    b.getUnits().insertAfter(newU, u);
}
项目:JAADAS    文件:InterproceduralConstantValuePropagator.java   
/**
 * Gets the first statement in the body of the given method that does not
 * assign the "this" local or a parameter local
 * @param sm The method in whose body to look
 * @return The first non-identity statement in the body of the given method.
 */
private Unit getFirstNonIdentityStmt(SootMethod sm) {
    for (Unit u : sm.getActiveBody().getUnits()) {
        if (!(u instanceof IdentityStmt))
            return u;

        IdentityStmt id = (IdentityStmt) u;
        if (!(id.getRightOp() instanceof ThisRef)
                && !(id.getRightOp() instanceof ParameterRef))
            return u;
    }
    return null;
}
项目:JAADAS    文件:ThisInliner.java   
private IdentityStmt findIdentityStmt(Body b){
    for (Unit u : b.getUnits()) {
        Stmt s = (Stmt)u;
        if ((s instanceof IdentityStmt) && (((IdentityStmt)s).getRightOp() instanceof ThisRef)){
            return (IdentityStmt)s;
        }
    }
    return null;
}
项目:JAADAS    文件:ConstraintCollector.java   
public void caseIdentityStmt(IdentityStmt stmt) {
    Value l = stmt.getLeftOp();
    Value r = stmt.getRightOp();

    if (l instanceof Local) {
        if (((Local) l).getType() instanceof IntegerType) {
            TypeVariable left = resolver.typeVariable((Local) l);

            TypeVariable right = resolver.typeVariable(r.getType());
            right.addParent(left);
        }
    }
}
项目:JAADAS    文件:Util.java   
/**
 * A new "normal" statement cannot be inserted in the middle of special
 * "identity statements" (a = @parameter or b = @this in Jimple).
 * 
 * This method returns the last "identity statement" of the method.
 * @param b
 * @param s
 * @return
 */
public static Unit findLastIdentityUnit(Body b, Stmt s) {
    Unit u2 = s;
    Unit u1 = s;
    while (u1 instanceof IdentityStmt) {
        u2 = u1;
        u1 = b.getUnits().getSuccOf(u1);
    }
    return u2;
}
项目:JAADAS    文件:Util.java   
/**
 * Returns the first statement after all the "identity statements".
 * @param b
 * @param s
 * @return
 */
public static Unit findFirstNonIdentityUnit(Body b, Stmt s) {
    Unit u1 = s;
    while (u1 instanceof IdentityStmt)
        u1 = b.getUnits().getSuccOf(u1);
    return u1;
}
项目:JAADAS    文件:FastDexTrapTightener.java   
private boolean isDexInstruction(Unit unit) {
    if (unit instanceof IdentityStmt) {
        IdentityStmt is = (IdentityStmt) unit;
        return !(is.getRightOp() instanceof ThisRef
                || is.getRightOp() instanceof ParameterRef);
    }
    return true;
}
项目:JAADAS    文件:Body.java   
/** Return LHS of the first identity stmt assigning from \@this. **/
public Local getThisLocal()
{
    for (Unit s : getUnits())
    {
        if (s instanceof IdentityStmt &&
            ((IdentityStmt)s).getRightOp() instanceof ThisRef)
            return (Local)(((IdentityStmt)s).getLeftOp());
    }

    throw new RuntimeException("couldn't find identityref!"+" in "+getMethod());
}
项目:JAADAS    文件:Body.java   
/**
  * Returns the list of parameter references used in this body. The list is as long as
  * the number of parameters declared in the associated method's signature.
  * The list may have <code>null</code> entries for parameters not referenced in the body.
  * The returned list is of fixed size.
  */
 public List<Value> getParameterRefs()
 {
    Value[] res = new Value[getMethod().getParameterCount()];
     for (Unit s : getUnits()) {
         if (s instanceof IdentityStmt) {
    Value rightOp = ((IdentityStmt)s).getRightOp();
    if (rightOp instanceof ParameterRef) {
        ParameterRef parameterRef = (ParameterRef) rightOp;
        res[parameterRef.getIndex()] = parameterRef;
    }
}
     }
     return Arrays.asList(res);
 }
项目:pipegen    文件:ParameterSinkExpression.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 !input.isEmpty() &&
           node instanceof IdentityStmt &&
           ((IdentityStmt)node).getRightOp() instanceof ParameterRef;
}
项目:pipegen    文件:ParameterSinkExpression.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));

    //TODO isApplicable should have access to tainted values...
    if(isTainted(taintedValues, node))
        queue.addAll(getCallers(graph.getBody().getMethod(),
                     ((IdentityStmt) node).getRightOp()));
}
项目:soot-inflow    文件:DefaultSourceSinkManager.java   
@Override
public boolean isSource(Stmt sCallSite, InterproceduralCFG<Unit, SootMethod> cfg) {
    if (super.isSource(sCallSite, cfg))
        return true;

    if (sCallSite instanceof IdentityStmt) {
        IdentityStmt is = (IdentityStmt) sCallSite;
        if (is.getRightOp() instanceof ParameterRef)
            if (this.parameterTaintMethods != null && this.parameterTaintMethods.contains
                    (cfg.getMethodOf(sCallSite).getSignature()))
                return true;
    }

    return false;
}
项目:FlowTwist    文件:SeedFactory.java   
@Override
public Set<Unit> initialSeeds(AnalysisContext config) {
    List<Unit> worklist = Lists.newLinkedList((new I2OSeedFactory().initialSeeds(config)));
    Set<SootMethod> visited = Sets.newHashSet();
    Set<Unit> result = Sets.newHashSet();

    while (!worklist.isEmpty()) {
        Unit current = worklist.remove(0);
        SootMethod method = config.icfg.getMethodOf(current);
        if (visited.add(method)) {
            if (AnalysisUtil.methodMayBeCallableFromApplication(method)) {
                PatchingChain<Unit> units = method.getActiveBody().getUnits();
                for (Unit u : units) {
                    if (u instanceof IdentityStmt) {
                        IdentityStmt idStmt = (IdentityStmt) u;

                        if (idStmt.getRightOp().toString().contains("@parameter"))
                            result.add(u);
                    }
                }
            } else {
                worklist.addAll(config.icfg.getCallersOf(method));
            }
        }
    }

    System.out.println("forwards from all transitive callers parameters initial seeds: " + result.size());
    return result;
}
项目:FlowTwist    文件:SeedFactory.java   
@Override
public Set<Unit> initialSeeds(AnalysisContext config) {
    List<Unit> worklist = Lists.newLinkedList((new I2OSeedFactory().initialSeeds(config)));
    Set<SootMethod> visited = Sets.newHashSet();
    Set<Unit> result = Sets.newHashSet();

    while (!worklist.isEmpty()) {
        Unit current = worklist.remove(0);
        SootMethod method = config.icfg.getMethodOf(current);
        if (visited.add(method)) {
            if (AnalysisUtil.methodMayBeCallableFromApplication(method)) {
                PatchingChain<Unit> units = method.getActiveBody().getUnits();
                for (Unit u : units) {
                    if (u instanceof IdentityStmt) {
                        IdentityStmt idStmt = (IdentityStmt) u;

                        if (idStmt.getRightOp().toString().contains("@parameter")
                                && idStmt.getRightOp().getType().toString().equals("java.lang.String"))
                            result.add(u);
                    }
                }
            } else {
                worklist.addAll(config.icfg.getCallersOf(method));
            }
        }
    }

    System.out.println("forwards from string transitive callers parameters initial seeds: " + result.size());
    return result;
}
项目:FlowTwist    文件:DefaultTaintPropagator.java   
public Value getParameter(SootMethod destinationMethod, int i) {
    Iterator<Unit> unitsIt = destinationMethod.getActiveBody().getUnits().iterator();
    while (unitsIt.hasNext()) {
        Unit s = unitsIt.next();
        if (s instanceof IdentityStmt) {
            Value rightOp = ((IdentityStmt) s).getRightOp();
            if (rightOp instanceof ParameterRef && ((ParameterRef) rightOp).getIndex() == i) {
                return rightOp;
            }
        }
    }

    throw new RuntimeException("couldn't find parameterref for index " + i + " in " + destinationMethod);
}
项目:FlowTwist    文件:ZeroAtParameterHandler.java   
public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) {
    if (curr instanceof IdentityStmt) {
        IdentityStmt idStmt = (IdentityStmt) curr;
        if (idStmt.getRightOp().toString().contains("@parameter")) {
            if (context.type == Type.ForwardsFromAllParameters || idStmt.getRightOp().getType().toString().equals("java.lang.String"))
                return KillGenInfo.propagate(new Taint(curr, trackable, idStmt.getLeftOp(), idStmt.getLeftOp().getType()));
        }
    }

    return KillGenInfo.kill();
}
项目:bladedroid    文件:Util.java   
public static void insertAfterIdentityStmt(PatchingChain<Unit> units,
        Chain<Unit> toInsert) {
    Unit point = null;
    Iterator<Unit> unitIt = units.snapshotIterator();
    boolean foundIdentityStmt = false;
    while (unitIt.hasNext())
    {
        Unit unit = unitIt.next();
        if (!(unit instanceof IdentityStmt) && !(unit instanceof EnterMonitorStmt))
        {
            point = units.getPredOf(unit);
            break;
        }
        else
        {
            foundIdentityStmt = true;
        }
    }
    if (point == null && foundIdentityStmt)
    {
        point = units.getLast();
    }
    else if (point == null && !foundIdentityStmt)
    {
        units.insertBefore(toInsert, units.getFirst());
    }
    units.insertAfter(toInsert, point);
}
项目:bladedroid    文件:Util.java   
public static Local findthislocal(Chain<Unit> units)
{
    // TODO: HACK! assume the first identity stmt is always for 'this'
    for (Unit unit : units)
    {
        if (unit instanceof IdentityStmt)
        {
            IdentityStmt istmt = (IdentityStmt) unit;
            return (Local) istmt.getLeftOp();
        }
    }
    return null;
}
项目:jgs    文件:SecurityConstraintStmtSwitch.java   
@Override
public void caseIdentityStmt(IdentityStmt stmt) {
    SecurityConstraintValueWriteSwitch writeSwitch =
        getWriteSwitch(stmt.getLeftOp());
    SecurityConstraintValueReadSwitch readSwitch =
        getReadSwitch(stmt.getRightOp());
    handleReadAndWriteStmt(writeSwitch, readSwitch);

}