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;
}
}
}
}
}
}
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;
}
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);
}
}
}
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;
}
}
}
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("}");
}
Aggregations