public void checkAndSwitch(ValueBox valBox) { Value val = valBox.getValue(); Object finalField = check(val); if (finalField != null) { // System.out.println("Final field with this value exists"+finalField); /* * If the final field belongs to the same class then we should supress declaring class */ SootField field = (SootField) finalField; if (sootClass.declaresField(field.getName(), field.getType())) { // this field is of this class so supress the declaring class if (valBox.canContainValue(new DStaticFieldRef(field.makeRef(), true))) { valBox.setValue(new DStaticFieldRef(field.makeRef(), true)); } } else { if (valBox.canContainValue(new DStaticFieldRef(field.makeRef(), true))) { valBox.setValue(new DStaticFieldRef(field.makeRef(), false)); } } } // else // System.out.println("Final field not found"); }
private void handleFinalLocalInits() { ArrayList<SootField> finalsList = ((PolyglotMethodSource) body.getMethod().getSource()).getFinalsList(); if (finalsList == null) { return; } int paramCount = paramRefCount - finalsList.size(); Iterator<SootField> it = finalsList.iterator(); while (it.hasNext()) { soot.SootField sf = it.next(); soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(specialThisLocal, sf.makeRef()); soot.jimple.AssignStmt stmt = soot.jimple.Jimple.v().newAssignStmt(fieldRef, body.getParameterLocal(paramCount)); body.getUnits().add(stmt); paramCount++; } }
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (b.getMethod().getName().indexOf("<clinit>") >= 0) { return; } int weight = soot.jbco.Main.getWeight(phaseName, b.getMethod().getSignature()); if (weight == 0) { return; } PatchingChain<Unit> units = b.getUnits(); Iterator<Unit> iter = units.snapshotIterator(); while (iter.hasNext()) { Unit u = (Unit) iter.next(); if (u instanceof PushInst) { SootField f = CollectConstants.constantsToFields.get(((PushInst) u).getConstant()); if (f != null && Rand.getInt(10) <= weight) { Unit get = Baf.v().newStaticGetInst(f.makeRef()); units.insertBefore(get, u); BodyBuilder.updateTraps(get, u, b.getTraps()); units.remove(u); updated++; } } } } }
/** * adds this field for the outer class */ private void handleOuterClassThisInit(soot.SootMethod sootMethod) { // static inner classes are different SootField this0Field = body.getMethod().getDeclaringClass().getFieldByNameUnsafe("this$0"); if (this0Field != null) { soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(specialThisLocal, this0Field.makeRef()); soot.jimple.AssignStmt stmt = soot.jimple.Jimple.v().newAssignStmt(fieldRef, outerClassParamLocal); body.getUnits().add(stmt); } }
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if (sf.isStatic()) { return new CachedEquivalentValue(Jimple.v().newStaticFieldRef(sf.makeRef())); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if (sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } } }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { // Some apps reference static fields as instance fields. We need to fix // this for not breaking the client analysis. for (Iterator<Unit> unitIt = b.getUnits().iterator(); unitIt.hasNext();) { Stmt s = (Stmt) unitIt.next(); if (s.containsFieldRef() && s instanceof AssignStmt) { FieldRef ref = s.getFieldRef(); // Make sure that the target class has already been loaded if (isTypeLoaded(ref.getFieldRef().type())) { try { if (ref instanceof InstanceFieldRef) { SootField fld = ref.getField(); if (fld != null && fld.isStatic()) { AssignStmt assignStmt = (AssignStmt) s; if (assignStmt.getLeftOp() == ref) { assignStmt.setLeftOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } else if (assignStmt.getRightOp() == ref) { assignStmt.setRightOp(Jimple.v().newStaticFieldRef(ref.getField().makeRef())); } } } } catch (ConflictingFieldRefException ex) { // That field is broken, just don't touch it } } } } }
InstanceFieldRef newLock = Jimple.v().newInstanceFieldRef(baseLocal, lock.getField().makeRef()); logger.debug(" as " + newLock); return newLock;
private void loadBooleanValue(PatchingChain<Unit> units, SootField f, Unit insert) { units.insertBefore(Baf.v().newStaticGetInst(f.makeRef()), insert); if (f.getType() instanceof RefType) { SootMethod boolInit = ((RefType) f.getType()).getSootClass().getMethod("boolean booleanValue()"); units.insertBefore(Baf.v().newVirtualInvokeInst(boolInit.makeRef()), insert); } }
us.add(Jimple.v().newAssignStmt(l, Jimple.v().newInstanceFieldRef(this_, f.makeRef()))); args.add(l);
if (field instanceof SootField) { SootFieldRef tempFieldRef = ((SootField) field).makeRef();
soot.Local t1 = lg.generateLocal(outerThisField.getType()); soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(specialThisLocal, outerThisField.makeRef()); soot.jimple.AssignStmt fieldAssignStmt = soot.jimple.Jimple.v().newAssignStmt(t1, fieldRef); body.getUnits().add(fieldAssignStmt);
body.getLocals().add(tmpRef); list.add(Jimple.v().newAssignStmt(tmpRef, Jimple.v().newStaticFieldRef(Scene.v().getField("<java.lang.System: java.io.PrintStream out>").makeRef())));
for (SootField f : capFields) { Local l2 = localItr.next(); us.add(Jimple.v().newAssignStmt(Jimple.v().newInstanceFieldRef(l, f.makeRef()), l2));
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), constant)); if (newInit) { units.addLast(Jimple.v().newReturnVoidStmt());
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), IntConstant.v(value ? 1 : 0))); } else { Local bool = Jimple.v().newLocal("boolLcl", booleanWrapperRefType); units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), bool)); units.addFirst(Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(bool, booleanWrapperConstructor.makeRef(), IntConstant.v(value ? 1 : 0))));
lockClass.addField(actualLockObject); StaticFieldRef actualLockSfr = Jimple.v().newStaticFieldRef(actualLockObject.makeRef()); Stmt assignStmt = Jimple.v().newAssignStmt(actualLockSfr, lockLocal); if (addingNewClinit) {
b.newInstanceFieldRef( base, enclosing.getSootField("this$0", enclosing.enclosingType()).makeRef(), this ),
b.add(Jimple.v().newAssignStmt( Jimple.v().newInstanceFieldRef(b.emitThis(hostType()), hostType().getSootField("this$0", type).makeRef()), asLocal(b, Jimple.v().newParameterRef(type.getSootType(), 0))));