/** Returns the class which declares the current {@link SootMethod}. */ @Override public SootClass getDeclaringClass() { if (!isDeclared) { throw new RuntimeException("not declared: " + getName()); } return declaringClass; }
private static boolean isConstructor(SootMethod invokedMethod) { return invokedMethod.getName().equals("<init>"); }
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; }
private Set<SootClass> getDeclaringClasses(SootClass applicationClass, SootMethod method) { return getTree(applicationClass).stream() .filter(sootClass -> isDeclared(sootClass, method.getName(), method.getParameterTypes())).collect(toSet()); }
/** Returns a list of all constructors. */ public List<SootMethod> allInits() { List<SootMethod> ret = new ArrayList<SootMethod>(); for (Iterator<SootClass> clIt = Scene.v().getClasses().iterator(); clIt.hasNext();) { final SootClass cl = clIt.next(); for (SootMethod m : cl.getMethods()) { if (m.getName().equals("<init>")) { ret.add(m); } } } return ret; }
private void handleFieldInits() { if ((fieldInits != null) || (initializerBlocks != null)) { Iterator methodsIt = sootClass.getMethods().iterator(); while (methodsIt.hasNext()) { soot.SootMethod next = (soot.SootMethod) methodsIt.next(); if (next.getName().equals("<init>")) { soot.javaToJimple.PolyglotMethodSource src = (soot.javaToJimple.PolyglotMethodSource) next.getSource(); src.setInitializerBlocks(initializerBlocks); src.setFieldInits(fieldInits); } } } }
/** * 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(); }
private void addQualifierRefToInit(polyglot.types.Type type) { soot.Type sootType = Util.getSootType(type); Iterator it = sootClass.getMethods().iterator(); while (it.hasNext()) { soot.SootMethod meth = (soot.SootMethod) it.next(); if (meth.getName().equals("<init>")) { List newParams = new ArrayList(); newParams.add(sootType); newParams.addAll(meth.getParameterTypes()); meth.setParameterTypes(newParams); meth.addTag(new soot.tagkit.QualifyingTag()); } } }
public RegionAnalysis(UnitGraph cfg, SootMethod m, SootClass c) { this.m_methodBody = cfg.getBody(); this.m_cfg = cfg; this.m_method = m; this.m_class = c; if (Options.v().verbose()) { logger.debug( "[RegionAnalysis]~~~~~~~~~~~~~~~ Begin Region Analsis for method: " + m.getName() + " ~~~~~~~~~~~~~~~~~~~~"); } this.findWeakRegions(); if (Options.v().verbose()) { logger.debug("[RegionAnalysis]~~~~~~~~~~~~~~~ End:" + m.getName() + " ~~~~~~~~~~~~~~~~~~~~"); } }
/** * performs critical edge-removing. */ protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (Options.v().verbose()) { logger.debug("[" + b.getMethod().getName() + "] Removing Critical Edges..."); } removeCriticalEdges(b); if (Options.v().verbose()) { logger.debug("[" + b.getMethod().getName() + "] Removing Critical Edges done."); } }
/** * @param lvNode * @param cName * @param mName * @return */ private boolean isDefinedIn(LocalVarNode lvNode, String cName, String mName) { return lvNode.getMethod() != null && lvNode.getMethod().getDeclaringClass().getName().equals(cName) && lvNode.getMethod().getName().equals(mName); }
public static String makeLabel(LocalVarNode n) { SootMethod sm = n.getMethod(); return "LV " + n.getVariable().toString() + " " + n.getNumber() + "\\n" + sm.getDeclaringClass() + "\\n" + sm.getName(); }
/** * Returns the Soot subsignature of this method. Used to refer to methods unambiguously. */ public String getSubSignature() { if (subSig == null) { synchronized (this) { if (subSig == null) { subSig = getSubSignatureImpl(getName(), getParameterTypes(), getReturnType()); } } } return subSig; }
private void printStatementsInBody(Body body, java.io.PrintWriter out) { if (Options.v().verbose()) { System.out.println("Printing " + body.getMethod().getName()); } Chain<Unit> units = ((DavaBody) body).getUnits(); if (units.size() != 1) { throw new RuntimeException("DavaBody AST doesn't have single root."); } UnitPrinter up = new DavaUnitPrinter((DavaBody) body); ((ASTNode) units.getFirst()).toString(up); out.print(up.toString()); }
private void dumpLocalP2Set(String mName, final PrintStream ps) { for (Iterator iter = pag.getVarNodeNumberer().iterator(); iter.hasNext();) { VarNode vNode = (VarNode) iter.next(); if (vNode instanceof LocalVarNode) { final LocalVarNode lvNode = (LocalVarNode) vNode; if (lvNode.getMethod() != null && lvNode.getMethod().getName().equals(mName)) { ps.println("\t" + makeNodeName(lvNode) + " [label=\"" + makeLabel(lvNode) + "\"];"); lvNode.getP2Set().forall(new P2SetToDotPrinter(lvNode, ps)); } } } }
public Body getBody(SootMethod m, String phaseName) { JimpleBody jb = (JimpleBody) mJimpleAST.getBody(m); if (jb == null) { throw new RuntimeException("Could not load body for method " + m.getSignature()); } if (Options.v().verbose()) { logger.debug("[" + m.getName() + "] Retrieving JimpleBody from AST..."); } PackManager.v().getPack("jb").apply(jb); return jb; } }
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { initialize(options); SootMethod meth = b.getMethod(); if ((methodsToPrint == null) || (meth.getDeclaringClass().getName() == methodsToPrint.get(meth.getName()))) { Body body = ir.getBody((JimpleBody) b); print_cfg(body); } }
public void handleNewAnalysis(Transform t, Body b) { // here save current phase name and only send if actual data flow analysis exists if (PhaseOptions.getBoolean(PhaseOptions.v().getPhaseOptions(t.getPhaseName()), "enabled")) { String name = t.getPhaseName() + " for method: " + b.getMethod().getName(); currentPhaseName(name); currentPhaseEnabled(true); doneCurrent(false); } else { currentPhaseEnabled(false); setInteractThisAnalysis(false); } }
public SootMethod resolveSpecial(SpecialInvokeExpr iie, NumberedString subSig, SootMethod container, boolean appOnly) { SootMethod target = iie.getMethod(); /* cf. JVM spec, invokespecial instruction */ if (Scene.v().getOrMakeFastHierarchy().canStoreType(container.getDeclaringClass().getType(), target.getDeclaringClass().getType()) && container.getDeclaringClass().getType() != target.getDeclaringClass().getType() && !target.getName().equals("<init>") && subSig != sigClinit) { return resolveNonSpecial(container.getDeclaringClass().getSuperclass().getType(), subSig, appOnly); } else { return target; } }