public CPVariable(SootField field) { this.field = field; this.local = null; if (!(field.getType() instanceof PrimType)) { throw new DavaFlowAnalysisException("Variables managed for CP should only be primitives"); } }
public SootClass getDeclaringClass() { if (!isDeclared) { throw new RuntimeException("not declared: " + getName() + " " + getType()); } return declaringClass; }
public void caseStaticPutInst(StaticPutInst i) { remove_types = new Type[] { i.getField().getType() }; add_types = null; }
public void caseStaticGetInst(StaticGetInst i) { remove_types = null; add_types = new Type[] { i.getField().getType() }; }
/** * Determine if the field accepts a string default value, this is only true for fields of type String or a sub-type of * String * * @param field * Field * @return <code>true</code> if the field is of type String or sub-type, <code>false</code> otherwise. */ public static boolean acceptsStringInitialValue(SootField field) { if (field.getType() instanceof RefType) { SootClass fieldClass = ((RefType) field.getType()).getSootClass(); return fieldClass.getName().equals("java.lang.String"); } return false; }
/** * Does this class declare a field with the given name and type. */ public boolean declaresField(String name, Type type) { checkLevel(SIGNATURES); if (fields == null) { return false; } for (SootField field : fields) { if (field.getName().equals(name) && field.getType().equals(type)) { return true; } } return false; }
public String getSubSignature() { if (subSig == null) { synchronized (this) { if (subSig == null) { subSig = getSubSignature(getName(), getType()); } } } return subSig; }
/** Returns the set of objects pointed to by static field f. */ public PointsToSet reachingObjects(SootField f) { Type t = f.getType(); if (t instanceof RefType) { return FullObjectSet.v((RefType) t); } return FullObjectSet.v(); }
public static boolean hasRecursiveField(SootClass sootClass) { Chain fields = sootClass.getFields(); for (Iterator iter = fields.iterator(); iter.hasNext();) { SootField sootField = (SootField) iter.next(); Type type = sootField.getType(); if (type instanceof RefType) { RefType refType = (RefType) type; SootClass sootClass2 = refType.getSootClass(); if (sootClass == sootClass2) { return true; } } } return false; }
/** * Returns the field of this class with the given name and type. If the field cannot be found, null is returned. */ public SootField getFieldUnsafe(String name, Type type) { checkLevel(SIGNATURES); if (fields == null) { return null; } for (SootField field : fields.getElementsUnsorted()) { if (field.getName().equals(name) && field.getType().equals(type)) { return field; } } return null; }
protected ReferenceVariable staticFieldImpl(String className, String fieldName) { SootClass c = RefType.v(className).getSootClass(); SootField f = c.getFieldByName(fieldName); return pag.makeGlobalVarNode(f, f.getType()); }
@Override final public void caseStaticFieldRef(StaticFieldRef sfr) { setResult(pag.makeGlobalVarNode(sfr.getField(), sfr.getField().getType())); }
public void caseFieldGetInst(FieldGetInst i) { remove_types = new Type[] { i.getField().getDeclaringClass().getType() }; add_types = new Type[] { i.getField().getType() }; }
public void caseFieldPutInst(FieldPutInst i) { remove_types = new Type[] { i.getField().getDeclaringClass().getType(), i.getField().getType() }; add_types = null; }
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); } }
private static soot.SootMethod makeOuterThisAccessMethod(soot.SootClass classToInvoke) { String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); paramTypes.add(classToInvoke.getType()); soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, classToInvoke.getFieldByName("this$0").getType(), soot.Modifier.STATIC); classToInvoke.addMethod(meth); PrivateFieldAccMethodSource src = new PrivateFieldAccMethodSource(classToInvoke.getFieldByName("this$0").getType(), "this$0", classToInvoke.getFieldByName("this$0").isStatic(), classToInvoke); meth.setActiveBody(src.getBody(meth, null)); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
protected static FieldReference toFieldReference(SootField f) { FieldReference fieldRef = new ImmutableFieldReference(SootToDexUtils.getDexClassName(f.getDeclaringClass().getName()), f.getName(), SootToDexUtils.getDexTypeDescriptor(f.getType())); return fieldRef; }
public synchronized SootField getOrAddField(SootField f) { checkLevel(SIGNATURES); if (f.isDeclared()) { throw new RuntimeException("already declared: " + f.getName()); } SootField old = getFieldUnsafe(f.getName(), f.getType()); if (old != null) { return old; } if (fields == null) { fields = new HashChain<>(); } fields.add(f); f.setDeclared(true); f.setDeclaringClass(this); return f; }
private void printFieldRef(FieldRef v) { String refTypeName = v.getClass().getSimpleName(); p.openBlock(); String oldName = varName; SootField f = v.getField(); ttp.setVariableName("type"); f.getType().apply(ttp); p.print("SootFieldRef fieldRef = "); p.printNoIndent("Scene.v().makeFieldRef("); String className = f.getDeclaringClass().getName(); p.printNoIndent("Scene.v().getSootClass(\"" + className + "\"),"); p.printNoIndent("\"" + f.getName() + "\","); p.printNoIndent("type,"); p.printNoIndent(f.isStatic() + ");"); p.println("Value " + oldName + " = Jimple.v().new" + refTypeName + "(fieldRef);"); varName = oldName; p.closeBlock(); }
@Override final public void caseInstanceFieldRef(InstanceFieldRef ifr) { if (pag.getOpts().field_based() || pag.getOpts().vta()) { setResult(pag.makeGlobalVarNode(ifr.getField(), ifr.getField().getType())); } else { setResult(pag.makeLocalFieldRefNode(ifr.getBase(), ifr.getBase().getType(), ifr.getField(), method)); } }