protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (!b.getMethod().isSynchronized() || b.getMethod().isStatic()) return; Iterator<Unit> it = b.getUnits().snapshotIterator(); while (it.hasNext()) { Unit u = it.next(); if (u instanceof IdentityStmt) continue; // This the first real statement. If it is not a MonitorEnter // instruction, we generate one if (!(u instanceof EnterMonitorStmt)) { b.getUnits().insertBeforeNoRedirect(Jimple.v().newEnterMonitorStmt(b.getThisLocal()), u); // We also need to leave the monitor when the method terminates UnitGraph graph = new ExceptionalUnitGraph(b); for (Unit tail : graph.getTails()) b.getUnits().insertBefore(Jimple.v().newExitMonitorStmt(b.getThisLocal()), tail); } break; } }
private void checkSynchronizationStmt(Stmt sootStmt) { if(sootStmt instanceof EnterMonitorStmt) { EnterMonitorStmt enterMonitorStmt = (EnterMonitorStmt)sootStmt; lockStack.add(0, enterMonitorStmt.getOp()); expSecondExitMonitor = false; } else if(sootStmt instanceof ExitMonitorStmt) { if(!expSecondExitMonitor) { lockStack.remove(0); expSecondExitMonitor = true; } else { expSecondExitMonitor = false; } } }
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { if (uses) { if (stmt.getOp() instanceof Local) { TypeVariable op = resolver.typeVariable((Local) stmt.getOp()); op.addParent(resolver.typeVariable(RefType.v("java.lang.Object"))); } } }
public Set<Unit> getUnitsWithMonitor(UnitGraph ug) { Set<Unit> unitsWithMonitor = new HashSet<Unit>(); for (Unit head : ug.getHeads()) { List<Unit> workList = new ArrayList<Unit>(); workList.add(head); Set<Unit> doneSet = new HashSet<Unit>(); while (!workList.isEmpty()) { Unit curUnit = workList.remove(0); if (!doneSet.add(curUnit)) continue; workList.addAll(ug.getSuccsOf(curUnit)); // If this is an "entermonitor" construct, // we're in a monitor from now on if (curUnit instanceof EnterMonitorStmt) unitsWithMonitor.add(curUnit); // If we leave a monitor, we're out now else if (curUnit instanceof ExitMonitorStmt) continue; else { for (Unit pred : ug.getPredsOf(curUnit)) if (unitsWithMonitor.contains(pred)) unitsWithMonitor.add(curUnit); } } } // Get rid of the entermonitor statements themselves for (Iterator<Unit> it = unitsWithMonitor.iterator(); it.hasNext(); ) if (it.next() instanceof EnterMonitorStmt) it.remove(); return unitsWithMonitor; }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt arg0) { injectLabelStatements(arg0); arg0.getOp().apply(this.valueswitch); this.valueswitch.getExpression(); this.inMonitor = true; // TODO: this is a very aggressive hack // to avoid false positives that we encountered in Tomcat. // For example: if (A) synchronized() { if (A) ... // havoc everything. this.boogieStatements.add(TranslationHelpers.havocEverything(this.getProcInfo(), this.valueswitch)); }
public static void insertAfterIdentityStmt(PatchingChain<Unit> units, Chain<Unit> toInsert) { Unit point = null; Iterator<Unit> unitIt = units.snapshotIterator(); boolean foundIdentityStmt = false; while (unitIt.hasNext()) { Unit unit = unitIt.next(); if (!(unit instanceof IdentityStmt) && !(unit instanceof EnterMonitorStmt)) { point = units.getPredOf(unit); break; } else { foundIdentityStmt = true; } } if (point == null && foundIdentityStmt) { point = units.getLast(); } else if (point == null && !foundIdentityStmt) { units.insertBefore(toInsert, units.getFirst()); } units.insertAfter(toInsert, point); }
private void analyzeUnit(SootMethod method, Unit unit, UnitGraph cfg, StackNode<EnterMonitorStmt> stack) { if (visited.contains(unit)) return; /* Unit already taken care of */ visited.add(unit); if (unit instanceof EnterMonitorStmt) stack=new StackNode<EnterMonitorStmt>(stack,(EnterMonitorStmt)unit); else if (unit instanceof ExitMonitorStmt && stack != null) { EnterMonitorStmt enter; enter=stack.element(); if (!exitMon.containsKey(enter)) exitMon.put(enter,new ArrayList<ExitMonitorStmt>(8)); exitMon.get(enter).add((ExitMonitorStmt)unit); stack=stack.parent(); } for (Unit succ: cfg.getSuccsOf(unit)) analyzeUnit(method,succ,cfg,stack); }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { throw new RuntimeException("todo"); }
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { String varName = printValueAssignment(stmt.getOp(), "monitor"); printStmt(stmt,varName); }
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { stmt.setOp(this.uv.visit( stmt.getOp(), RefType.v("java.lang.Object"), stmt)); }
public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { addInsn(buildMonitorInsn(stmt, Opcode.MONITOR_ENTER), stmt); }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt s) { result = result.add(mgr.NULL_POINTER_EXCEPTION); result = result.add(mightThrow(s.getOp())); }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { throwNotImplementedException(stmt.getClass(), stmt.toString()); }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { logger.fine("\n > > > Enter monitor statement identified < < <"); valueSwitch.callingStmt = stmt; throw new NotSupportedStmtException("EnterMonitorStmt"); }
@Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { logger.fine("\n > > > Enter monitor statement identified < < <"); throw new NotSupportedStmtException("EnterMonitorStmt"); }
private void analyzeUnitEnterMonitor(SootMethod method, UnitGraph cfg, EnterMonitorStmt unit) { PBNonTerminal synchNonTerm=new PBNonTerminal(alias(unit)+"@",method);
public MonitorAnalysis(Scene s) { scene=s; visited=null; exitMon=new HashMap<EnterMonitorStmt,Collection<ExitMonitorStmt>>(); }
public Collection<ExitMonitorStmt> getExitMonitor(EnterMonitorStmt enterMon) { assert exitMon.containsKey(enterMon); return exitMon.get(enterMon); }
/** * Method, which should process the given statement of type * {@link EnterMonitorStmt}, but is not implemented in the current version * of this method. If method will be called an exception is thrown. * * @param stmt * Statement that should be processed to check for security * violations. * @see soot.jimple.StmtSwitch#caseEnterMonitorStmt(soot.jimple.EnterMonitorStmt) * @throws UnimplementedSwitchException * Method throws always this exception, because the method is * not implemented. */ @Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { throw new SwitchException(getMsg("exception.analysis.switch.not_implemented", stmt.toString(), getSourceLine(), stmt.getClass().getSimpleName(), this.getClass().getSimpleName())); }
/** * DOC * * @see soot.jimple.StmtSwitch#caseEnterMonitorStmt(soot.jimple.EnterMonitorStmt) */ @Override public void caseEnterMonitorStmt(EnterMonitorStmt stmt) { stmt.getOp().apply(valueSwitch); }