/** * Checks whether the given method can be made static, i.e., does not reference the "this" object * * @param target * The method to check * @return True if the given method can be made static, otherwise false */ private boolean canBeMadeStatic(SootMethod target) { if (target.hasActiveBody()) { Body body = target.getActiveBody(); Value thisLocal = body.getThisLocal(); for (Unit u : body.getUnits()) { for (ValueBox vb : u.getUseBoxes()) { if (vb.getValue() == thisLocal) { return false; } } } return true; } return false; }
} else if (fr instanceof InstanceFieldRef) { InstanceFieldRef ifr = (InstanceFieldRef) fr; if (!method.isStatic() && ifr.getBase().equivTo(b.getThisLocal())) { } else if (ie instanceof InstanceInvokeExpr) { InstanceInvokeExpr iie = (InstanceInvokeExpr) ie; if (!method.isStatic() && iie.getBase().equivTo(b.getThisLocal())) {
if (sm.getActiveBody().getThisLocal() == l) { paramRegNum = 0; found = true;
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; } } }
/** A constructor that doesn't run the analysis */ protected SimpleMethodInfoFlowAnalysis(UnitGraph g, InfoFlowAnalysis dfa, boolean ignoreNonRefTypeFlow, boolean dummyDontRunAnalysisYet) { super(g); this.sm = g.getBody().getMethod(); if (sm.isStatic()) { this.thisLocal = null; } else { this.thisLocal = g.getBody().getThisLocal(); } this.dfa = dfa; this.refOnly = ignoreNonRefTypeFlow; this.infoFlowGraph = new MemoryEfficientGraph<EquivalentValue>(); this.returnRef = new ParameterRef(g.getBody().getMethod().getReturnType(), -1); // it's a dummy parameter ref this.entrySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); this.emptySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); printMessages = false; }
soot.Local specialThisLocal = body.getThisLocal();
thisLocal = b.getThisLocal();
this.thisLocal = null; } else { this.thisLocal = g.getBody().getThisLocal(); EquivalentValue fieldRefEqVal; if (!sm.isStatic()) { fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, sf, sm.retrieveActiveBody().getThisLocal()); } else { fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, sf); EquivalentValue fieldRefEqVal; if (!sm.isStatic()) { fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, scField, sm.retrieveActiveBody().getThisLocal()); } else { fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, scField);
Value base = ifr.getBase(); if (base instanceof Local) { if (dfa.includesInnerFields() || ((!sm.isStatic()) && base.equivTo(b.getThisLocal()))) { fieldsStaticsParamsAccessed.add(InfoFlowAnalysis.getNodeForFieldRef(sm, ifr.getField()));
if (m.isConcrete() && !m.isStatic() && m.retrieveActiveBody().getThisLocal().equivTo(ifr.getBase()) && tlo.isObjectThreadLocal(ifr, m)) { return null;
thisLocal = b.getThisLocal(); } catch (RuntimeException re) {
SootMethod im = initMethodsToRewrite.remove(i); Body b = im.getActiveBody(); Local thisLocal = b.getThisLocal(); Iterator<Unit> uIt = b.getUnits().snapshotIterator(); while (uIt.hasNext()) {
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if (sf.isStatic()) { return new CachedEquivalentValue(Jimple.v().newStaticFieldRef(sf.makeRef())); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if (sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } } }
if (!containingMethod.isStatic() && iie.getBase().equivTo(b.getThisLocal())) {
.newAssignStmt(Jimple.v().newInstanceFieldRef(body.getThisLocal(), sf.makeRef()), constant);
if (m.isConcrete() && !m.isStatic() && m.retrieveActiveBody().getThisLocal().equivTo(ifr.getBase()) && tlo.isObjectThreadLocal(ifr, m)) { return null;
@Override public Local[] load(SootMethod method) throws Exception { if (!method.isConcrete() || !method.hasActiveBody()) return new Local[0]; List<Local> lcs = new ArrayList<Local>(method.getParameterCount() + (method.isStatic() ? 0 : 1)); for (Unit u : method.getActiveBody().getUnits()) useBox: for (ValueBox vb : u.getUseBoxes()) { // Check for parameters for (int i = 0; i < method.getParameterCount(); i++) { if (method.getActiveBody().getParameterLocal(i) == vb.getValue()) { lcs.add((Local) vb.getValue()); continue useBox; } } } // Add the "this" local if (!method.isStatic()) lcs.add(method.getActiveBody().getThisLocal()); return lcs.toArray(new Local[lcs.size()]); } });
/** A constructor that doesn't run the analysis */ protected SimpleMethodInfoFlowAnalysis(UnitGraph g, InfoFlowAnalysis dfa, boolean ignoreNonRefTypeFlow, boolean dummyDontRunAnalysisYet) { super(g); this.sm = g.getBody().getMethod(); if(sm.isStatic()) this.thisLocal = null; else this.thisLocal = g.getBody().getThisLocal(); this.dfa = dfa; this.refOnly = ignoreNonRefTypeFlow; this.infoFlowGraph = new MemoryEfficientGraph(); this.returnRef = new ParameterRef(g.getBody().getMethod().getReturnType(), -1); // it's a dummy parameter ref this.entrySet = new ArraySparseSet(); this.emptySet = new ArraySparseSet(); printMessages = false; }
/** A constructor that doesn't run the analysis */ protected SimpleMethodInfoFlowAnalysis(UnitGraph g, InfoFlowAnalysis dfa, boolean ignoreNonRefTypeFlow, boolean dummyDontRunAnalysisYet) { super(g); this.sm = g.getBody().getMethod(); if(sm.isStatic()) this.thisLocal = null; else this.thisLocal = g.getBody().getThisLocal(); this.dfa = dfa; this.refOnly = ignoreNonRefTypeFlow; this.infoFlowGraph = new MemoryEfficientGraph(); this.returnRef = new ParameterRef(g.getBody().getMethod().getReturnType(), -1); // it's a dummy parameter ref this.entrySet = new ArraySparseSet(); this.emptySet = new ArraySparseSet(); printMessages = false; }
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if(sf.isStatic()) { return new CachedEquivalentValue( Jimple.v().newStaticFieldRef(sf.makeRef()) ); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if(sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue( Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef()) ); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue( Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef()) ); // fake thisLocal } } }