soot.jimple.AssignStmt Java Examples
The following examples show how to use
soot.jimple.AssignStmt.
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: TimingBombTransformer.java From FuzzDroid with Apache License 2.0 | 7 votes |
private void prepareAlarmManagerSet(Body body, InvokeStmt setStmt, SootMethodRef reportRef) { Value oldVal = setStmt.getInvokeExpr().getArg(1); Local longLocal = UtilInstrumenter.generateFreshLocal(body, LongType.v()); SootMethod currentTimeMillis = Scene.v().getMethod("<java.lang.System: long currentTimeMillis()>"); StaticInvokeExpr timeInvoke = Jimple.v().newStaticInvokeExpr(currentTimeMillis.makeRef()); AssignStmt timeInitalize = Jimple.v().newAssignStmt(longLocal, timeInvoke); AddExpr addTime = Jimple.v().newAddExpr(longLocal, LongConstant.v(2000L)); AssignStmt timeAssign = Jimple.v().newAssignStmt(longLocal, addTime); body.getUnits().insertBefore(timeInitalize, setStmt); body.getUnits().insertBefore(timeAssign, setStmt); InvokeExpr expr = setStmt.getInvokeExpr(); expr.setArg(0, IntConstant.v(0)); expr.setArg(1, longLocal); // Report the change InvokeStmt reportStmt = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr( reportRef, oldVal, longLocal)); reportStmt.addTag(new InstrumentedCodeTag()); body.getUnits().insertAfter(reportStmt, setStmt); }
Example #2
Source File: TypeStateMachineWeightFunctions.java From SPDS with Eclipse Public License 2.0 | 6 votes |
protected Collection<WeightedForwardQuery<TransitionFunction>> generateAtAllocationSiteOf(SootMethod m, Unit unit, Class allocationSuperType) { if (unit instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) unit; if (assignStmt.getRightOp() instanceof NewExpr) { NewExpr newExpr = (NewExpr) assignStmt.getRightOp(); Value leftOp = assignStmt.getLeftOp(); soot.Type type = newExpr.getType(); if (Scene.v().getOrMakeFastHierarchy().canStoreType(type, Scene.v().getType(allocationSuperType.getName()))) { return Collections.singleton(new WeightedForwardQuery<>(new Statement((Stmt) unit, m), new AllocVal(leftOp, m, assignStmt.getRightOp(), new Statement((Stmt) unit, m)), initialTransition())); } } } return Collections.emptySet(); }
Example #3
Source File: SmartConstantDataExtractorFuzzyAnalysis.java From FuzzDroid with Apache License 2.0 | 6 votes |
private int getConstantArrayIndexForSplitDataFlow(Stmt[] dataflow) { Stmt firstAssign = dataflow[0]; if(firstAssign instanceof AssignStmt) { AssignStmt ass = (AssignStmt)firstAssign; Value value = ass.getRightOp(); if(value instanceof ArrayRef) { ArrayRef aRef = (ArrayRef)value; Value index = aRef.getIndex(); if(index instanceof IntConstant) return ((IntConstant) index).value; } } else throw new RuntimeException("this should not happen - wrong assumption"); return -1; }
Example #4
Source File: AndroidSourceSinkManager.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * Finds the last assignment to the given String local by searching upwards * from the given statement * * @param stmt * The statement from which to look backwards * @param local * The variable for which to look for assignments * @return The last value assigned to the given variable */ private String findLastStringAssignment(Stmt stmt, Local local, BiDiInterproceduralCFG<Unit, SootMethod> cfg) { if (stmt instanceof AssignStmt) { AssignStmt assign = (AssignStmt) stmt; if (assign.getLeftOp() == local) { // ok, now find the new value from the right side if (assign.getRightOp() instanceof StringConstant) return ((StringConstant) assign.getRightOp()).value; } } // Continue the search upwards for (Unit pred : cfg.getPredsOf(stmt)) { if (!(pred instanceof Stmt)) continue; String lastAssignment = findLastStringAssignment((Stmt) pred, local, cfg); if (lastAssignment != null) return lastAssignment; } return null; }
Example #5
Source File: SmartConstantDataExtractorFuzzyAnalysis.java From FuzzDroid with Apache License 2.0 | 6 votes |
private boolean hasConstantIndexAtArrayForSplitDataFlow(Stmt[] dataflow) { Stmt firstAssign = dataflow[0]; if(firstAssign instanceof AssignStmt) { AssignStmt ass = (AssignStmt)firstAssign; Value value = ass.getRightOp(); if(value instanceof ArrayRef) { ArrayRef aRef = (ArrayRef)value; Value index = aRef.getIndex(); if(index instanceof IntConstant) return true; } } else throw new RuntimeException("this should not happen - wrong assumption"); return false; }
Example #6
Source File: DummyMainGenerator.java From DroidRA with GNU Lesser General Public License v2.1 | 6 votes |
public void instrumentDummyMainMethod(SootMethod mainMethod) { Body body = mainMethod.getActiveBody(); PatchingChain<Unit> units = body.getUnits(); for (Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext(); ) { Stmt stmt = (Stmt) iter.next(); if (stmt instanceof IdentityStmt) { continue; } //For the purpose of confusion dex optimization (because of the strategy of generating dummyMain method) AssignStmt aStmt = (AssignStmt) stmt; SootMethod fuzzyMe = generateFuzzyMethod(mainMethod.getDeclaringClass()); InvokeExpr invokeExpr = Jimple.v().newVirtualInvokeExpr(body.getThisLocal(), fuzzyMe.makeRef()); Unit assignU = Jimple.v().newAssignStmt(aStmt.getLeftOp(), invokeExpr); units.insertAfter(assignU, aStmt); break; } }
Example #7
Source File: BaseEntryPointCreator.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * Constructs an array of the given type with a single element of this type * in the given method * @param body The body of the method in which to create the array * @param gen The local generator * @param tp The type of which to create the array * @param constructionStack Set of classes currently being built to avoid * constructor loops * @param parentClasses If a requested type is compatible with one of the * types in this list, the already-created object is used instead of * creating a new one. * @return The local referencing the newly created array, or null if the * array generation failed */ private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp, Set<SootClass> constructionStack, Set<SootClass> parentClasses) { Local local = gen.generateLocal(tp); // Generate a new single-element array NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(), IntConstant.v(1)); AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr); body.getUnits().add(assignArray); // Generate a single element in the array AssignStmt assign = Jimple.v().newAssignStmt (Jimple.v().newArrayRef(local, IntConstant.v(0)), getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses)); body.getUnits().add(assign); return local; }
Example #8
Source File: SMTPreparationPhase.java From FuzzDroid with Apache License 2.0 | 6 votes |
private ResultSourceInfo findDataFlowPathForSink(Stmt sinkStmt, Local sinkLokal, List<ResultSourceInfo> allDataFlows) { for(ResultSourceInfo singleFlow : allDataFlows){ Stmt[] statements = singleFlow.getPath(); AccessPath[] accessPath = singleFlow.getPathAccessPaths(); for(int i = 0; i < statements.length; i++) { Stmt currentStmt = statements[i]; if(currentStmt == sinkStmt) { if(accessPath[i].getPlainValue() == sinkLokal) return singleFlow; } else if(currentStmt instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt)currentStmt; Value lhs = assignStmt.getLeftOp(); if(lhs == sinkLokal) return singleFlow; } } } return null; }
Example #9
Source File: ForwardBoomerangSolver.java From SPDS with Eclipse Public License 2.0 | 6 votes |
@Override protected boolean killFlow(SootMethod m, Stmt curr, Val value) { if (!m.getActiveBody().getLocals().contains(value.value()) && !value.isStatic()) return true; if (curr instanceof AssignStmt) { AssignStmt as = (AssignStmt) curr; // Kill x at any statement x = * during propagation. if (as.getLeftOp().equals(value.value())) { // But not for a statement x = x.f if (as.getRightOp() instanceof InstanceFieldRef) { InstanceFieldRef iie = (InstanceFieldRef) as.getRightOp(); if (iie.getBase().equals(value.value())) { return false; } } return true; } if (as.getLeftOp() instanceof StaticFieldRef) { StaticFieldRef sfr = (StaticFieldRef) as.getLeftOp(); if (value.isStatic() && value.equals(new StaticFieldVal(as.getLeftOp(), sfr.getField(), m))) { return true; } } } return false; }
Example #10
Source File: WholeProgramBoomerang.java From SPDS with Eclipse Public License 2.0 | 6 votes |
@Override public SeedFactory<W> getSeedFactory() { if (seedFactory == null) { seedFactory = new SeedFactory<W>() { @Override protected Collection<? extends Query> generate(SootMethod method, Stmt u) { if (u instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) u; if (options.isAllocationVal(assignStmt.getRightOp())) { return Collections.singleton( new ForwardQuery(new Statement(u, method), new AllocVal(assignStmt.getLeftOp(), method, assignStmt.getRightOp(), new Statement((Stmt) u, method)))); } } return Collections.emptySet(); } @Override public ObservableICFG<Unit, SootMethod> icfg() { return new ObservableStaticICFG(new BoomerangICFG(false)); } }; } return seedFactory; }
Example #11
Source File: Util.java From DroidForce with GNU Lesser General Public License v2.1 | 6 votes |
public static void changeConstantStringInField(SootField sf, String newConstantString) { SootClass sc = sf.getDeclaringClass(); SootMethod sm = sc.getMethodByName("<clinit>"); boolean hasBeenUpdated = false; for (Unit u: sm.retrieveActiveBody().getUnits()) { if (u instanceof AssignStmt) { AssignStmt ass = (AssignStmt)u; Value lop = ass.getLeftOp(); if (lop.toString().equals(sf.toString())) { System.out.println("previous string: "+ ass); ass.setRightOp(StringConstant.v(newConstantString)); hasBeenUpdated = true; System.out.println("updated string : "+ ass); } } } if (!hasBeenUpdated) throw new RuntimeException("error: no StringConstant found for field "+ sf); }
Example #12
Source File: UpdateManifestAndCodeForWaitPDP.java From DroidForce with GNU Lesser General Public License v2.1 | 6 votes |
/** * * @param mainActivityClass * @param mainActivityClass */ public static void updateWaitPDPActivity(String packageName, String mainActivityClass) { if (mainActivityClass.startsWith(".")) { mainActivityClass = packageName + mainActivityClass; } SootClass sc = Scene.v().getSootClass("de.ecspride.javaclasses.WaitPDPActivity"); SootMethod sm = sc.getMethodByName("<init>"); Body b = sm.retrieveActiveBody(); for (Unit u: b.getUnits()) { if (u instanceof AssignStmt) { AssignStmt asg = (AssignStmt)u; if (asg.getRightOp() instanceof StringConstant) { StringConstant cst = (StringConstant)asg.getRightOp(); System.out.println("cst: "+ cst); if (cst.value.equals("")) { asg.setRightOp(StringConstant.v(mainActivityClass)); System.out.println("asg: "+ asg); } } } } }
Example #13
Source File: HasNextStateMachine.java From SPDS with Eclipse Public License 2.0 | 6 votes |
@Override public Set<WeightedForwardQuery<TransitionFunction>> generateSeed(SootMethod method, Unit unit) { Iterator<Edge> edIt = Scene.v().getCallGraph().edgesOutOf(unit); while (edIt.hasNext()) { SootMethod m = edIt.next().getTgt().method(); if (retrieveIteratorConstructors().contains(m)) { Stmt stmt = ((Stmt) unit); InvokeExpr invokeExpr = stmt.getInvokeExpr(); if (stmt instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) stmt; InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr; return Collections .singleton(new WeightedForwardQuery<>( new Statement(stmt, method), new AllocVal(assignStmt.getLeftOp(), method, assignStmt.getLeftOp(), new Statement((Stmt) unit, m)), initialTransition())); } } } return Collections.emptySet(); }
Example #14
Source File: AbstractBoomerangTest.java From SPDS with Eclipse Public License 2.0 | 6 votes |
@Override public SeedFactory<Weight.NoWeight> getSeedFactory() { return new SeedFactory<Weight.NoWeight>() { @Override protected Collection<? extends Query> generate(SootMethod method, Stmt u) { if (u instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) u; if (options.isAllocationVal(assignStmt.getRightOp())) { return Collections.singleton(new ForwardQuery(new Statement((Stmt) u, method), new AllocVal(assignStmt.getLeftOp(), method, assignStmt.getRightOp(), new Statement((Stmt) u, method)))); } } return Collections.emptySet(); } @Override public ObservableICFG<Unit, SootMethod> icfg() { return staticIcfg; } }; }
Example #15
Source File: DexNumTransformer.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * Collect all the locals which are assigned a IntConstant(0) or are used * within a zero comparison. * * @param body * the body to analyze */ private Set<Local> getNumCandidates(Body body) { Set<Local> candidates = new HashSet<Local>(); for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt a = (AssignStmt) u; if (!(a.getLeftOp() instanceof Local)) continue; Local l = (Local) a.getLeftOp(); Value r = a.getRightOp(); if ((r instanceof IntConstant || r instanceof LongConstant)) { candidates.add(l); Debug.printDbg("[add null candidate: ", u); } } } return candidates; }
Example #16
Source File: FieldInstruction.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * Check if the field type equals the type of the value that will be stored in the field. A cast expression has to be introduced for the unequal case. * @return assignment statement which hold a cast or not depending on the types of the operation */ protected AssignStmt getAssignStmt(DexBody body, Local sourceValue, ConcreteRef instanceField) { AssignStmt assign; // Type targetType = getTargetType(body); // if(targetType != UnknownType.v() && targetType != sourceValue.getType() && ! (targetType instanceof RefType)) { // CastExpr castExpr = Jimple.v().newCastExpr(sourceValue, targetType); // Local local = body.generateLocal(targetType); // assign = Jimple.v().newAssignStmt(local, castExpr); // body.add(assign); // beginUnit = assign; // assign = Jimple.v().newAssignStmt(instanceField, local); // } // else { assign = Jimple.v().newAssignStmt(instanceField, sourceValue); // } return assign; }
Example #17
Source File: AbstractBoomerangTest.java From SPDS with Eclipse Public License 2.0 | 6 votes |
public Optional<? extends Query> test(Stmt stmt) { if (stmt instanceof AssignStmt) { AssignStmt as = (AssignStmt) stmt; if (as.getLeftOp().toString().equals("allocation")) { Statement statement = new Statement(stmt, staticIcfg.getMethodOf(stmt)); if (as.getLeftOp() instanceof Local && as.getRightOp() instanceof IntConstant) { Local local = (Local) as.getLeftOp(); ForwardQuery forwardQuery = new ForwardQuery(statement, new AllocVal(local, staticIcfg.getMethodOf(stmt), as.getRightOp(), new Statement(as, staticIcfg.getMethodOf(stmt)))); return Optional.<Query> of(forwardQuery); } if (as.containsInvokeExpr()) { AtomicReference<Query> returnValue = new AtomicReference<>(); staticIcfg.addCalleeListener( new IntegerAllocationSiteCalleeListener(returnValue, as, statement, stmt)); if (returnValue.get() != null) { return Optional.of(returnValue.get()); } } } } return Optional.empty(); }
Example #18
Source File: DexNullTransformer.java From JAADAS with GNU General Public License v3.0 | 6 votes |
private boolean isObjectArray(Value v, Body body) { for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp() == v) { if (assign.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nea = (NewArrayExpr) assign.getRightOp(); if (isObject(nea.getBaseType())) return true; } else if (assign.getRightOp() instanceof FieldRef) { FieldRef fr = (FieldRef) assign.getRightOp(); if (fr.getType() instanceof ArrayType) if (isObject(((ArrayType) fr.getType()) .getArrayElementType())) return true; } } } } return false; }
Example #19
Source File: AbstractBoomerangTest.java From SPDS with Eclipse Public License 2.0 | 6 votes |
public Optional<? extends Query> test(Stmt unit) { if (unit instanceof AssignStmt) { AssignStmt as = (AssignStmt) unit; if (as.getLeftOp() instanceof Local && as.getRightOp() instanceof NewExpr) { NewExpr expr = ((NewExpr) as.getRightOp()); if (allocatesObjectOfInterest(expr)) { Local local = (Local) as.getLeftOp(); Statement statement = new Statement(unit, staticIcfg.getMethodOf(unit)); ForwardQuery forwardQuery = new ForwardQuery(statement, new AllocVal(local, staticIcfg.getMethodOf(unit), as.getRightOp(), statement)); return Optional.<Query> of(forwardQuery); } } } return Optional.empty(); }
Example #20
Source File: AsmMethodSource.java From JAADAS with GNU General Public License v3.0 | 6 votes |
private void convertArrayStoreInsn(InsnNode insn) { int op = insn.getOpcode(); boolean dword = op == LASTORE || op == DASTORE; StackFrame frame = getFrame(insn); if (!units.containsKey(insn)) { Operand valu = dword ? popImmediateDual() : popImmediate(); Operand indx = popImmediate(); Operand base = popLocal(); ArrayRef ar = Jimple.v().newArrayRef( base.stackOrValue(), indx.stackOrValue()); indx.addBox(ar.getIndexBox()); base.addBox(ar.getBaseBox()); AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue()); valu.addBox(as.getRightOpBox()); frame.in(valu, indx, base); frame.boxes(as.getRightOpBox(), ar.getIndexBox(), ar.getBaseBox()); setUnit(insn, as); } else { frame.mergeIn(dword ? popDual() : pop(), pop(), pop()); } }
Example #21
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
protected FieldReadPOI createArrayFieldLoad(Statement s) { Stmt stmt = s.getUnit().get(); AssignStmt as = (AssignStmt) stmt; ArrayRef ifr = (ArrayRef) as.getRightOp(); Val base = new Val(ifr.getBase(), icfg().getMethodOf(as)); Val stored = new Val(as.getLeftOp(), icfg().getMethodOf(as)); return fieldReads.getOrCreate(new FieldReadPOI(s, base, Field.array(), stored)); }
Example #22
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
public static boolean isArrayStore(Statement s) { Optional<Stmt> optUnit = s.getUnit(); if (optUnit.isPresent()) { Stmt stmt = optUnit.get(); if (stmt instanceof AssignStmt && ((AssignStmt) stmt).getLeftOp() instanceof ArrayRef) { return true; } } return false; }
Example #23
Source File: AbstractBoomerangSolver.java From SPDS with Eclipse Public License 2.0 | 5 votes |
protected boolean isFieldWriteWithBase(Stmt curr, Val base) { if (curr instanceof AssignStmt) { AssignStmt as = (AssignStmt) curr; if (as.getLeftOp() instanceof InstanceFieldRef) { InstanceFieldRef ifr = (InstanceFieldRef) as.getLeftOp(); return ifr.getBase().equals(base.value()); } } return false; }
Example #24
Source File: AbstractBoomerangSolver.java From SPDS with Eclipse Public License 2.0 | 5 votes |
protected Field getWrittenField(Stmt curr) { AssignStmt as = (AssignStmt) curr; if (as.getLeftOp() instanceof StaticFieldRef) { StaticFieldRef staticFieldRef = (StaticFieldRef) as.getLeftOp(); return new Field(staticFieldRef.getField()); } InstanceFieldRef ifr = (InstanceFieldRef) as.getLeftOp(); return new Field(ifr.getField()); }
Example #25
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
public static boolean isArrayLoad(Statement s) { Optional<Stmt> optUnit = s.getUnit(); if (optUnit.isPresent()) { Stmt stmt = optUnit.get(); if (stmt instanceof AssignStmt && ((AssignStmt) stmt).getRightOp() instanceof ArrayRef) { return true; } } return false; }
Example #26
Source File: AbstractBoomerangSolver.java From SPDS with Eclipse Public License 2.0 | 5 votes |
private boolean containsStaticFieldAccess(Stmt succ) { if (succ instanceof AssignStmt) { AssignStmt assignStmt = (AssignStmt) succ; return assignStmt.getLeftOp() instanceof StaticFieldRef || assignStmt.getRightOp() instanceof StaticFieldRef; } return false; }
Example #27
Source File: CopyConstantAnalysis.java From vasco with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Map<Local, Constant> callExitFlowFunction(Context<SootMethod, Unit, Map<Local, Constant>> context, SootMethod calledMethod, Unit unit, Map<Local, Constant> exitValue) { // Initialise result to an empty value Map<Local, Constant> afterCallValue = topValue(); // Only propagate constants for return values if (unit instanceof AssignStmt) { Value lhsOp = ((AssignStmt) unit).getLeftOp(); assign((Local) lhsOp, RETURN_LOCAL, exitValue, afterCallValue); } // Return the map with the returned value's constant return afterCallValue; }
Example #28
Source File: UnitThrowAnalysis.java From JAADAS with GNU General Public License v3.0 | 5 votes |
@Override public void caseAssignStmt(AssignStmt s) { Value lhs = s.getLeftOp(); if (lhs instanceof ArrayRef && (lhs.getType() instanceof UnknownType || lhs.getType() instanceof RefType)) { // This corresponds to an aastore byte code. result = result.add(mgr.ARRAY_STORE_EXCEPTION); } result = result.add(mightThrow(s.getLeftOp())); result = result.add(mightThrow(s.getRightOp())); }
Example #29
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
public static boolean isFieldLoad(Statement s) { Optional<Stmt> optUnit = s.getUnit(); if (optUnit.isPresent()) { Stmt stmt = optUnit.get(); if (stmt instanceof AssignStmt && ((AssignStmt) stmt).getRightOp() instanceof InstanceFieldRef) { return true; } } return false; }
Example #30
Source File: WeightedBoomerang.java From SPDS with Eclipse Public License 2.0 | 5 votes |
protected FieldWritePOI createFieldStore(Statement s) { Stmt stmt = s.getUnit().get(); AssignStmt as = (AssignStmt) stmt; InstanceFieldRef ifr = (InstanceFieldRef) as.getLeftOp(); Val base = new Val(ifr.getBase(), icfg().getMethodOf(as)); Val stored = new Val(as.getRightOp(), icfg().getMethodOf(as)); Field field = new Field(ifr.getField()); return fieldWrites.getOrCreate(new FieldWritePOI(s, base, field, stored)); }