public static SootField mockSootField(String clsName, String fieldName, boolean isStatic) { SootClass sc = mockSootClass(clsName); SootField sf = null; try { sf = sc.getFieldByName(fieldName); } catch (Exception ex) { sf = null; } if (null == sf) { int m = Modifier.PUBLIC; if (isStatic) { m = m | Modifier.STATIC; } sf = new SootField(fieldName, InstrumentationUtils.toSootTypeByName(fieldName), m); sc.addField(sf); } return sf; }
public void fixFields() { Iterator<SootField> iter = m_fieldsToFix.keySet().iterator(); while (iter.hasNext()) { SootField curr = iter.next(); SootClass soot_class = curr.getDeclaringClass(); SootField orig = curr; SootClass field_cls = curr.getDeclaringClass(); if (shouldMap(field_cls)) { SootClass new_field_cls = getMapping(field_cls); curr = new_field_cls.getFieldByName(curr.getName()); } Type type = curr.getType(); if (type instanceof RefType) { RefType ref_type = (RefType) type; if (shouldMap(ref_type.getSootClass())) { SootClass new_class = getMapping(ref_type.getSootClass()); curr.setType(new_class.getType()); } } else if (type instanceof ArrayType) { ArrayType array_type = (ArrayType) type; if (array_type.baseType instanceof RefType == false) { continue; } RefType ref_type = (RefType) array_type.baseType; if (shouldMap(ref_type.getSootClass())) { SootClass new_class = getMapping(ref_type.getSootClass()); ArrayType new_type = ArrayType.v(new_class.getType(), array_type.numDimensions); curr.setType(new_type); } } List<FieldRef> refs = m_fieldsToFix.get(orig); for (FieldRef ref : refs) { ref.setFieldRef(curr.makeRef()); } } }
protected ReferenceVariable staticFieldImpl(String className, String fieldName) { SootClass c = RefType.v(className).getSootClass(); SootField f = c.getFieldByName(fieldName); return pag.makeGlobalVarNode(f, f.getType()); }