public SootClass getDeclaringClass() { if (!isDeclared) { throw new RuntimeException("not declared: " + getName() + " " + getType()); } return declaringClass; }
/** * Does this class declare a field with the given name? */ public boolean declaresFieldByName(String name) { checkLevel(SIGNATURES); if (fields == null) { return false; } for (SootField field : fields) { if (field.getName().equals(name)) { return true; } } return false; }
FieldRWTag(Set<SootField> fields) { StringBuffer sb = new StringBuffer(); boolean first = true; for (SootField field : fields) { if (!first) { sb.append("%"); } first = false; sb.append(field.getDeclaringClass().getName()); sb.append(":"); sb.append(field.getName()); } fieldNames = sb.toString(); }
/** * 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; }
protected void renameField(SootClass sootClass, SootField field) { final String fullyQualifiedName = sootClass.getName() + "." + field.getName(); final String newName = getOrAddNewName(field.getName()); if (isVerbose()) { logger.info("Changing {} to {}", fullyQualifiedName, newName); } field.setName(newName); }
public void inInstanceFieldRef(InstanceFieldRef ifr) { if (ifr instanceof AbstractInstanceFieldRef) { if (inDefinitionStmt && (definedLocal != null)) { SootField field = ((AbstractInstanceFieldRef) ifr).getField(); // System.out.println(definedLocal+" is being assigned field:"+field.getName()); info.setFieldName(definedLocal, field.getName()); } } }
public String getSubSignature() { if (subSig == null) { synchronized (this) { if (subSig == null) { subSig = getSubSignature(getName(), getType()); } } } return subSig; }
public void inStaticFieldRef(StaticFieldRef sfr) { if (inDefinitionStmt && (definedLocal != null)) { SootField field = sfr.getField(); info.setFieldName(definedLocal, field.getName()); } }
/** * Returns the field of this class with the given name. Throws a RuntimeException if there is more than one field with the * given name. Returns null if no field with the given name exists. */ public SootField getFieldByNameUnsafe(String name) { checkLevel(SIGNATURES); if (fields == null) { return null; } SootField foundField = null; for (SootField field : fields.getElementsUnsorted()) { if (field.getName().equals(name)) { if (foundField == null) { foundField = field; } else { throw new RuntimeException("ambiguous field: " + name); } } } return foundField; }
/** * 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; }
/** * Adds the given field to this class. */ public void addField(SootField f) { checkLevel(SIGNATURES); if (f.isDeclared()) { throw new RuntimeException("already declared: " + f.getName()); } if (declaresField(f.getName(), f.getType())) { throw new RuntimeException("Field already exists : " + f.getName() + " of type " + f.getType()); } if (fields == null) { fields = new HashChain<>(); } fields.add(f); f.setDeclared(true); f.setDeclaringClass(this); }
public static void retrieveAllNames() { if (namesHaveBeenRetrieved) { return; } // iterate through application classes, rename fields with junk for (SootClass c : soot.Scene.v().getApplicationClasses()) { nameList.add(c.getName()); for (SootMethod m : c.getMethods()) { nameList.add(m.getName()); } for (SootField m : c.getFields()) { nameList.add(m.getName()); } } namesHaveBeenRetrieved = true; }
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; }
public boolean equals(CPVariable var) { // check they have the same type Local or SootField if (this.containsLocal() && var.containsLocal()) { // both locals and same name if (this.getLocal().getName().equals(var.getLocal().getName())) { return true; } } if (this.containsSootField() && var.containsSootField()) { // both SootFields check they have same name if (this.getSootField().getName().equals(var.getSootField().getName())) { return true; } } return false; }
/** * Removes the given field from this class. */ public void removeField(SootField f) { checkLevel(SIGNATURES); if (!f.isDeclared() || f.getDeclaringClass() != this) { throw new RuntimeException("did not declare: " + f.getName()); } if (fields != null) { fields.remove(f); } f.setDeclared(false); f.setDeclaringClass(null); }
public String toString() { if (containsLocal()) { return "Local: " + getLocal().getName(); } else if (containsSootField()) { return "SootField: " + getSootField().getName(); } else { return "UNKNOWN CONSTANT_PROPAGATION_VARIABLE"; } } }
protected static FieldReference toFieldReference(SootField f) { FieldReference fieldRef = new ImmutableFieldReference(SootToDexUtils.getDexClassName(f.getDeclaringClass().getName()), f.getName(), SootToDexUtils.getDexTypeDescriptor(f.getType())); return fieldRef; }
/** * @param node * @return */ public static String makeLabel(FieldRefNode node) { if (node.getField() instanceof SootField) { final SootField sf = (SootField) node.getField(); return "FNR " + makeLabel(node.getBase()) + "." + sf.getName(); } else { return "FNR " + makeLabel(node.getBase()) + "." + node.getField(); } }
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(); }
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"); }