soot.jimple.ParameterRef Java Examples
The following examples show how to use
soot.jimple.ParameterRef.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValueTemplatePrinter.java From JAADAS with GNU General Public License v3.0 | 6 votes |
public void caseParameterRef(ParameterRef v) { String oldName = varName; Type paramType= v.getType(); suggestVariableName("paramType"); String paramTypeName = this.varName; ttp.setVariableName(paramTypeName); paramType.apply(ttp); int number = v.getIndex(); suggestVariableName("number"); p.println("int "+varName+"=" + number+ ";"); p.println("Value "+oldName+" = Jimple.v().newParameterRef("+paramTypeName+", "+varName+");"); varName = oldName; }
Example #2
Source File: StmtVisitor.java From JAADAS with GNU General Public License v3.0 | 6 votes |
@Override public void caseIdentityStmt(IdentityStmt stmt) { Value lhs = stmt.getLeftOp(); Value rhs = stmt.getRightOp(); if (rhs instanceof CaughtExceptionRef) { // save the caught exception with move-exception Register localReg = regAlloc.asLocal(lhs); addInsn(new Insn11x(Opcode.MOVE_EXCEPTION, localReg), stmt); this.insnRegisterMap.put(insns.get(insns.size() - 1), LocalRegisterAssignmentInformation.v(localReg, (Local)lhs)); } else if (rhs instanceof ThisRef || rhs instanceof ParameterRef) { /* * do not save the ThisRef or ParameterRef in a local, because it always has a parameter register already. * at least use the local for further reference in the statements */ Local localForThis = (Local) lhs; regAlloc.asParameter(belongingMethod, localForThis); parameterInstructionsList.add(LocalRegisterAssignmentInformation.v(regAlloc.asLocal(localForThis).clone(), localForThis)); } else { throw new Error("unknown Value as right-hand side of IdentityStmt: " + rhs); } }
Example #3
Source File: Body.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** Return LHS of the first identity stmt assigning from \@parameter i. **/ public Local getParameterLocal(int i) { for (Unit s : getUnits()) { if (s instanceof IdentityStmt && ((IdentityStmt)s).getRightOp() instanceof ParameterRef) { IdentityStmt is = (IdentityStmt)s; ParameterRef pr = (ParameterRef)is.getRightOp(); if (pr.getIndex() == i) return (Local)is.getLeftOp(); } } throw new RuntimeException("couldn't find parameterref" + i +"! in "+getMethod()); }
Example #4
Source File: Body.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * 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){ //FLANKER FIX BEGIN //throw new RuntimeException("couldn't find parameterref! in " + getMethod()); return retVal; //FLANKER FIX END } return retVal; }
Example #5
Source File: DefaultSourceSinkManager.java From JAADAS with GNU General Public License v3.0 | 5 votes |
@Override public SourceInfo getSourceInfo(Stmt sCallSite, InterproceduralCFG<Unit, SootMethod> cfg) { SootMethod callee = sCallSite.containsInvokeExpr() ? sCallSite.getInvokeExpr().getMethod() : null; AccessPath targetAP = null; if (callee != null && sources.contains(callee.toString())) { if (callee.getReturnType() != null && sCallSite instanceof DefinitionStmt) { // Taint the return value Value leftOp = ((DefinitionStmt) sCallSite).getLeftOp(); targetAP = new AccessPath(leftOp, true); } else if (sCallSite.getInvokeExpr() instanceof InstanceInvokeExpr) { // Taint the base object Value base = ((InstanceInvokeExpr) sCallSite.getInvokeExpr()).getBase(); targetAP = new AccessPath(base, true); } } // Check whether we need to taint parameters else if (sCallSite instanceof IdentityStmt) { IdentityStmt istmt = (IdentityStmt) sCallSite; if (istmt.getRightOp() instanceof ParameterRef) { ParameterRef pref = (ParameterRef) istmt.getRightOp(); SootMethod currentMethod = cfg.getMethodOf(istmt); if (parameterTaintMethods.contains(currentMethod.toString())) targetAP = new AccessPath(currentMethod.getActiveBody() .getParameterLocal(pref.getIndex()), true); } } if (targetAP == null) return null; // Create the source information data structure return new SourceInfo(targetAP); }
Example #6
Source File: InterproceduralConstantValuePropagator.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * Checks whether the given method is a library stub method * @param method The method to check * @return True if the given method is an Android library stub, false * otherwise */ private boolean methodIsAndroidStub(SootMethod method) { if (!(Options.v().src_prec() == Options.src_prec_apk && method.getDeclaringClass().isLibraryClass() && SystemClassHandler.isClassInSystemPackage( method.getDeclaringClass().getName()))) return false; // Check whether there is only a single throw statement for (Unit u : method.getActiveBody().getUnits()) { if (u instanceof DefinitionStmt) { DefinitionStmt defStmt = (DefinitionStmt) u; if (!(defStmt.getRightOp() instanceof ThisRef) && !(defStmt.getRightOp() instanceof ParameterRef) && !(defStmt.getRightOp() instanceof NewExpr)) return false; } else if (u instanceof InvokeStmt) { InvokeStmt stmt = (InvokeStmt) u; // Check for exception constructor invocations SootMethod callee = stmt.getInvokeExpr().getMethod(); if (!callee.getSubSignature().equals("void <init>(java.lang.String)")) // Check for super class constructor invocation if (!(method.getDeclaringClass().hasSuperclass() && callee.getDeclaringClass() == method.getDeclaringClass().getSuperclass() && callee.getName().equals("<init>"))) return false; } else if (!(u instanceof ThrowStmt)) return false; } return true; }
Example #7
Source File: InterproceduralConstantValuePropagator.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * Gets the first statement in the body of the given method that does not * assign the "this" local or a parameter local * @param sm The method in whose body to look * @return The first non-identity statement in the body of the given method. */ private Unit getFirstNonIdentityStmt(SootMethod sm) { for (Unit u : sm.getActiveBody().getUnits()) { if (!(u instanceof IdentityStmt)) return u; IdentityStmt id = (IdentityStmt) u; if (!(id.getRightOp() instanceof ThisRef) && !(id.getRightOp() instanceof ParameterRef)) return u; } return null; }
Example #8
Source File: FastDexTrapTightener.java From JAADAS with GNU General Public License v3.0 | 5 votes |
private boolean isDexInstruction(Unit unit) { if (unit instanceof IdentityStmt) { IdentityStmt is = (IdentityStmt) unit; return !(is.getRightOp() instanceof ThisRef || is.getRightOp() instanceof ParameterRef); } return true; }
Example #9
Source File: Body.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * 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); }
Example #10
Source File: IntValueAnalysis.java From DroidRA with GNU Lesser General Public License v2.1 | 5 votes |
/** * Return all possible values for an integer local variable. * * @param start The statement where the analysis should start. * @param local The local variable whose values we are looking for. * @param visitedStmts The set of visited statement. * @return The set of possible values for the local variable. */ private Set<Object> findIntAssignmentsForLocal(Stmt start, Local local, Set<Stmt> visitedStmts) { List<DefinitionStmt> assignStmts = findAssignmentsForLocal(start, local, true, new HashSet<Pair<Unit, Local>>()); Set<Object> result = new HashSet<>(assignStmts.size()); for (DefinitionStmt assignStmt : assignStmts) { Value rhsValue = assignStmt.getRightOp(); if (rhsValue instanceof IntConstant) { result.add(((IntConstant) rhsValue).value); } else if (rhsValue instanceof LongConstant) { result.add(((LongConstant) rhsValue).value); } else if (rhsValue instanceof ParameterRef) { ParameterRef parameterRef = (ParameterRef) rhsValue; Iterator<Edge> edges = Scene.v().getCallGraph() .edgesInto(AnalysisParameters.v().getIcfg().getMethodOf(assignStmt)); while (edges.hasNext()) { Edge edge = edges.next(); InvokeExpr invokeExpr = edge.srcStmt().getInvokeExpr(); Value argValue = invokeExpr.getArg(parameterRef.getIndex()); if (argValue instanceof IntConstant) { result.add(((IntConstant) argValue).value); } else if (argValue instanceof LongConstant) { result.add(((LongConstant) argValue).value); } else if (argValue instanceof Local) { Set<Object> newResults = findIntAssignmentsForLocal(edge.srcStmt(), (Local) argValue, visitedStmts); result.addAll(newResults); } else { result.add(TOP_VALUE); } } } else { return Collections.singleton((Object) TOP_VALUE); } } return result; }
Example #11
Source File: JimpleStmtVisitorImpl.java From FuzzDroid with Apache License 2.0 | 4 votes |
@Override public void caseInvokeStmt(InvokeStmt stmt) { InvokeExpr invokeExpr = stmt.getInvokeExpr(); SootClass declaringClass = invokeExpr.getMethod().getDeclaringClass(); if(exprVisitor.isExpressionThatNeedsToBeConvertedToSMT(invokeExpr)) exprVisitor.convertSpecialExpressionsToSMT(invokeExpr, stmt); else if(UtilInstrumenter.isAppDeveloperCode(declaringClass)) { SootMethod method = invokeExpr.getMethod(); Body body = method.retrieveActiveBody(); SMTBinding newRhs = getBindingForTaintedValue(stmt); //if there is no taint-tracking involved (newRhs == null), we do not have to do anything here if(newRhs == null) return; int indexOfInterest = -1; for(int i = 0; i < invokeExpr.getArgCount(); i++) { if(newRhs.getVariableName().equals(invokeExpr.getArg(i).toString())) { indexOfInterest = i; break; } } if(indexOfInterest == -1) return; for(Unit unit : body.getUnits()) { if(unit instanceof IdentityStmt) { IdentityStmt identity = (IdentityStmt)unit; Value rhs = identity.getRightOp(); if(rhs instanceof ParameterRef) { ParameterRef param = (ParameterRef)rhs; if(param.getIndex() == indexOfInterest) { Value lhs = identity.getLeftOp(); SMTBinding newLhs = createNewBindingForValue(lhs); addValueBindingToVariableDeclaration(lhs, newLhs); SMTSimpleAssignment simpleAssignment = new SMTSimpleAssignment(newLhs, new SMTBindingValue(newRhs)); SMTAssertStatement assignmentAssert = new SMTAssertStatement(simpleAssignment); addAssertStmtToAllPrograms(assignmentAssert); } } } } } else { System.err.println(String.format("Double-Check if the following method contains useful information which can be extracted: \n%s", stmt)); } }
Example #12
Source File: ExprTranslator.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseParameterRef(ParameterRef expr) { st.addStatement(new Nop()); }
Example #13
Source File: LocalMustAliasAnalysis.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public static int parameterRefNumber(ParameterRef r) { //unique number for ParameterRef[i] (must be <0) return -1 - r.getIndex(); }
Example #14
Source File: UnitThrowAnalysis.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseParameterRef(ParameterRef v) { }
Example #15
Source File: PolicyEnforcementPoint.java From DroidForce with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isSourceInfoParameter(ResultSourceInfo sInfo) { return sInfo.getSource() instanceof IdentityStmt && ((IdentityStmt) sInfo.getSource()).getRightOp() instanceof ParameterRef; }