Search in sources :

Example 31 with Unit

use of soot.Unit in project soot by Sable.

the class Util method findLastIdentityUnit.

/**
 * 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;
}
Also used : Unit(soot.Unit) IdentityStmt(soot.jimple.IdentityStmt)

Example 32 with Unit

use of soot.Unit in project soot by Sable.

the class SparkTransformer method addTags.

protected void addTags(PAG pag) {
    final Tag unknown = new StringTag("Untagged Spark node");
    final Map<Node, Tag> nodeToTag = pag.getNodeTags();
    for (final SootClass c : Scene.v().getClasses()) {
        for (final SootMethod m : c.getMethods()) {
            if (!m.isConcrete())
                continue;
            if (!m.hasActiveBody())
                continue;
            for (final Unit u : m.getActiveBody().getUnits()) {
                final Stmt s = (Stmt) u;
                if (s instanceof DefinitionStmt) {
                    Value lhs = ((DefinitionStmt) s).getLeftOp();
                    VarNode v = null;
                    if (lhs instanceof Local) {
                        v = pag.findLocalVarNode(lhs);
                    } else if (lhs instanceof FieldRef) {
                        v = pag.findGlobalVarNode(((FieldRef) lhs).getField());
                    }
                    if (v != null) {
                        PointsToSetInternal p2set = v.getP2Set();
                        p2set.forall(new P2SetVisitor() {

                            public final void visit(Node n) {
                                addTag(s, n, nodeToTag, unknown);
                            }
                        });
                        Node[] simpleSources = pag.simpleInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.allocInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.loadInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                    }
                }
            }
        }
    }
}
Also used : StringTag(soot.tagkit.StringTag) VarNode(soot.jimple.spark.pag.VarNode) FieldRef(soot.jimple.FieldRef) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Local(soot.Local) SootClass(soot.SootClass) Unit(soot.Unit) Stmt(soot.jimple.Stmt) DefinitionStmt(soot.jimple.DefinitionStmt) Value(soot.Value) SootMethod(soot.SootMethod) Tag(soot.tagkit.Tag) StringTag(soot.tagkit.StringTag) DefinitionStmt(soot.jimple.DefinitionStmt) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 33 with Unit

use of soot.Unit in project soot by Sable.

the class JTableSwitchStmt method toString.

public String toString() {
    StringBuffer buffer = new StringBuffer();
    String endOfLine = " ";
    buffer.append(Jimple.TABLESWITCH + "(" + keyBox.getValue().toString() + ")" + endOfLine);
    buffer.append("{" + endOfLine);
    // The case for "i == highIndex" is handled separately after the loop.
    for (int i = lowIndex; i < highIndex; i++) {
        Unit target = getTarget(i - lowIndex);
        buffer.append("    " + Jimple.CASE + " " + i + ": " + Jimple.GOTO + " " + (target == this ? "self" : target) + ";" + endOfLine);
    }
    Unit target = getTarget(highIndex - lowIndex);
    buffer.append("    " + Jimple.CASE + " " + highIndex + ": " + Jimple.GOTO + " " + (target == this ? "self" : target) + ";" + endOfLine);
    target = getDefaultTarget();
    buffer.append("    " + Jimple.DEFAULT + ": " + Jimple.GOTO + " " + (target == this ? "self" : target) + ";" + endOfLine);
    buffer.append("}");
    return buffer.toString();
}
Also used : Unit(soot.Unit)

Example 34 with Unit

use of soot.Unit in project soot by Sable.

the class JTableSwitchStmt method convertToBaf.

public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
    List<PlaceholderInst> targetPlaceholders = new ArrayList<PlaceholderInst>();
    ((ConvertToBaf) getKey()).convertToBaf(context, out);
    for (Unit target : getTargets()) {
        targetPlaceholders.add(Baf.v().newPlaceholderInst(target));
    }
    Unit u = Baf.v().newTableSwitchInst(Baf.v().newPlaceholderInst(getDefaultTarget()), lowIndex, highIndex, targetPlaceholders);
    u.addAllTagsOf(this);
    out.add(u);
}
Also used : PlaceholderInst(soot.baf.PlaceholderInst) ArrayList(java.util.ArrayList) ConvertToBaf(soot.jimple.ConvertToBaf) Unit(soot.Unit)

Example 35 with Unit

use of soot.Unit in project soot by Sable.

the class JDynamicInvokeExpr method convertToBaf.

public void convertToBaf(JimpleToBafContext context, List<Unit> out) {
    if (argBoxes != null) {
        for (ValueBox element : argBoxes) {
            ((ConvertToBaf) (element.getValue())).convertToBaf(context, out);
        }
    }
    List<Value> bsmArgs = new ArrayList<Value>();
    for (ValueBox argBox : bsmArgBoxes) {
        bsmArgs.add(argBox.getValue());
    }
    Unit u = Baf.v().newDynamicInvokeInst(bsmRef, bsmArgs, methodRef, tag);
    u.addAllTagsOf(context.getCurrentUnit());
    out.add(u);
}
Also used : ValueBox(soot.ValueBox) Value(soot.Value) ArrayList(java.util.ArrayList) ConvertToBaf(soot.jimple.ConvertToBaf) Unit(soot.Unit)

Aggregations

Unit (soot.Unit)240 Local (soot.Local)77 Stmt (soot.jimple.Stmt)77 Value (soot.Value)74 ArrayList (java.util.ArrayList)65 AssignStmt (soot.jimple.AssignStmt)58 SootMethod (soot.SootMethod)47 Body (soot.Body)37 InvokeStmt (soot.jimple.InvokeStmt)35 Type (soot.Type)34 HashSet (java.util.HashSet)33 ValueBox (soot.ValueBox)33 InvokeExpr (soot.jimple.InvokeExpr)33 Trap (soot.Trap)32 RefType (soot.RefType)30 IdentityStmt (soot.jimple.IdentityStmt)28 HashMap (java.util.HashMap)27 IfStmt (soot.jimple.IfStmt)27 DefinitionStmt (soot.jimple.DefinitionStmt)25 List (java.util.List)23