Search in sources :

Example 21 with UnitBox

use of soot.UnitBox in project soot by Sable.

the class Walker method outAFullMethodBody.

public void outAFullMethodBody(AFullMethodBody node) {
    JimpleBody jBody = Jimple.v().newBody();
    if (node.getCatchClause() != null) {
        int size = node.getCatchClause().size();
        for (int i = 0; i < size; i++) jBody.getTraps().addFirst((Trap) mProductions.removeLast());
    }
    if (node.getStatement() != null) {
        int size = node.getStatement().size();
        Unit lastStmt = null;
        for (int i = 0; i < size; i++) {
            Object o = mProductions.removeLast();
            if (o instanceof Unit) {
                jBody.getUnits().addFirst((Unit) o);
                lastStmt = (Unit) o;
            } else if (o instanceof String) {
                if (lastStmt == null)
                    throw new RuntimeException("impossible");
                mLabelToStmtMap.put(o, lastStmt);
            } else
                throw new RuntimeException("impossible");
        }
    }
    if (node.getDeclaration() != null) {
        int size = node.getDeclaration().size();
        for (int i = 0; i < size; i++) {
            List<Local> localList = (List<Local>) mProductions.removeLast();
            jBody.getLocals().addAll(localList);
        }
    }
    Iterator<String> it = mLabelToPatchList.keySet().iterator();
    while (it.hasNext()) {
        String label = it.next();
        Unit target = mLabelToStmtMap.get(label);
        Iterator patchIt = mLabelToPatchList.get(label).iterator();
        while (patchIt.hasNext()) {
            UnitBox box = (UnitBox) patchIt.next();
            box.setUnit(target);
        }
    }
    /*
		 * Iterator it = mLabelToStmtMap.keySet().iterator();
		 * while(it.hasNext()) { String label = (String) it.next(); Unit target
		 * = (Unit) mLabelToStmtMap.get(label);
		 * 
		 * List l = (List) mLabelToPatchList.get(label); if(l != null) {
		 * Iterator patchIt = l.iterator(); while(patchIt.hasNext()) { UnitBox
		 * box = (UnitBox) patchIt.next(); box.setUnit(target); } } }
		 */
    mProductions.addLast(jBody);
}
Also used : UnitBox(soot.UnitBox) Local(soot.Local) Trap(soot.Trap) Unit(soot.Unit) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JimpleBody(soot.jimple.JimpleBody)

Example 22 with UnitBox

use of soot.UnitBox in project soot by Sable.

the class Walker method outATableswitchStatement.

public void outATableswitchStatement(ATableswitchStatement node) {
    List<UnitBox> targets = new ArrayList<UnitBox>();
    UnitBox defaultTarget = null;
    int lowIndex = 0, highIndex = 0;
    if (node.getCaseStmt() != null) {
        int size = node.getCaseStmt().size();
        for (int i = 0; i < size; i++) {
            Object valueTargetPair = mProductions.removeLast();
            if (valueTargetPair instanceof UnitBox) {
                if (defaultTarget != null)
                    throw new RuntimeException("error: can't ;have more than 1 default stmt");
                defaultTarget = (UnitBox) valueTargetPair;
            } else {
                Object[] pair = (Object[]) valueTargetPair;
                if ((i == 0 && defaultTarget == null) || (i == 1 && defaultTarget != null))
                    highIndex = ((IntConstant) pair[0]).value;
                if (i == (size - 1))
                    lowIndex = ((IntConstant) pair[0]).value;
                targets.add(0, (UnitBox) pair[1]);
            }
        }
    } else {
        throw new RuntimeException("error: switch stmt has no case stmts");
    }
    Value key = (Value) mProductions.removeLast();
    Unit switchStmt = Jimple.v().newTableSwitchStmt(key, lowIndex, highIndex, targets, defaultTarget);
    mProductions.addLast(switchStmt);
}
Also used : UnitBox(soot.UnitBox) ArrayList(java.util.ArrayList) Value(soot.Value) IntConstant(soot.jimple.IntConstant) Unit(soot.Unit)

Example 23 with UnitBox

use of soot.UnitBox in project soot by Sable.

the class Walker method outAIfStatement.

public void outAIfStatement(AIfStatement node) {
    String targetLabel = (String) mProductions.removeLast();
    Value condition = (Value) mProductions.removeLast();
    UnitBox box = Jimple.v().newStmtBox(null);
    Unit u = Jimple.v().newIfStmt(condition, box);
    addBoxToPatch(targetLabel, box);
    mProductions.addLast(u);
}
Also used : UnitBox(soot.UnitBox) Value(soot.Value) Unit(soot.Unit)

Aggregations

UnitBox (soot.UnitBox)23 Unit (soot.Unit)16 ArrayList (java.util.ArrayList)9 Trap (soot.Trap)9 Value (soot.Value)8 HashMap (java.util.HashMap)5 Local (soot.Local)5 Iterator (java.util.Iterator)4 LabelNode (org.objectweb.asm.tree.LabelNode)4 GotoStmt (soot.jimple.GotoStmt)4 IntConstant (soot.jimple.IntConstant)4 ReturnStmt (soot.jimple.ReturnStmt)4 HashSet (java.util.HashSet)3 List (java.util.List)3 CaughtExceptionRef (soot.jimple.CaughtExceptionRef)3 IdentityStmt (soot.jimple.IdentityStmt)3 IfStmt (soot.jimple.IfStmt)3 ParameterRef (soot.jimple.ParameterRef)3 Stmt (soot.jimple.Stmt)3 ThisRef (soot.jimple.ThisRef)3