@Override protected boolean acceptMethod(SootMethod n) { int nParams = n.getParameterCount(); return nParams == 0; } };
public int hashCode() { return m.hashCode() + m.getParameterCount(); }
@Override protected boolean acceptMethod(SootMethod m) { if (!at.possibleSizes.contains(m.getParameterCount())) { return false; } for (int i = 0; i < m.getParameterCount(); i++) { if (at.possibleTypes[i].isEmpty()) { continue; } if (!isReflectionCompatible(m.getParameterType(i), at.possibleTypes[i])) { return false; } } return true; }
@Override protected boolean acceptMethod(SootMethod n) { int nParams = n.getParameterCount(); if (methodSizes != null) { // if the arg array can be null we have to still allow for // nullary methods boolean compatibleSize = methodSizes.get(nParams) || (!mustNotBeNull && nParams == 0); if (!compatibleSize) { return false; } } List<Type> t = n.getParameterTypes(); for (Type pTy : t) { if (!isReflectionCompatible(pTy, reachingTypes)) { return false; } } return true; }
vats = visibleParamAnnotations; if (vats == null) { vats = new VisibilityAnnotationTag[method.getParameterCount()]; visibleParamAnnotations = vats; vats = invisibleParamAnnotations; if (vats == null) { vats = new VisibilityAnnotationTag[method.getParameterCount()]; invisibleParamAnnotations = vats;
/** * Checks that method is declared in class. We assume that method is declared in class if class contains method with the * same name and the same number of arguments. The exact types are not compared. * * @param sootClass * the class to search in * @param methodName * the searching method name * @param parameterTypes * the searching method parameters * @return {@code true} if passed class contains similar method; {@code false} otherwise */ private boolean isDeclared(SootClass sootClass, String methodName, List<Type> parameterTypes) { for (SootMethod declared : sootClass.getMethods()) { if (declared.getName().equals(methodName) && declared.getParameterCount() == parameterTypes.size()) { return true; } } return false; }
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() }; } }
public FlowFunction<Pair<Value, Type>> getCallFlowFunction(final Unit src, final SootMethod dest) { Stmt stmt = (Stmt) src; InvokeExpr ie = stmt.getInvokeExpr(); final List<Value> callArgs = ie.getArgs(); final List<Local> paramLocals = new ArrayList<Local>(); for (int i = 0; i < dest.getParameterCount(); i++) { paramLocals.add(dest.getActiveBody().getParameterLocal(i)); } return new FlowFunction<Pair<Value, Type>>() { public Set<Pair<Value, Type>> computeTargets(Pair<Value, Type> source) { if (!dest.getName().equals("<clinit>") && !dest.getSubSignature().equals("void run()")) { Value value = source.getO1(); int argIndex = callArgs.indexOf(value); if (argIndex > -1) { return Collections.singleton(new Pair<Value, Type>(paramLocals.get(argIndex), source.getO2())); } } return Collections.emptySet(); } }; }
@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; } }; }
@Override public FlowFunction<Local> getCallFlowFunction(Unit src, final SootMethod dest) { Stmt s = (Stmt) src; InvokeExpr ie = s.getInvokeExpr(); final List<Value> callArgs = ie.getArgs(); final List<Local> paramLocals = new ArrayList<Local>(); for (int i = 0; i < dest.getParameterCount(); i++) { paramLocals.add(dest.getActiveBody().getParameterLocal(i)); } return new FlowFunction<Local>() { public Set<Local> computeTargets(Local source) { // ignore implicit calls to static initializers if (dest.getName().equals(SootMethod.staticInitializerName) && dest.getParameterCount() == 0) { return Collections.emptySet(); } Set<Local> taintsInCaller = new HashSet<Local>(); for (int i = 0; i < callArgs.size(); i++) { if (callArgs.get(i).equivTo(source)) { taintsInCaller.add(paramLocals.get(i)); } } return taintsInCaller; } }; }
/** * Returns the list of parameter references used in this body. The list is as long as the number of parameters declared in * the associated method's signature. The list may have <code>null</code> entries for parameters not referenced in the * body. The returned list is of fixed size. */ public List<Value> getParameterRefs() { Value[] res = new Value[getMethod().getParameterCount()]; for (Unit s : getUnits()) { if (s instanceof IdentityStmt) { Value rightOp = ((IdentityStmt) s).getRightOp(); if (rightOp instanceof ParameterRef) { ParameterRef parameterRef = (ParameterRef) rightOp; res[parameterRef.getIndex()] = parameterRef; } } } return Arrays.asList(res); }
@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")); } } } }
/** * Get all the LHS of the identity statements assigning from parameter references. * * @return a list of size as per <code>getMethod().getParameterCount()</code> with all elements ordered as per the * parameter index. * @throws RuntimeException * if a parameterref is missing */ public List<Local> getParameterLocals() { final int numParams = getMethod().getParameterCount(); final List<Local> retVal = new ArrayList<Local>(numParams); // Parameters are zero-indexed, so the keeping of the index is safe for (Unit u : getUnits()) { if (u instanceof IdentityStmt) { IdentityStmt is = ((IdentityStmt) u); if (is.getRightOp() instanceof ParameterRef) { ParameterRef pr = (ParameterRef) is.getRightOp(); retVal.add(pr.getIndex(), (Local) is.getLeftOp()); } } } if (retVal.size() != numParams) { throw new RuntimeException("couldn't find parameterref! in " + getMethod()); } return retVal; }
/** 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(); } }
for (int i = 0; i < sm.getParameterCount(); i++) { if (sm.getActiveBody().getParameterLocal(i) == l) {
public void validate(Body body, List<ValidationException> exceptions) { boolean hasThisLocal = false; int paramCount = body.getMethod().getParameterCount(); boolean[] parameterRefs = new boolean[paramCount];
protected void buildNative() { ValNode thisNode = null; ValNode retNode = null; if (!method.isStatic()) { thisNode = (ValNode) nodeFactory.caseThis(); } if (method.getReturnType() instanceof RefLikeType) { retNode = (ValNode) nodeFactory.caseRet(); // on library analysis we assume that the return type of an native method can // be anything matching to the declared type. if (pag.getCGOpts().library() != CGOptions.library_disabled) { Type retType = method.getReturnType(); retType.apply(new SparkLibraryHelper(pag, retNode, method)); } } ValNode[] args = new ValNode[method.getParameterCount()]; for (int i = 0; i < method.getParameterCount(); i++) { if (!(method.getParameterType(i) instanceof RefLikeType)) { continue; } args[i] = (ValNode) nodeFactory.caseParm(i); } pag.nativeMethodDriver.process(method, thisNode, retNode, args); }
if (sm.getParameterCount() > 0) { parameters = new ArrayList<MethodParameter>(); for (Type tp : sm.getParameterTypes()) {
public SimpleMethodLocalObjectsAnalysis(UnitGraph g, ClassLocalObjectsAnalysis cloa, InfoFlowAnalysis dfa) { super(g, dfa, true, true); // special version doesn't run analysis yet mlocounter++; printMessages = false; SootMethod method = g.getBody().getMethod(); AbstractDataSource sharedDataSource = new AbstractDataSource(new String("SHARED")); // Add a source for every parameter that is shared for (int i = 0; i < method.getParameterCount(); i++) // no need to worry about return value... { EquivalentValue paramEqVal = InfoFlowAnalysis.getNodeForParameterRef(method, i); if (!cloa.parameterIsLocal(method, paramEqVal)) { addToEntryInitialFlow(sharedDataSource, paramEqVal.getValue()); addToNewInitialFlow(sharedDataSource, paramEqVal.getValue()); } } for (SootField sf : cloa.getSharedFields()) { EquivalentValue fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(method, sf); addToEntryInitialFlow(sharedDataSource, fieldRefEqVal.getValue()); addToNewInitialFlow(sharedDataSource, fieldRefEqVal.getValue()); } if (printMessages) { logger.debug("----- STARTING SHARED/LOCAL ANALYSIS FOR " + g.getBody().getMethod() + " -----"); } doFlowInsensitiveAnalysis(); if (printMessages) { logger.debug("----- ENDING SHARED/LOCAL ANALYSIS FOR " + g.getBody().getMethod() + " -----"); } }
private CallLocalityContext getContextFor(SootMethod sm, boolean includePrimitiveDataFlowIfAvailable) { CallLocalityContext context; if (includePrimitiveDataFlowIfAvailable) { context = new CallLocalityContext(primitiveDfa.getMethodInfoFlowSummary(sm).getNodes()); } else { context = new CallLocalityContext(dfa.getMethodInfoFlowSummary(sm).getNodes()); } // Set context for every parameter that is shared for (int i = 0; i < sm.getParameterCount(); i++) // no need to worry about return value... { EquivalentValue paramEqVal = InfoFlowAnalysis.getNodeForParameterRef(sm, i); if (parameterIsLocal(sm, paramEqVal, includePrimitiveDataFlowIfAvailable)) { context.setParamLocal(i); } else { context.setParamShared(i); } } for (SootField sf : getLocalFields()) { EquivalentValue fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, sf); context.setFieldLocal(fieldRefEqVal); } for (SootField sf : getSharedFields()) { EquivalentValue fieldRefEqVal = InfoFlowAnalysis.getNodeForFieldRef(sm, sf); context.setFieldShared(fieldRefEqVal); } return context; }