/** * Make sure that all invoke special targets are cloned into the class from ancestors. This might * mean that we have to clone hidden methods, and change their names. So clone them in, and update * the clone to original map, and update the invoke special Also, this will update invoke specials * that target methods cloned in previous call to above cloneReachableNonHiddenAncestorMethods() */ private void cloneHiddenAncestorMethodsAndFixInvokeSpecial() { Set<SootClass> parents = SootUtils.getParents(clazz); boolean debug = false; // (clazz.getName().contains("ResultDisplayer")); boolean cloneAdded = false; do { cloneAdded = false; for (SootMethod method : clazz.getMethods()) { if (method.isAbstract() || method.isPhantom() || !method.isConcrete()) continue; if (debug) System.out.println(method); Body body = null; try { body = method.retrieveActiveBody(); } catch (Exception ex) { logger.info("Exception retrieving method body {}", ex); continue; } StmtBody stmtBody = (StmtBody) body; Chain units = stmtBody.getUnits(); Iterator stmtIt = units.iterator(); while (stmtIt.hasNext()) { Stmt stmt = (Stmt) stmtIt.next(); if (stmt.containsInvokeExpr() && stmt.getInvokeExpr() instanceof SpecialInvokeExpr) { SpecialInvokeExpr si = (SpecialInvokeExpr) stmt.getInvokeExpr(); SootMethod target = resolveSpecialInvokeTarget(si); // si.getMethod(); if (debug) System.out.printf("\t%s %s", si, target); if (clonedToOriginal.values().contains(target)) { // found target of invoke special, and it has been cloned, so change the invoke // special SootMethod cloneOfTarget = clonedToOriginal.inverse().get(target); si.setMethodRef(cloneOfTarget.makeRef()); if (debug) System.out.println("\tChange ref " + cloneOfTarget); } else if (parents.contains(target.getDeclaringClass())) { // target has not been cloned, but should be cloned, so clone it and change ref of // invoke String name = target.getName() + CLONED_METHOD_SUFFIX + (cloned_method_id++); SootMethod clonedMethod = cloneMethod(target, name); si.setMethodRef(clonedMethod.makeRef()); cloneAdded = true; if (debug) System.out.println("\tClone and Change ref " + clonedMethod); } } } } } while (cloneAdded); }