public TypeResolver(JimpleBody jb) { this.jb = jb; this.assignments = new ArrayList<DefinitionStmt>(); this.depends = new HashMap<Local, BitSet>(jb.getLocalCount()); for (Local v : this.jb.getLocals()) { this.addLocal(v); } this.initAssignments(); }
public Local newLocal(String name, soot.Type type) { Local local = Jimple.v().newLocal(name, type); body.getLocals().add(local); if(name.equals("this") && thisName == null) thisName = local; return local; }
private boolean typingFailed(JimpleBody b) { // Check to see if any locals are untyped { Iterator<Local> localIt = b.getLocals().iterator(); final UnknownType unknownType = UnknownType.v(); final ErroneousType errornousType = ErroneousType.v(); while (localIt.hasNext()) { Local l = localIt.next(); if (l.getType().equals(unknownType) || l.getType().equals(errornousType)) { return true; } } } return false; }
public Local newTemp(soot.Type type) { Local local = Jimple.v().newLocal("temp$" + nextTempIndex++, type); body.getLocals().add(local); return local; }
Local getLocalCreatingIfNecessary(JimpleBody listBody, String name, Type type) { Local l = getLocalUnsafe(listBody, name); if (l != null) { if (!l.getType().equals(type)) { throw new RuntimeException("The body already declares this local name with a different type."); } } else { l = Jimple.v().newLocal(name, type); listBody.getLocals().add(l); } return l; }
private soot.Local createLocal(String name, soot.Type sootType) { soot.Local sootLocal = soot.jimple.Jimple.v().newLocal(name, sootType); body.getLocals().add(sootLocal); return sootLocal; }
private void assign_types_3() throws TypeException { for (Iterator<Local> localIt = stmtBody.getLocals().iterator(); localIt.hasNext();) { final Local local = localIt.next(); TypeVariable var = typeVariable(local); if (var == null || var.approx() == null || var.approx().type() == null) { local.setType(RefType.v("java.lang.Object")); } else { local.setType(var.approx().type()); } } }
private void assign_types_3() throws TypeException { for (Iterator<Local> localIt = stmtBody.getLocals().iterator(); localIt.hasNext();) { final Local local = localIt.next(); TypeVariableBV var = typeVariable(local); if (var == null || var.approx() == null || var.approx().type() == null) { local.setType(RefType.v("java.lang.Object")); } else { local.setType(var.approx().type()); } } }
private Local insertCast(Value oldvalue, Type oldtype, Type type, Stmt stmt) { Local newlocal1 = Jimple.v().newLocal("tmp", oldtype); Local newlocal2 = Jimple.v().newLocal("tmp", type); stmtBody.getLocals().add(newlocal1); stmtBody.getLocals().add(newlocal2); Unit u = Util.findFirstNonIdentityUnit(this.stmtBody, stmt); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal1, oldvalue), u); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal2, Jimple.v().newCastExpr(newlocal1, type)), u); return newlocal2; } }
private void emitLocals() { JimpleBody jb = body; SootMethod m = jb.getMethod(); Collection<Local> jbl = jb.getLocals(); Collection<Unit> jbu = jb.getUnits(); int iloc = 0; if (!m.isStatic()) { Local l = getLocal(iloc++); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType()))); } int nrp = 0; for (Object ot : m.getParameterTypes()) { Type t = (Type) ot; Local l = getLocal(iloc); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++))); if (AsmUtil.isDWord(t)) { iloc += 2; } else { iloc++; } } for (Local l : locals.values()) { jbl.add(l); } }
private void assign_types_1() throws TypeException { for (Iterator<Local> localIt = stmtBody.getLocals().iterator(); localIt.hasNext();) { final Local local = localIt.next(); if (local.getType() instanceof IntegerType) { TypeVariable var = typeVariable(local); if (var.type() == null || var.type().type() == null) { TypeVariable.error("Type Error(21): Variable without type"); } else { local.setType(var.type().type()); } if (DEBUG) { if ((var != null) && (var.approx() != null) && (var.approx().type() != null) && (local != null) && (local.getType() != null) && !local.getType().equals(var.approx().type())) { logger.debug("local: " + local + ", type: " + local.getType() + ", approx: " + var.approx().type()); } } } } }
/** * Creates a cast at stmt of vold to the given type. * * @param useType * the new type * @param stmt * stmt * @param old * the old local * @return the new local */ protected Local createCast(Type useType, Stmt stmt, Local old) { Jimple jimple = Jimple.v(); Local vnew = jimple.newLocal("tmp", useType); vnew.setName("tmp$" + System.identityHashCode(vnew)); this.tg.set(vnew, useType); this.jb.getLocals().add(vnew); Unit u = Util.findFirstNonIdentityUnit(jb, stmt); this.jb.getUnits().insertBefore(jimple.newAssignStmt(vnew, jimple.newCastExpr(old, useType)), u); return vnew; }
static Stmt addThrowAfter(JimpleBody b, Stmt target) { Chain<Unit> units = b.getUnits(); Collection<Local> locals = b.getLocals(); int i = 0; // Bah! boolean canAddI = false; do { canAddI = true; Iterator<Local> localIt = locals.iterator(); while (localIt.hasNext()) { Local l = (Local) localIt.next(); if (l.getName().equals("__throwee" + i)) { canAddI = false; } } if (!canAddI) { i++; } } while (!canAddI); Local l = Jimple.v().newLocal("__throwee" + i, RefType.v("java.lang.NullPointerException")); b.getLocals().add(l); Stmt newStmt = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v("java.lang.NullPointerException"))); Stmt invStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().getMethod("<java.lang.NullPointerException: void <init>()>").makeRef())); Stmt throwStmt = Jimple.v().newThrowStmt(l); units.insertAfter(newStmt, target); units.insertAfter(invStmt, newStmt); units.insertAfter(throwStmt, invStmt); return newStmt; }
private Local insertCastAfter(Local leftlocal, Type lefttype, Type righttype, Stmt stmt) { Local newlocal = Jimple.v().newLocal("tmp", righttype); stmtBody.getLocals().add(newlocal); Unit u = Util.findLastIdentityUnit(this.stmtBody, stmt); stmtBody.getUnits().insertAfter(Jimple.v().newAssignStmt(leftlocal, Jimple.v().newCastExpr(newlocal, lefttype)), u); return newlocal; }
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; }
private Local insertCast(Local oldlocal, Type type, Stmt stmt) { Local newlocal = Jimple.v().newLocal("tmp", type); stmtBody.getLocals().add(newlocal); Unit u = Util.findFirstNonIdentityUnit(stmtBody, stmt); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal, Jimple.v().newCastExpr(oldlocal, type)), u); return newlocal; } }
private Local insertCast(Local oldlocal, Type type, Stmt stmt) { Local newlocal = Jimple.v().newLocal("tmp", type); stmtBody.getLocals().add(newlocal); Unit u = Util.findFirstNonIdentityUnit(stmtBody, stmt); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal, Jimple.v().newCastExpr(oldlocal, type)), u); return newlocal; } }
stmtBody.getLocals().add(newlocal);
private void assign_types_2() throws TypeException { for (Iterator<Local> localIt = stmtBody.getLocals().iterator(); localIt.hasNext();) { final Local local = localIt.next(); if (local.getType() instanceof IntegerType) { TypeVariable var = typeVariable(local); if (var.inv_approx() != null && var.inv_approx().type() != null) { local.setType(var.inv_approx().type()); } else if (var.approx().type() != null) { local.setType(var.approx().type()); } else if (var.approx() == ClassHierarchy.v().R0_1) { local.setType(BooleanType.v()); } else if (var.approx() == ClassHierarchy.v().R0_127) { local.setType(ByteType.v()); } else { local.setType(ShortType.v()); } } } }