private void changeUntypedConstantsInInvoke(InvokeExpr invokeExpr) { for (int i = 0; i < invokeExpr.getArgCount(); i++) { Value v = invokeExpr.getArg(i); if (!(v instanceof UntypedConstant)) { continue; } Type t = invokeExpr.getMethodRef().parameterType(i); UntypedConstant uc = (UntypedConstant) v; invokeExpr.setArg(i, uc.defineType(t)); } }
/** * Returns true if a method call is fixed, i.e., assuming that all classes in the Scene resemble library code, then client * code cannot possible overwrite the called method. This is trivially true for InvokeStatic and InvokeSpecial, but can * also hold for virtual invokes if all possible call targets in the library cannot be overwritten. * * @see #clientOverwriteableOverwrites(SootMethod) */ public static boolean isFixed(InvokeExpr ie) { return ie instanceof StaticInvokeExpr || ie instanceof SpecialInvokeExpr || !clientOverwriteableOverwrites(ie.getMethod()); }
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; }
private boolean examineInvokeExpr(InvokeExpr e) { List<Value> args = e.getArgs(); List<Type> argTypes = e.getMethodRef().parameterTypes(); assert args.size() == argTypes.size(); for (int i = 0; i < args.size(); i++) { if (args.get(i) == l && isFloatingPointLike(argTypes.get(i))) { return true; } } return false; }
public void caseInvokeExpr(InvokeExpr ie) { inInvokeExpr(ie); for (int i = 0; i < ie.getArgCount(); i++) { caseExprOrRefValueBox(ie.getArgBox(i)); // decideCaseExprOrRef(ie.getArg(i)); } if (ie instanceof InstanceInvokeExpr) { caseInstanceInvokeExpr((InstanceInvokeExpr) ie); } outInvokeExpr(ie); }
if (stmt.containsInvokeExpr()) { InvokeExpr ie = stmt.getInvokeExpr(); SootMethod calledMethod = ie.getMethod(); if (ie instanceof StaticInvokeExpr) { SootMethod calledMethod = ie.getMethod(); int argCount = stmt.getInvokeExpr().getArgCount(); for (int i = 0; i < argCount; i++) { uses.add(ie.getArg(i));
int argCount = stmt.getInvokeExpr().getArgCount(); for (int i = 0; i < argCount; i++) { ret.union(addValue(stmt.getInvokeExpr().getArg(i), method, stmt));
private void handleInvokeExpr(InvokeExpr ie) { if (!uses) { return; } // Handle the parameters SootMethodRef method = ie.getMethodRef(); for (int i = 0; i < ie.getArgCount(); i++) { if (ie.getArg(i) instanceof Local) { Local local = (Local) ie.getArg(i); if (local.getType() instanceof IntegerType) { TypeVariable localType = resolver.typeVariable(local); localType.addParent(resolver.typeVariable(method.parameterType(i))); } } } if (ie instanceof DynamicInvokeExpr) { DynamicInvokeExpr die = (DynamicInvokeExpr) ie; SootMethodRef bootstrapMethod = die.getBootstrapMethodRef(); for (int i = 0; i < die.getBootstrapArgCount(); i++) { if (die.getBootstrapArg(i) instanceof Local) { Local local = (Local) die.getBootstrapArg(i); if (local.getType() instanceof IntegerType) { TypeVariable localType = resolver.typeVariable(local); localType.addParent(resolver.typeVariable(bootstrapMethod.parameterType(i))); } } } } }
protected void setInvokeType(InvokeExpr invokeExpr) { for (int i = 0; i < invokeExpr.getArgCount(); i++) { Value v = invokeExpr.getArg(i); if (!(v instanceof Local)) { continue; } Type t = invokeExpr.getMethodRef().parameterType(i); DalvikTyper.v().setType(invokeExpr.getArgBox(i), t, true); } if (invokeExpr instanceof StaticInvokeExpr) { // nothing to do } else if (invokeExpr instanceof InstanceInvokeExpr) { InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr; DalvikTyper.v().setType(iie.getBaseBox(), RefType.v("java.lang.Object"), true); } else if (invokeExpr instanceof DynamicInvokeExpr) { DynamicInvokeExpr die = (DynamicInvokeExpr) invokeExpr; // ? } else { throw new RuntimeException("error: unhandled invoke expression: " + invokeExpr + " " + invokeExpr.getClass()); } }
private List<Register> getInvokeArgumentRegs(InvokeExpr ie) { constantV.setOrigStmt(origStmt); List<Register> argumentRegs = new ArrayList<Register>(); for (Value arg : ie.getArgs()) { Register currentReg = regAlloc.asImmediate(arg, constantV); argumentRegs.add(currentReg); } return argumentRegs; }
&& (ie.getMethodRef().getSignature().equals("<java.lang.Class: java.lang.Class forName(java.lang.String)>") || ie.getMethodRef().getSignature() .equals("<java.lang.Class: java.lang.Class forName(java.lang.String,boolean,java.lang.ClassLoader)>"))) { found = true; Value classNameValue = ie.getArg(0); newUnits.add(Jimple.v() .newInvokeStmt(Jimple.v() .makeRef(), IntConstant.v(callSiteId), classNameValue))); } else if (callKind == Kind.ClassNewInstance && ie.getMethodRef().getSignature().equals("<java.lang.Class: java.lang.Object newInstance()>")) { found = true; Local classLocal = (Local) ((InstanceInvokeExpr) ie).getBase(); .getMethod("<soot.rtlib.tamiflex.ReflectiveCalls: void knownClassNewInstance(int,java.lang.Class)>") .makeRef(), IntConstant.v(callSiteId), classLocal))); } else if (callKind == Kind.ConstructorNewInstance && ie.getMethodRef().getSignature() .equals("<java.lang.reflect.Constructor: java.lang.Object newInstance(java.lang.Object[])>")) { found = true; "<soot.rtlib.tamiflex.ReflectiveCalls: void knownConstructorNewInstance(int,java.lang.reflect.Constructor)>") .makeRef(), IntConstant.v(callSiteId), constrLocal))); } else if (callKind == Kind.MethodInvoke && ie.getMethodRef().getSignature() .equals("<java.lang.reflect.Method: java.lang.Object invoke(java.lang.Object,java.lang.Object[])>")) { found = true; Local methodLocal = (Local) ((InstanceInvokeExpr) ie).getBase(); Value recv = ie.getArg(0); newUnits.add(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(Scene.v().getMethod( "<soot.rtlib.tamiflex.ReflectiveCalls: void knownMethodInvoke(int,java.lang.Object,java.lang.reflect.Method)>")
@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 (invokeExpr.getMethod().getSignature().equals(INVOKE_SIG)) { if (invokeExpr.getArg(0) instanceof StringConstant) { StringConstant constant = (StringConstant) invokeExpr.getArg(0); Local newLocal = Jimple.v().newLocal("sc" + body.getLocalCount(), constant.getType()); body.getLocals().add(newLocal); body.getUnits().insertBefore(Jimple.v().newAssignStmt(newLocal, constant), u); invokeExpr.setArg(0, newLocal);
private static SootMethod getMethodSafely(InvokeExpr invokeExpr) { try { final SootMethod invokedMethod = invokeExpr.getMethod(); if (invokedMethod == null) { return null; } if (SootMethod.constructorName.equals(invokedMethod.getName()) || SootMethod.staticInitializerName.equals(invokedMethod.getName())) { logger.debug("Skipping wrapping method {} as it is constructor/initializer.", invokedMethod); return null; } final SootClass invokedMethodClass = invokedMethod.getDeclaringClass(); if (!invokedMethodClass.isLibraryClass()) { logger.debug("Skipping wrapping method {} as it is not library one.", invokedMethod); return null; } if (invokeExpr.getMethodRef().declaringClass().isInterface() && !invokedMethodClass.isInterface()) { logger.debug( "Skipping wrapping method {} as original code suppose to execute it on interface {}" + " but resolved code trying to execute it on class {}", invokedMethod, invokeExpr.getMethodRef().declaringClass(), invokedMethodClass); return null; } return invokedMethod; } catch (RuntimeException exception) { logger.debug("Cannot resolve method of InvokeExpr: " + invokeExpr.toString(), exception); return null; } }
public boolean hasNonLocalEffects(SootMethod containingMethod, InvokeExpr ie, SootMethod context) { SootMethod target = ie.getMethodRef().resolve(); ParameterRef pr = (ParameterRef) node; if (pr.getIndex() != -1) { if (!isObjectLocalToContext(ie.getArg(pr.getIndex()), containingMethod, context)) { return true; ParameterRef pr = (ParameterRef) node; if (pr.getIndex() != -1) { if (!isObjectLocalToContext(ie.getArg(pr.getIndex()), containingMethod, context)) { return true; ParameterRef pr = (ParameterRef) node; if (pr.getIndex() != -1) { if (!isObjectLocalToContext(ie.getArg(pr.getIndex()), containingMethod, context)) { return true;
SootMethod tgt = ie.getMethod(); if (tgt != null) { addEdge(m, s, tgt); + "(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)>")) { Local receiver = (Local) ie.getArg(0); addVirtualCallSite(s, m, receiver, null, sigObjRun, Kind.PRIVILEGED); if (!Options.v().ignore_resolution_errors()) { throw new InternalError( "Unresolved target " + ie.getMethod() + ". Resolution error should have occured earlier.");
protected MutableDirectedGraph<EquivalentValue> getInvokeAbbreviatedInfoFlowGraph(InvokeExpr ie, SootMethod context) { // get the data flow graph for each possible target of ie, // then combine them conservatively and return the result. SootMethodRef methodRef = ie.getMethodRef(); return getMethodInfoFlowAnalysis(methodRef.resolve()).getMethodAbbreviatedInfoFlowGraph(); }
/** * Method nondet*() of the Verifier class used to formula SV-COMP problems. * Replace those method with a simple havoc. */ private void translateVerifierNondet(Type t, Value optionalLhs, InvokeExpr call) { Verify.verify(call.getArgCount() == 0); if (optionalLhs != null) { final InvokeExpr newInvokeExpr = Jimple.v().newStaticInvokeExpr( SootTranslationHelpers.v().getHavocMethod(t).makeRef()); final Unit stmt = Jimple.v().newAssignStmt(optionalLhs, newInvokeExpr); translateMethodInvokation(stmt, optionalLhs, newInvokeExpr); } }
doBreak = true; } else if (r instanceof InvokeExpr) { usedAsFloatingPoint = isFloatingPointLike(((InvokeExpr) r).getType()); doBreak = true; } else if (r instanceof LengthExpr) {