Search in sources :

Example 71 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolver method split_new.

/* Taken from the soot.jimple.toolkits.typing.TypeResolver class of Soot
	version 2.2.5. */
private void split_new() {
    LocalDefs defs = LocalDefs.Factory.newLocalDefs(jb);
    PatchingChain<Unit> units = this.jb.getUnits();
    Stmt[] stmts = new Stmt[units.size()];
    units.toArray(stmts);
    final Jimple jimple = Jimple.v();
    for (Stmt stmt : stmts) {
        if (stmt instanceof InvokeStmt) {
            InvokeStmt invoke = (InvokeStmt) stmt;
            if (invoke.getInvokeExpr() instanceof SpecialInvokeExpr) {
                SpecialInvokeExpr special = (SpecialInvokeExpr) invoke.getInvokeExpr();
                if (special.getMethodRef().name().equals("<init>")) {
                    List<Unit> deflist = defs.getDefsOfAt((Local) special.getBase(), invoke);
                    while (deflist.size() == 1) {
                        Stmt stmt2 = (Stmt) deflist.get(0);
                        if (stmt2 instanceof AssignStmt) {
                            AssignStmt assign = (AssignStmt) stmt2;
                            if (assign.getRightOp() instanceof Local) {
                                deflist = defs.getDefsOfAt((Local) assign.getRightOp(), assign);
                                continue;
                            } else if (assign.getRightOp() instanceof NewExpr) {
                                Local newlocal = jimple.newLocal("tmp", null);
                                newlocal.setName("tmp$" + System.identityHashCode(newlocal));
                                this.jb.getLocals().add(newlocal);
                                special.setBase(newlocal);
                                DefinitionStmt assignStmt = jimple.newAssignStmt(assign.getLeftOp(), newlocal);
                                Unit u = Util.findLastIdentityUnit(jb, assign);
                                units.insertAfter(assignStmt, u);
                                assign.setLeftOp(newlocal);
                                this.addLocal(newlocal);
                                this.initAssignment(assignStmt);
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}
Also used : InvokeStmt(soot.jimple.InvokeStmt) AssignStmt(soot.jimple.AssignStmt) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) Local(soot.Local) Unit(soot.Unit) LocalDefs(soot.toolkits.scalar.LocalDefs) InvokeStmt(soot.jimple.InvokeStmt) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt) DefinitionStmt(soot.jimple.DefinitionStmt) NewExpr(soot.jimple.NewExpr) Jimple(soot.jimple.Jimple) DefinitionStmt(soot.jimple.DefinitionStmt)

Example 72 with Unit

use of soot.Unit in project soot by Sable.

the class ConstraintChecker method insertCast.

private Local insertCast(Local oldlocal, Type type, Stmt stmt) {
    Local newlocal = Jimple.v().newLocal("tmp", type);
    stmtBody.getLocals().add(newlocal);
    Unit u = Util.findFirstNonIdentityUnit(this.stmtBody, stmt);
    stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal, Jimple.v().newCastExpr(oldlocal, type)), u);
    return newlocal;
}
Also used : Local(soot.Local) Unit(soot.Unit)

Example 73 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolver method collect_constraints_1.

private void collect_constraints_1() {
    ConstraintCollector collector = new ConstraintCollector(this, true);
    for (Unit u : stmtBody.getUnits()) {
        final Stmt stmt = (Stmt) u;
        if (DEBUG) {
            logger.debug("stmt: ");
        }
        collector.collect(stmt, stmtBody);
        if (DEBUG) {
            logger.debug("" + stmt);
        }
    }
}
Also used : Unit(soot.Unit) Stmt(soot.jimple.Stmt)

Example 74 with Unit

use of soot.Unit in project soot by Sable.

the class TypeResolver method check_and_fix_constraints.

private void check_and_fix_constraints() throws TypeException {
    ConstraintChecker checker = new ConstraintChecker(this, true);
    StringBuffer s = null;
    PatchingChain<Unit> units = stmtBody.getUnits();
    Stmt[] stmts = new Stmt[units.size()];
    units.toArray(stmts);
    if (DEBUG) {
        s = new StringBuffer("Checking:\n");
    }
    for (Stmt stmt : stmts) {
        if (DEBUG) {
            s.append(" " + stmt + "\n");
        }
        try {
            checker.check(stmt, stmtBody);
        } catch (TypeException e) {
            if (DEBUG) {
                logger.debug("" + s);
            }
            throw e;
        }
    }
}
Also used : Unit(soot.Unit) Stmt(soot.jimple.Stmt)

Example 75 with Unit

use of soot.Unit in project soot by Sable.

the class TemplatePrinter method printTo.

private void printTo(SootClass c) {
    String templateClassName = c.getName().replace('.', '_') + "_Maker";
    // imports
    println("import java.util.*;");
    println("import soot.*;");
    println("import soot.jimple.*;");
    println("import soot.util.*;");
    println("");
    // open class
    print("public class ");
    print(templateClassName);
    println(" {");
    println("private static Local localByName(Body b, String name) {");
    println("	for(Local l: b.getLocals()) {");
    println("		if(l.getName().equals(name))");
    println("			return l;");
    println("	}");
    println("	throw new IllegalArgumentException(\"No such local: \"+name);");
    println("}");
    // open main method
    indent();
    println("public void create() {");
    indent();
    println("SootClass c = new SootClass(\"" + c.getName() + "\");");
    println("c.setApplicationClass();");
    // todo modifiers, extends etc.
    println("Scene.v().addClass(c);");
    for (int i = 0; i < c.getMethodCount(); i++) {
        println("createMethod" + i + "(c);");
    }
    // close main method
    closeMethod();
    int i = 0;
    for (SootMethod m : c.getMethods()) {
        newMethod("createMethod" + i);
        // TODO modifiers, types
        println("SootMethod m = new SootMethod(\"" + m.getName() + "\",null,null);");
        println("Body b = Jimple.v().newBody(m);");
        println("m.setActiveBody(b);");
        if (!m.hasActiveBody())
            continue;
        Body b = m.getActiveBody();
        println("Chain<Local> locals = b.getLocals();");
        for (Local l : b.getLocals()) {
            // TODO properly treat primitive types
            println("locals.add(Jimple.v().newLocal(\"" + l.getName() + "\", RefType.v(\"" + l.getType() + "\")));");
        }
        println("Chain<Unit> units = b.getUnits();");
        StmtTemplatePrinter sw = new StmtTemplatePrinter(this, b.getUnits());
        for (Unit u : b.getUnits()) {
            u.apply(sw);
        }
        // TODO print traps
        closeMethod();
        i++;
    }
    // close class
    println("}");
}
Also used : SootMethod(soot.SootMethod) Local(soot.Local) Unit(soot.Unit) Body(soot.Body)

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