soot.jimple.NullConstant Java Examples
The following examples show how to use
soot.jimple.NullConstant.
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: FixUndefinedLocals.java From JAADAS with GNU General Public License v3.0 | 6 votes |
public static PushInst getPushInitializer(Local l, Type t) { if (t instanceof IntegerType) { return Baf.v().newPushInst(IntConstant.v(soot.jbco.util.Rand.getInt())); } else if (t instanceof RefLikeType || t instanceof StmtAddressType) { return Baf.v().newPushInst(NullConstant.v()); } else if (t instanceof LongType) { return Baf.v().newPushInst(LongConstant.v(soot.jbco.util.Rand.getLong())); } else if (t instanceof FloatType) { return Baf.v().newPushInst( FloatConstant.v(soot.jbco.util.Rand.getFloat())); } else if (t instanceof DoubleType) { return Baf.v().newPushInst( DoubleConstant.v(soot.jbco.util.Rand.getDouble())); } return null; }
Example #2
Source File: DexNullThrowTransformer.java From JAADAS with GNU General Public License v3.0 | 6 votes |
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { LocalCreation lc = new LocalCreation(b.getLocals(), "ex"); for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext(); ) { Unit u = unitIt.next(); // Check for a null exception if (u instanceof ThrowStmt) { ThrowStmt throwStmt = (ThrowStmt) u; if (throwStmt.getOp() == NullConstant.v() || throwStmt.getOp().equals(IntConstant.v(0)) || throwStmt.getOp().equals(LongConstant.v(0))) { createThrowStmt(b, throwStmt, lc); } } } }
Example #3
Source File: ExprVisitor.java From JAADAS with GNU General Public License v3.0 | 5 votes |
private Value fixNullConstant(Value potentialNullConstant) { /* * The bytecode spec says: "In terms of bitwise representation, (Object) null == (int) 0." * So use an IntConstant(0) for null comparison in if-*z opcodes. */ if (potentialNullConstant instanceof NullConstant) { return IntConstant.v(0); } return potentialNullConstant; }
Example #4
Source File: PointsToGraph.java From vasco with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a new node for a constant. */ private NewExpr constantNewExpr(Constant constant) { if (constant instanceof StringConstant) { return STRING_SITE; } else if (constant instanceof ClassConstant) { return CLASS_SITE; } else if (constant instanceof NullConstant) { return null; } else { throw new RuntimeException(constant.toString()); } }
Example #5
Source File: InstrumentationUtils.java From DroidRA with GNU Lesser General Public License v2.1 | 5 votes |
public static Value toDefaultSootTypeValue(Type sootType) { String type = sootType.toString(); if ("boolean".equals(type)) { IntConstant.v(0); } else if ("byte".equals(type)) { return IntConstant.v(0); } else if ("char".equals(type)) { return IntConstant.v(0); } else if ("short".equals(type)) { return IntConstant.v(0); } else if ("int".equals(type)) { return IntConstant.v(0); } else if ("long".equals(type)) { return LongConstant.v(0); } else if ("float".equals(type)) { return FloatConstant.v(0); } else if ("double".equals(type)) { return DoubleConstant.v(0); } return NullConstant.v(); }
Example #6
Source File: NormalEdgeFunctionFactory.java From DroidRA with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns a normal edge function. * * @param curr The current statement. * @param currNode The current variable. * @param succNode The variable the current variable is propagated to after the statement. * @param zeroValue The zero value, which represents the absence of a data flow fact. * @param pointsToAnalysis The pointer analysis. * @return A normal edge function. */ public EdgeFunction<BasePropagationValue> getNormalEdgeFunction(Unit curr, Value currNode, Value succNode, Value zeroValue, PointsToAnalysis pointsToAnalysis) { if (curr instanceof AssignStmt) { if (logger.isDebugEnabled()) { logger.debug("Normal edge: " + curr); logger.debug(currNode + " " + succNode); } AssignStmt assignStmt = (AssignStmt) curr; final Value left = assignStmt.getLeftOp(); final String type = left.getType().toString(); final Value right = assignStmt.getRightOp(); if (Model.v().isModeledType(type)) { if (currNode.equivTo(zeroValue) && succNode.equivTo(left)) { if (right instanceof StaticFieldRef) { StaticFieldRef staticFieldRef = (StaticFieldRef) right; Argument[] arguments = Model.v().getArgumentsForStaticField(staticFieldRef.getField().getSignature()); EdgeFunction<BasePropagationValue> result = PropagationTransformerFactory.makeTransformer(null, arguments, false); if (arguments != null) { if (logger.isDebugEnabled()) { logger.debug("Returning " + result); } return PropagationTransformerFactory.makeTransformer(null, arguments, false); } } else if (right instanceof NullConstant) { return PropagationTransformerFactory.makeTransformer(null, null, false); } } } } return EdgeIdentity.v(); }
Example #7
Source File: AsmMethodSource.java From JAADAS with GNU General Public License v3.0 | 5 votes |
private void convertConstInsn(InsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Value v; if (op == ACONST_NULL) v = NullConstant.v(); else if (op >= ICONST_M1 && op <= ICONST_5) v = IntConstant.v(op - ICONST_0); else if (op == LCONST_0 || op == LCONST_1) v = LongConstant.v(op - LCONST_0); else if (op >= FCONST_0 && op <= FCONST_2) v = FloatConstant.v(op - FCONST_0); else if (op == DCONST_0 || op == DCONST_1) v = DoubleConstant.v(op - DCONST_0); else throw new AssertionError("Unknown constant opcode: " + op); opr = new Operand(insn, v); frame.out(opr); } else { opr = out[0]; } if (op == LCONST_0 || op == LCONST_1 || op == DCONST_0 || op == DCONST_1) { pushDual(opr); } else { push(opr); } }
Example #8
Source File: DexNullArrayRefTransformer.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * Checks whether the given local is guaranteed to be always null at the * given statement * @param s The statement at which to check the local * @param base The local to check * @param defs The definition analysis object to use for the check * @return True if the given local is guaranteed to always be null at the * given statement, otherwise false */ private boolean isAlwaysNullBefore(Stmt s, Local base, LocalDefs defs) { List<Unit> baseDefs = defs.getDefsOfAt(base, s); if (baseDefs.isEmpty()) return true; for (Unit u : baseDefs) { if (!(u instanceof DefinitionStmt)) return false; DefinitionStmt defStmt = (DefinitionStmt) u; if (defStmt.getRightOp() != NullConstant.v()) return false; } return true; }
Example #9
Source File: NullCheckEliminator.java From JAADAS with GNU General Public License v3.0 | 5 votes |
public void internalTransform(Body body, String phaseName, Map<String,String> options) { // really, the analysis should be able to use its own results to determine // that some branches are dead, but since it doesn't we just iterate. boolean changed; do { changed=false; NullnessAnalysis analysis=analysisFactory.newAnalysis(new ExceptionalUnitGraph(body)); Chain<Unit> units=body.getUnits(); Stmt s; for(s=(Stmt) units.getFirst();s!=null;s=(Stmt) units.getSuccOf(s)) { if(!(s instanceof IfStmt)) continue; IfStmt is=(IfStmt) s; Value c=is.getCondition(); if(!(c instanceof EqExpr || c instanceof NeExpr)) continue; BinopExpr e=(BinopExpr) c; Immediate i=null; if(e.getOp1() instanceof NullConstant) i=(Immediate) e.getOp2(); if(e.getOp2() instanceof NullConstant) i=(Immediate) e.getOp1(); if(i==null) continue; boolean alwaysNull = analysis.isAlwaysNullBefore(s, i); boolean alwaysNonNull = analysis.isAlwaysNonNullBefore(s, i); int elim=0; // -1 => condition is false, 1 => condition is true if(alwaysNonNull) elim=c instanceof EqExpr ? -1 : 1; if(alwaysNull) elim=c instanceof EqExpr ? 1 : -1; Stmt newstmt=null; if(elim==-1) newstmt=Jimple.v().newNopStmt(); if(elim==1) newstmt=Jimple.v().newGotoStmt(is.getTarget()); if(newstmt!=null) { units.swapWith(s,newstmt); s=newstmt; changed=true; } } } while(changed); }
Example #10
Source File: NullnessAnalysis.java From JAADAS with GNU General Public License v3.0 | 5 votes |
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) { Value left = assignStmt.getLeftOp(); Value right = assignStmt.getRightOp(); //unbox casted value if(right instanceof JCastExpr) { JCastExpr castExpr = (JCastExpr) right; right = castExpr.getOp(); } //if we have a definition (assignment) statement to a ref-like type, handle it, if ( isAlwaysNonNull(right) || right instanceof NewExpr || right instanceof NewArrayExpr || right instanceof NewMultiArrayExpr || right instanceof ThisRef || right instanceof StringConstant || right instanceof ClassConstant || right instanceof CaughtExceptionRef) { //if we assign new... or @this, the result is non-null out.put(left,NON_NULL); } else if(right==NullConstant.v()) { //if we assign null, well, it's null out.put(left, NULL); } else if(left instanceof Local && right instanceof Local) { out.put(left, out.get(right)); } else { out.put(left, TOP); } }
Example #11
Source File: NullnessAnalysis.java From JAADAS with GNU General Public License v3.0 | 5 votes |
private void handleEqualityOrNonEqualityCheck(AbstractBinopExpr eqExpr, AnalysisInfo in, AnalysisInfo out, AnalysisInfo outBranch) { Value left = eqExpr.getOp1(); Value right = eqExpr.getOp2(); Value val=null; if(left==NullConstant.v()) { if(right!=NullConstant.v()) { val = right; } } else if(right==NullConstant.v()) { if(left!=NullConstant.v()) { val = left; } } //if we compare a local with null then process further... if(val!=null && val instanceof Local) { if(eqExpr instanceof JEqExpr) //a==null handleEquality(val, out, outBranch); else if(eqExpr instanceof JNeExpr) //a!=null handleNonEquality(val, out, outBranch); else throw new IllegalStateException("unexpected condition: "+eqExpr.getClass()); } }
Example #12
Source File: LibraryClassPatcher.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * Creates a synthetic "java.lang.Thread.run()" method implementation that * calls the target previously passed in when the constructor was called * @param smRun The run() method for which to create a synthetic * implementation * @param runnable The "java.lang.Runnable" interface * @param fldTarget The field containing the target object */ private void patchThreadRunMethod(SootMethod smRun, SootClass runnable, SootField fldTarget) { SootClass sc = smRun.getDeclaringClass(); Body b = Jimple.v().newBody(smRun); smRun.setActiveBody(b); Local thisLocal = Jimple.v().newLocal("this", sc.getType()); b.getLocals().add(thisLocal); b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType()))); Local targetLocal = Jimple.v().newLocal("target", runnable.getType()); b.getLocals().add(targetLocal); b.getUnits().add(Jimple.v().newAssignStmt(targetLocal, Jimple.v().newInstanceFieldRef(thisLocal, fldTarget.makeRef()))); Unit retStmt = Jimple.v().newReturnVoidStmt(); // If (this.target == null) return; b.getUnits().add(Jimple.v().newIfStmt(Jimple.v().newEqExpr(targetLocal, NullConstant.v()), retStmt)); // Invoke target.run() b.getUnits().add(Jimple.v().newInvokeStmt(Jimple.v().newInterfaceInvokeExpr(targetLocal, runnable.getMethod("void run()").makeRef()))); b.getUnits().add(retStmt); }
Example #13
Source File: PathExecutionTransformer.java From FuzzDroid with Apache License 2.0 | 5 votes |
private void instrumentEachBranchAccess(Body body, IfStmt ifStmt){ String methodSignature = body.getMethod().getSignature(); String condition = ifStmt.getCondition().toString(); Unit generatedJimpleCodeForBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", RefType.v("java.lang.String"), StringConstant.v(methodSignature), RefType.v("java.lang.String"), StringConstant.v(condition), RefType.v("java.lang.String"), NullConstant.v() ); generatedJimpleCodeForBranch.addTag(new InstrumentedCodeTag()); Unit generatedJimpleCodeThenBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", RefType.v("java.lang.String"), StringConstant.v(methodSignature), RefType.v("java.lang.String"), NullConstant.v(), RefType.v("java.lang.String"), StringConstant.v("then branch") ); generatedJimpleCodeThenBranch.addTag(new InstrumentedCodeTag()); Unit generatedJimpleCodeElseBranch = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutBranchAccess", RefType.v("java.lang.String"), StringConstant.v(methodSignature), RefType.v("java.lang.String"), NullConstant.v(), RefType.v("java.lang.String"), StringConstant.v("else branch") ); generatedJimpleCodeElseBranch.addTag(new InstrumentedCodeTag()); body.getUnits().insertBefore(generatedJimpleCodeForBranch, ifStmt); //treatment of target statement ("true"-branch) Stmt targetStmt = ifStmt.getTarget(); if(!branchTargetStmt.contains(targetStmt.toString())) { branchTargetStmt.add(generatedJimpleCodeThenBranch.toString()); body.getUnits().insertBefore(generatedJimpleCodeThenBranch, targetStmt); } //treatment of "else"-branch body.getUnits().insertAfter(generatedJimpleCodeElseBranch, ifStmt); }
Example #14
Source File: ConstraintCollector.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseIfStmt(IfStmt stmt) { if (uses) { ConditionExpr cond = (ConditionExpr) stmt.getCondition(); BinopExpr expr = cond; Value lv = expr.getOp1(); Value rv = expr.getOp2(); TypeVariable lop; TypeVariable rop; // ******** LEFT ******** if (lv instanceof Local) { lop = resolver.typeVariable((Local) lv); } else if (lv instanceof DoubleConstant) { lop = resolver.typeVariable(DoubleType.v()); } else if (lv instanceof FloatConstant) { lop = resolver.typeVariable(FloatType.v()); } else if (lv instanceof IntConstant) { lop = resolver.typeVariable(IntType.v()); } else if (lv instanceof LongConstant) { lop = resolver.typeVariable(LongType.v()); } else if (lv instanceof NullConstant) { lop = resolver.typeVariable(NullType.v()); } else if (lv instanceof StringConstant) { lop = resolver.typeVariable(RefType.v("java.lang.String")); } else if (lv instanceof ClassConstant) { lop = resolver.typeVariable(RefType.v("java.lang.Class")); } else { throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass()); } // ******** RIGHT ******** if (rv instanceof Local) { rop = resolver.typeVariable((Local) rv); } else if (rv instanceof DoubleConstant) { rop = resolver.typeVariable(DoubleType.v()); } else if (rv instanceof FloatConstant) { rop = resolver.typeVariable(FloatType.v()); } else if (rv instanceof IntConstant) { rop = resolver.typeVariable(IntType.v()); } else if (rv instanceof LongConstant) { rop = resolver.typeVariable(LongType.v()); } else if (rv instanceof NullConstant) { rop = resolver.typeVariable(NullType.v()); } else if (rv instanceof StringConstant) { rop = resolver.typeVariable(RefType.v("java.lang.String")); } else if (rv instanceof ClassConstant) { rop = resolver.typeVariable(RefType.v("java.lang.Class")); } else { throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass()); } TypeVariable common = resolver.typeVariable(); rop.addParent(common); lop.addParent(common); } }
Example #15
Source File: RegisterAllocator.java From JAADAS with GNU General Public License v3.0 | 4 votes |
private Register asConstant(Value v, ConstantVisitor constantV) { Constant c = (Constant) v; Register constantRegister = null; List<Register> rArray = null; AtomicInteger iI = null; if (c instanceof ClassConstant) { rArray = classConstantReg; iI = classI; } else if (c instanceof NullConstant) { rArray = nullConstantReg; iI = nullI; } else if (c instanceof FloatConstant) { rArray = floatConstantReg; iI = floatI; } else if (c instanceof IntConstant) { rArray = intConstantReg; iI = intI; } else if (c instanceof LongConstant) { rArray = longConstantReg; iI = longI; } else if (c instanceof DoubleConstant) { rArray = doubleConstantReg; iI = doubleI; } else if (c instanceof StringConstant) { rArray = stringConstantReg; iI = stringI; } else { throw new RuntimeException("Error. Unknown constant type: '"+ c.getType() +"'"); } if (rArray.size() == 0 || iI.intValue() >= rArray.size()) { rArray.add(new Register(c.getType(), nextRegNum)); nextRegNum += SootToDexUtils.getDexWords(c.getType()); } constantRegister = rArray.get(iI.intValue()).clone(); iI.set(iI.intValue() + 1); // "load" constant into the register... constantV.setDestination(constantRegister); c.apply(constantV); // ...but return an independent register object return constantRegister.clone(); }
Example #16
Source File: PathExecutionTransformer.java From FuzzDroid with Apache License 2.0 | 4 votes |
private void instrumentInfoAboutNonApiCaller(Body body, Unit unit) { //our instrumented code if(unit.hasTag(InstrumentedCodeTag.name)) return; InvokeExpr invokeExpr = null; if(unit instanceof DefinitionStmt) { DefinitionStmt defStmt = (DefinitionStmt)unit; if(defStmt.containsInvokeExpr()) { invokeExpr = defStmt.getInvokeExpr(); } } else if(unit instanceof InvokeStmt) { InvokeStmt invokeStmt = (InvokeStmt)unit; invokeExpr = invokeStmt.getInvokeExpr(); } if(invokeExpr != null) { if(!UtilInstrumenter.isApiCall(invokeExpr)) { String invokeExprMethodSignature = invokeExpr.getMethod().getSignature(); List<Value> parameter = invokeExpr.getArgs(); List<Unit> generated = new ArrayList<Unit>(); Pair<Value, List<Unit>> arrayRefAndInstrumentation = UtilInstrumenter.generateParameterArray(parameter, body); List<Unit> generatedArrayInstrumentation = arrayRefAndInstrumentation.getSecond(); Value arrayRef = arrayRefAndInstrumentation.getFirst(); Unit generatedInvokeStmt = UtilInstrumenter.makeJimpleStaticCallForPathExecution("logInfoAboutNonApiMethodCaller", RefType.v("java.lang.String"), StringConstant.v(body.getMethod().getSignature()), RefType.v("java.lang.String"), StringConstant.v(invokeExprMethodSignature), UtilInstrumenter.getParameterArrayType(), (parameter.isEmpty())? NullConstant.v() : arrayRef); generatedInvokeStmt.addTag(new InstrumentedCodeTag()); generated.addAll(generatedArrayInstrumentation); generated.add(generatedInvokeStmt); body.getUnits().insertBefore(generated, unit); } } }
Example #17
Source File: ConstantVisitor.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseNullConstant(NullConstant v) { // dex bytecode spec says: "In terms of bitwise representation, (Object) null == (int) 0." stmtV.addInsn(buildConstInsn(0), origStmt); }
Example #18
Source File: Walker.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void outANullConstant(ANullConstant node) { mProductions.addLast(NullConstant.v()); }
Example #19
Source File: ValueTemplatePrinter.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseNullConstant(NullConstant v) { printConstant(v); }
Example #20
Source File: UnitThrowAnalysis.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseNullConstant(NullConstant c) { }
Example #21
Source File: ExprTranslator.java From JAADAS with GNU General Public License v3.0 | 4 votes |
public void caseNullConstant(NullConstant expr) { jt.notSupported("The null constant is not supported"); }
Example #22
Source File: StringValueAnalysis.java From DroidRA with GNU Lesser General Public License v2.1 | 4 votes |
/** * Returns the string values of a variable used at a given statement. * * @param value The value or variable that should be determined. * @param stmt The statement that uses the variable whose values should be determined. * @return The set of possible values. */ @Override public Set<Object> computeVariableValues(Value value, Stmt stmt) { if (value instanceof StringConstant) { return Collections.singleton((Object) ((StringConstant) value).value.intern()); } else if (value instanceof NullConstant) { return Collections.singleton((Object) "<NULL>"); } else if (value instanceof Local) { Local local = (Local) value; ConstraintCollector constraintCollector = new ConstraintCollector(new ExceptionalUnitGraph(AnalysisParameters.v().getIcfg() .getMethodOf(stmt).getActiveBody())); LanguageConstraints.Box lcb = constraintCollector.getConstraintOfAt(local, stmt); RecursiveDAGSolverVisitorLC dagvlc = new RecursiveDAGSolverVisitorLC(5, null, new RecursiveDAGSolverVisitorLC.MethodReturnValueAnalysisInterface() { @Override public Set<Object> getMethodReturnValues(Call call) { return MethodReturnValueManager.v().getMethodReturnValues(call); } }); if (dagvlc.solve(lcb)) { // boolean flag = false; // if (dagvlc.result.size() == 0 || flag == true) { // System.out.println("ID: " + lcb.uid); // // int dbg = 10; // // while (dbg == 10) { // System.out.println("Returning " + dagvlc.result); // System.out.println("Returning.. " + lcb); // dagvlc.solve(lcb); // System.out.println("done"); // // } // } // System.out.println("Returning " + dagvlc.result); return new HashSet<Object>(dagvlc.result); } else { return Collections.singleton((Object) TOP_VALUE); } } else { return Collections.singleton((Object) TOP_VALUE); } }
Example #23
Source File: ICCRedirectionCreator.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 4 votes |
public SootMethod generateRedirectMethodForStartActivityForResult(SootClass originActivity, SootClass destComp) { String newSM_name = "redirector" + num++; List<Type> newSM_parameters = new ArrayList<Type>(); newSM_parameters.add(originActivity.getType()); newSM_parameters.add(INTENT_TYPE); Type newSM_return_type = VoidType.v(); int modifiers = Modifier.STATIC | Modifier.PUBLIC; SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers); ipcSC.addMethod(newSM); JimpleBody b = Jimple.v().newBody(newSM); newSM.setActiveBody(b); LocalGenerator lg = new LocalGenerator(b); Local originActivityParameterLocal = lg.generateLocal(originActivity.getType()); Unit originActivityParameterU = Jimple.v().newIdentityStmt( originActivityParameterLocal, Jimple.v().newParameterRef(originActivity.getType(), 0)); Local intentParameterLocal = lg.generateLocal(INTENT_TYPE); Unit intentParameterU = Jimple.v().newIdentityStmt( intentParameterLocal, Jimple.v().newParameterRef(INTENT_TYPE, 1)); // new dest component Local destCompLocal = lg.generateLocal(destComp.getType()); Unit newU = (Unit) Jimple.v().newAssignStmt(destCompLocal, Jimple.v().newNewExpr(destComp.getType()) ); //call <init> method List<Type> parameters = new ArrayList<Type>(); parameters.add(INTENT_TYPE); SootMethod method = destComp.getMethod("<init>", parameters, VoidType.v()); List<Value> args = new ArrayList<Value>(); args.add(intentParameterLocal); Unit initU = (Unit) Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(destCompLocal, method.makeRef(), args)); List<SootMethod> sms = destComp.getMethods(); for (SootMethod sm : sms) { System.out.println(sm); } // call onCreate method = destComp.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD); InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(destCompLocal, method.makeRef()); Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke); //call sc.getIntentForActivityResult Local arIntentLocal = lg.generateLocal(INTENT_TYPE); Unit nullarIntentLocalParamU = (Unit) Jimple.v().newAssignStmt( arIntentLocal, NullConstant.v()); method = destComp.getMethodByName("getIntentForActivityResult"); invoke = Jimple.v().newVirtualInvokeExpr(destCompLocal, method.makeRef()); Unit destCompCallU = (Unit) Jimple.v().newAssignStmt(arIntentLocal, invoke); //some apps do not have an onActivityResult method even they use startActivityForResult to communicate with other components. try { method = originActivity.getMethodByName("onActivityResult"); } catch (Exception ex) { method = generateFakeOnActivityResult(originActivity); } Local iLocal1 = lg.generateLocal(IntType.v()); Local iLocal2 = lg.generateLocal(IntType.v()); Unit defaultValueParamU1 = (Unit) Jimple.v().newAssignStmt(iLocal1, IntConstant.v(-1)); Unit defaultValueParamU2 = (Unit) Jimple.v().newAssignStmt(iLocal2, IntConstant.v(-1)); args = new ArrayList<Value>(); args.add(iLocal1); args.add(iLocal2); args.add(arIntentLocal); invoke = Jimple.v().newVirtualInvokeExpr(originActivityParameterLocal, method.makeRef(), args); Unit onActivityResultCall = (Unit) Jimple.v().newInvokeStmt(invoke); b.getUnits().add(originActivityParameterU); b.getUnits().add(intentParameterU); b.getUnits().add(newU); b.getUnits().add(initU); //b.getUnits().add(nullParamU); b.getUnits().add(callU); b.getUnits().add(nullarIntentLocalParamU); b.getUnits().add(destCompCallU); b.getUnits().add(defaultValueParamU1); b.getUnits().add(defaultValueParamU2); b.getUnits().add(onActivityResultCall); b.getUnits().add(Jimple.v().newReturnVoidStmt()); System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody()); return newSM; }
Example #24
Source File: ICCRedirectionCreator.java From soot-infoflow-android-iccta with GNU Lesser General Public License v2.1 | 4 votes |
public SootMethod generateRedirectMethodForStartActivity(SootClass wrapper) { System.out.println("create method to call wrapper class: "+ wrapper); String newSM_name = "redirector" + num++; List<Type> newSM_parameters = new ArrayList<Type>(); newSM_parameters.add(INTENT_TYPE); Type newSM_return_type = VoidType.v(); int modifiers = Modifier.STATIC | Modifier.PUBLIC; SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers); ipcSC.addMethod(newSM); JimpleBody b = Jimple.v().newBody(newSM); newSM.setActiveBody(b); LocalGenerator lg = new LocalGenerator(b); // identity Local intentParameterLocal = lg.generateLocal(INTENT_TYPE); Unit intentParameterU = Jimple.v().newIdentityStmt( intentParameterLocal, Jimple.v().newParameterRef(INTENT_TYPE, 0)); // new Local al = lg.generateLocal(wrapper.getType()); Unit newU = (Unit) Jimple.v().newAssignStmt(al, Jimple.v().newNewExpr(wrapper.getType()) ); // init List<Type> parameters = new ArrayList<Type>(); parameters.add(INTENT_TYPE); SootMethod method = wrapper.getMethod("<init>", parameters, VoidType.v()); List<Value> args = new ArrayList<Value>(); args.add(intentParameterLocal); Unit initU = (Unit) Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args)); // call dummyMainMethod //method = wrapper.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD); method = wrapper.getMethodByName("onCreate"); args = new ArrayList<Value>(); Local pLocal = lg.generateLocal(RefType.v("android.os.Bundle")); Unit nullParamU = (Unit) Jimple.v().newAssignStmt(pLocal, NullConstant.v()); args.add(pLocal); InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef(), args); Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke); b.getUnits().add(intentParameterU); b.getUnits().add(newU); b.getUnits().add(initU); b.getUnits().add(nullParamU); b.getUnits().add(callU); b.getUnits().add(Jimple.v().newReturnVoidStmt()); System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody()); return newSM; }