@Override public boolean isCallStmt(Unit u) { return ((Stmt) u).containsInvokeExpr(); }
protected Object keyFor(Stmt s) { if (s.containsInvokeExpr()) { if (optionNaive) { throw new RuntimeException("shouldn't get here"); } Iterator it = cg.edgesOutOf(s); if (!it.hasNext()) { return Collections.EMPTY_LIST; } ArrayList ret = new ArrayList(); while (it.hasNext()) { ret.add(it.next()); } return ret; } else { return s; } }
protected Object keyFor(Stmt s) { if (s.containsInvokeExpr()) { if (optionNaive) { throw new RuntimeException("shouldn't get here"); } Iterator it = cg.edgesOutOf(s); if (!it.hasNext()) { return Collections.EMPTY_LIST; } ArrayList ret = new ArrayList(); while (it.hasNext()) { ret.add(it.next()); } return ret; } else { return s; } }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Unit u : b.getUnits()) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr ie = s.getInvokeExpr(); if (FixedMethods.isFixed(ie)) { System.err.println("+++ " + ie); yes++; } else { System.err.println(" - " + ie); no++; } } } }
if (s.containsInvokeExpr()) { if (!(v instanceof Local)) { return true;
private void findMultiCalledMethodsIntra(Set<SootMethod> multiCalledMethods, CallGraph callGraph) { Iterator<Unit> it = multiRunStatements.iterator(); while (it.hasNext()) { Stmt stmt = (Stmt) it.next(); if (stmt.containsInvokeExpr()) { InvokeExpr invokeExpr = stmt.getInvokeExpr(); List<SootMethod> targetList = new ArrayList<SootMethod>(); SootMethod method = invokeExpr.getMethod(); if (invokeExpr instanceof StaticInvokeExpr) { targetList.add(method); } else if (invokeExpr instanceof InstanceInvokeExpr) { if (method.isConcrete() && !method.getDeclaringClass().isLibraryClass()) { TargetMethodsFinder tmd = new TargetMethodsFinder(); targetList = tmd.find(stmt, callGraph, true, true); } } if (targetList != null) { Iterator<SootMethod> iterator = targetList.iterator(); while (iterator.hasNext()) { SootMethod obj = iterator.next(); if (!obj.isNative()) { multiCalledMethods.add(obj); } } } } } }
if (s.containsInvokeExpr()) { Set<SootMethod> calleesOfCallAt = icfg.getCalleesOfCallAt(s); if (s.getInvokeExpr() instanceof VirtualInvokeExpr || s.getInvokeExpr() instanceof InterfaceInvokeExpr) {
@Override public void validate(Body body, List<ValidationException> exceptions) { for (Unit u : body.getUnits()) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr iinvExpr = s.getInvokeExpr(); SootMethod callee = iinvExpr.getMethod(); if (callee != null && iinvExpr.getArgCount() != callee.getParameterCount()) { exceptions.add(new ValidationException(s, "Invalid number of arguments")); } } } }
if (stmt.containsInvokeExpr()) {
if (s.containsInvokeExpr()) { if (!(v instanceof Local)) { return true;
@Override public void validate(Body body, List<ValidationException> exception) { for (Unit u : body.getUnits()) { if (u instanceof Stmt) { Stmt stmt = (Stmt) u; if (stmt.containsInvokeExpr()) { InvokeExpr iexpr = stmt.getInvokeExpr(); SootMethodRef ref = iexpr.getMethodRef(); if (ref.name().contains("'") || ref.declaringClass().getName().contains("'")) { throw new ValidationException(stmt, "Escaped name in signature found"); } for (Type paramType : ref.parameterTypes()) { if (paramType.toString().contains("'")) { throw new ValidationException(stmt, "Escaped name in signature found"); } } } } } }
if (stmt.containsInvokeExpr()) { createInvokeAccessor(container, stmt); } else if (stmt instanceof AssignStmt) {
public static int getOutWordCount(Collection<Unit> units) { int outWords = 0; for (Unit u : units) { Stmt stmt = (Stmt) u; if (stmt.containsInvokeExpr()) { int wordsForParameters = 0; InvokeExpr invocation = stmt.getInvokeExpr(); List<Value> args = invocation.getArgs(); for (Value arg : args) { wordsForParameters += getDexWords(arg.getType()); } if (!invocation.getMethod().isStatic()) { wordsForParameters++; // extra word for "this" } if (wordsForParameters > outWords) { outWords = wordsForParameters; } } } return outWords; }
public static boolean checkSpecialInlineRestrictions(SootMethod container, SootMethod target, String options) { // Check the body of the method to inline for specialinvoke's boolean accessors = options.equals("accessors"); Body inlineeBody = target.getActiveBody(); Iterator unitsIt = inlineeBody.getUnits().iterator(); while (unitsIt.hasNext()) { Stmt st = (Stmt) unitsIt.next(); if (st.containsInvokeExpr()) { InvokeExpr ie1 = st.getInvokeExpr(); if (ie1 instanceof SpecialInvokeExpr) { if ((InlinerSafetyManager.specialInvokePerformsLookupIn(ie1, container.getDeclaringClass()) || InlinerSafetyManager.specialInvokePerformsLookupIn(ie1, target.getDeclaringClass()))) { return false; } SootMethod specialTarget = ie1.getMethod(); if (specialTarget.isPrivate()) { if (specialTarget.getDeclaringClass() != container.getDeclaringClass()) { // Do not inline a call which contains a specialinvoke call to a private method outside // the current class. This avoids a verifier error and we assume will not have a big // impact because we are inlining methods bottom-up, so such a call will be rare if (!accessors) { return false; } } } } } } return true; }
if (s.containsInvokeExpr()) { InvokeExpr invokeExpr = s.getInvokeExpr(); handleInvokeExpr(invokeExpr, out);
public static boolean checkAccessRestrictions(SootMethod container, SootMethod target, String modifierOptions) { // Check the body of the method to inline for // method or field access restrictions { Body inlineeBody = target.getActiveBody(); Iterator unitsIt = inlineeBody.getUnits().iterator(); while (unitsIt.hasNext()) { Stmt st = (Stmt) unitsIt.next(); if (st.containsInvokeExpr()) { InvokeExpr ie1 = st.getInvokeExpr(); if (!AccessManager.ensureAccess(container, ie1.getMethod(), modifierOptions)) { return false; } } if (st instanceof AssignStmt) { Value lhs = ((AssignStmt) st).getLeftOp(); Value rhs = ((AssignStmt) st).getRightOp(); if (lhs instanceof FieldRef && !AccessManager.ensureAccess(container, ((FieldRef) lhs).getField(), modifierOptions)) { return false; } if (rhs instanceof FieldRef && !AccessManager.ensureAccess(container, ((FieldRef) rhs).getField(), modifierOptions)) { return false; } } } } return true; }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); if (u instanceof Stmt) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr iexpr = s.getInvokeExpr(); if (iexpr instanceof StaticInvokeExpr) { if (isClassLoaded(iexpr.getMethodRef().declaringClass())) { SootMethod target = Scene.v().grabMethod(iexpr.getMethodRef().getSignature()); if (target != null && !target.isStatic()) { if (canBeMadeStatic(target)) { // Remove the this-assignment to prevent // 'this-assignment in a static method!' exception target.getActiveBody().getUnits().remove(target.getActiveBody().getThisUnit()); target.setModifiers(target.getModifiers() | Modifier.STATIC); logger.warn(target.getName() + " changed into a static method"); } } } } } } } }
Stmt u = (Stmt) iterator.next(); if (u.containsInvokeExpr()) { InvokeExpr invokeExpr = u.getInvokeExpr(); if (invokeExpr.getMethod().getSignature().equals(INVOKE_SIG)) {
/** * Returns true if the statement <code>stmt</code> contains an illegal access to a field or method, assuming the statement * is in method <code>container</code> * * @param container * @param stmt * @return */ public static boolean isAccessLegal(SootMethod container, Stmt stmt) { if (stmt.containsInvokeExpr()) { return AccessManager.isAccessLegal(container, stmt.getInvokeExpr().getMethod()); } else if (stmt instanceof AssignStmt) { AssignStmt as = (AssignStmt) stmt; if (as.getRightOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getRightOp(); return AccessManager.isAccessLegal(container, r.getField()); } if (as.getLeftOp() instanceof FieldRef) { FieldRef r = (FieldRef) as.getLeftOp(); return AccessManager.isAccessLegal(container, r.getField()); } } return true; }
if (stmt.containsInvokeExpr()) { SootMethodRef called = stmt.getInvokeExpr().getMethodRef(); InvokeExpr iexpr = stmt.getInvokeExpr();