public void initializeUnitToOwner(SootMethod m) { if (m.hasActiveBody()) { Body b = m.getActiveBody(); PatchingChain<Unit> units = b.getUnits(); for (Unit unit : units) { unitToOwner.put(unit, b); } } }
private boolean isRenamingAllowed(SootMethod method) { if (soot.jbco.Main.getWeight(MethodRenamer.name, method.getSignature()) == 0) { return false; } final String subSignature = method.getSubSignature(); if (MAIN_METHOD_SUB_SIGNATURE.equals(subSignature) && method.isPublic() && method.isStatic()) { if (isVerbose()) { logger.info("Skipping renaming \"{}\" method as it is main one.", subSignature); } return false; // skip the main method } if (method.getName().equals(SootMethod.constructorName) || method.getName().equals(SootMethod.staticInitializerName)) { if (isVerbose()) { logger.info("Skipping renaming \"{}\" method as it is constructor or static initializer.", subSignature); } return false; // skip constructors/initializers } return true; }
private void processNewMethod(SootMethod m) { if (!m.isConcrete()) { return; } Body b = m.retrieveActiveBody(); getImplicitTargets(m); findReceivers(m, b); }
MethodBuilder(SootMethod method, SootClassBuilder scb, String desc, String[] ex) { super(Opcodes.ASM5, null, method.getModifiers(), method.getName(), desc, null, ex); this.method = method; this.scb = scb; }
public Type getType() { if (index == PointsToAnalysis.RETURN_NODE) { return method.getReturnType(); } return method.getParameterType(index); }
/** * Returns the Soot signature of this method. Used to refer to methods unambiguously. */ public String getSignature() { if (sig == null) { synchronized (this) { if (sig == null) { sig = getSignature(getDeclaringClass(), getSubSignature()); } } } return sig; }
/** Sets the method for which a graph is currently being built. */ private void setCurrentMethod(SootMethod m) { method = m; if (!m.isStatic()) { SootClass c = m.getDeclaringClass(); if (c == null) { throw new RuntimeException("Method " + m + " has no declaring class"); } caseThis(); } for (int i = 0; i < m.getParameterCount(); i++) { if (m.getParameterType(i) instanceof RefLikeType) { caseParm(i); } } Type retType = m.getReturnType(); if (retType instanceof RefLikeType) { caseRet(); } }
if (!sm.isStatic()) { if (sm.getActiveBody().getThisLocal() == l) { paramRegNum = 0; found = true; for (int i = 0; i < sm.getParameterCount(); i++) { if (sm.getActiveBody().getParameterLocal(i) == l) { if (!sm.isStatic()) { paramRegNum++; Type paramType = sm.getParameterType(i); paramRegNum += SootToDexUtils.getDexWords(paramType);
public static String makeLabel(LocalVarNode n) { SootMethod sm = n.getMethod(); return "LV " + n.getVariable().toString() + " " + n.getNumber() + "\\n" + sm.getDeclaringClass() + "\\n" + sm.getName(); }
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 } } }
public static void retrieveAllBodies() { if (bodiesHaveBeenBuilt) { return; } // iterate through application classes, rename fields with junk for (SootClass c : soot.Scene.v().getApplicationClasses()) { for (SootMethod m : c.getMethods()) { if (!m.isConcrete()) { continue; } if (!m.hasActiveBody()) { m.retrieveActiveBody(); } } } bodiesHaveBeenBuilt = true; }
/** * Returns the signature of this method in the format in which it appears in bytecode (eg. [Ljava/lang/Object instead of * java.lang.Object[]). */ public String getBytecodeSignature() { String name = getName(); StringBuffer buffer = new StringBuffer(); buffer.append("<" + Scene.v().quotedNameOf(getDeclaringClass().getName()) + ": "); buffer.append(name); buffer.append(AbstractJasminClass.jasminDescriptorOf(makeRef())); buffer.append(">"); return buffer.toString().intern(); }
/** * Implements the abstract method simulateMethod. It distributes the request to the corresponding methods by signatures. */ public void simulateMethod(SootMethod method, ReferenceVariable thisVar, ReferenceVariable returnVar, ReferenceVariable params[]) { String subSignature = method.getSubSignature(); /* TODO */ { defaultMethod(method, thisVar, returnVar, params); return; } }
protected Body initForMethod(SootMethod m) { assert Scene.v().hasFastHierarchy(); Body b = null; if (m.isConcrete()) { SootClass declaringClass = m.getDeclaringClass(); ensureClassHasBodies(declaringClass); synchronized (Scene.v()) { b = m.retrieveActiveBody(); } if (b != null) { for (Unit u : b.getUnits()) { if (unitToOwner.put(u, b) != null) { // if the unit was registered already then so were all units; // simply skip the rest break; } } } } assert Scene.v().hasFastHierarchy(); return b; }
private static Body getActiveBodySafely(SootMethod method) { try { return method.getActiveBody(); } catch (Exception exception) { logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception); } return null; }
/** * Returns true if the given method is visible to client code. */ private static boolean visible(SootMethod mPrime) { SootClass cPrime = mPrime.getDeclaringClass(); return (cPrime.isPublic() || cPrime.isProtected() || (!cPrime.isPrivate() && !ASSUME_PACKAGES_SEALED)) && (mPrime.isPublic() || mPrime.isProtected() || (!mPrime.isPrivate() && !ASSUME_PACKAGES_SEALED)); } }
private static Body getBodySafely(SootMethod method) { try { return method.getActiveBody(); } catch (Exception exception) { logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception); return method.retrieveActiveBody(); } }
@Override public FlowFunction<Value> getReturnFlowFunction(final Unit callSite, SootMethod calleeMethod, final Unit exitStmt, Unit returnSite) { Stmt s = (Stmt) callSite; InvokeExpr ie = s.getInvokeExpr(); final List<Value> callArgs = ie.getArgs(); final List<Local> paramLocals = new ArrayList<Local>(); for (int i = 0; i < calleeMethod.getParameterCount(); i++) { paramLocals.add(calleeMethod.getActiveBody().getParameterLocal(i)); } return new FlowFunction<Value>() { public Set<Value> computeTargets(Value source) { Set<Value> liveParamsAtCallee = new HashSet<Value>(); for (int i = 0; i < paramLocals.size(); i++) { if (paramLocals.get(i).equivTo(source)) { liveParamsAtCallee.add(callArgs.get(i)); } } return liveParamsAtCallee; } }; }
private void instanceinvoke(MethodArgInst i) { SootMethod m = i.getMethod(); int length = m.getParameterCount(); remove_types = new Type[length + 1]; remove_types[0] = RefType.v(); System.arraycopy(m.getParameterTypes().toArray(), 0, remove_types, 1, length); if (m.getReturnType() instanceof VoidType) { add_types = null; } else { add_types = new Type[] { m.getReturnType() }; } }
@Override public void run() { m.retrieveActiveBody(); }