use of org.jf.dexlib2.iface.Field in project atlas by alibaba.
the class ClassDefinition method writeInstanceFields.
private void writeInstanceFields(IndentingWriter writer, Set<String> staticFields) throws IOException {
if (!fullMethod && !DexDiffInfo.addedClasses.contains(classDef)) {
return;
}
boolean wroteHeader = false;
Set<String> writtenFields = new HashSet<String>();
Iterable<? extends Field> instanceFields;
if (classDef instanceof DexBackedClassDef) {
instanceFields = ((DexBackedClassDef) classDef).getInstanceFields(false);
} else {
instanceFields = classDef.getInstanceFields();
}
for (Field field : instanceFields) {
if (!wroteHeader) {
writer.write("\n\n");
writer.write("# instance fields");
wroteHeader = true;
}
writer.write('\n');
IndentingWriter fieldWriter = writer;
String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
if (!writtenFields.add(fieldString)) {
writer.write("# duplicate field ignored\n");
fieldWriter = new CommentingIndentingWriter(writer);
System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
} else if (staticFields.contains(fieldString)) {
System.err.println(String.format("Duplicate static+instance field found: %s->%s", classDef.getType(), fieldString));
System.err.println("You will need to rename one of these fields, including all references.");
writer.write("# There is both a static and instance field with this signature.\n" + "# You will need to rename one of these fields, including all references.\n");
}
FieldDefinition.writeTo(options, fieldWriter, field, false);
}
}
use of org.jf.dexlib2.iface.Field in project atlas by alibaba.
the class ClassDefinition method writeStaticFields.
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
if (!fullMethod && !DexDiffInfo.addedClasses.contains(classDef)) {
return null;
}
boolean wroteHeader = false;
Set<String> writtenFields = new HashSet<String>();
Iterable<? extends Field> staticFields;
if (classDef instanceof DexBackedClassDef) {
staticFields = ((DexBackedClassDef) classDef).getStaticFields(false);
} else {
staticFields = classDef.getStaticFields();
}
for (Field field : staticFields) {
if (!wroteHeader) {
writer.write("\n\n");
writer.write("# static fields");
wroteHeader = true;
}
writer.write('\n');
boolean setInStaticConstructor;
IndentingWriter fieldWriter = writer;
String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
if (!writtenFields.add(fieldString)) {
writer.write("# duplicate field ignored\n");
fieldWriter = new CommentingIndentingWriter(writer);
System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
setInStaticConstructor = false;
} else {
setInStaticConstructor = fieldsSetInStaticConstructor.contains(fieldString);
}
FieldDefinition.writeTo(options, fieldWriter, field, setInStaticConstructor);
}
return writtenFields;
}
use of org.jf.dexlib2.iface.Field in project atlas by alibaba.
the class FieldDefinition method writeTo.
public static void writeTo(baksmaliOptions options, IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
EncodedValue initialValue = field.getInitialValue();
int accessFlags = field.getAccessFlags();
if (setInStaticConstructor && AccessFlags.STATIC.isSet(accessFlags) && AccessFlags.FINAL.isSet(accessFlags) && initialValue != null) {
if (!EncodedValueUtils.isDefaultValue(initialValue)) {
writer.write("# The value of this static final field might be set in the static constructor\n");
} else {
// don't write out the default initial value for static final fields that get set in the static
// constructor
initialValue = null;
}
}
writer.write(".field ");
writeAccessFlags(writer, field.getAccessFlags());
writer.write(field.getName());
writer.write(':');
String clazz = TypeGenUtil.newType(field.getType());
writer.write(clazz);
if (initialValue != null) {
writer.write(" = ");
String containingClass = null;
if (options.useImplicitReferences) {
containingClass = field.getDefiningClass();
}
EncodedValueAdaptor.writeTo(writer, initialValue, containingClass);
}
writer.write('\n');
Collection<? extends Annotation> annotations = field.getAnnotations();
if (annotations.size() > 0) {
writer.indent(4);
String containingClass = null;
if (options.useImplicitReferences) {
containingClass = field.getDefiningClass();
}
AnnotationFormatter.writeTo(writer, annotations, containingClass);
writer.deindent(4);
writer.write(".end field\n");
}
}
use of org.jf.dexlib2.iface.Field in project atlas by alibaba.
the class AbIClassDef method reClassDef.
@Override
public ClassDef reClassDef(ClassDef classDef) {
Iterable<? extends Method> methods = classDef.getMethods();
LinkedHashSet<Method> newMethods = new LinkedHashSet<Method>();
Iterable<? extends Field> fields = classDef.getFields();
LinkedHashSet<Field> newFields = new LinkedHashSet<Field>();
Set<? extends Annotation> annotations = classDef.getAnnotations();
Set<String> interfaces = classDef.getInterfaces();
Set<String> newInterfaces = new HashSet<String>();
Set<Annotation> immutableAnnotations = new HashSet<Annotation>();
String type = classDef.getType();
reType = reType(type);
String superClass = classDef.getSuperclass();
for (String inter : interfaces) {
newInterfaces.add(reInterface(inter));
}
String reSuperClass = reSuperClass(superClass);
for (Annotation annotation : annotations) {
if (type.startsWith("Landroid/taobao/atlas/bundleInfo/AtlasBundleInfoManager;")) {
System.out.println("xxxx");
}
immutableAnnotations.add(reAnnotation(annotation));
}
for (Field field : fields) {
newFields.add(reField(field));
}
for (Method method : methods) {
if (method.getName().equals("<cinit>") || method.getName().equals("<init>")) {
newMethods.add(reMethod(method));
continue;
}
// if (method.getName().equals("getArchiveFile")) {
newMethods.add(reMethod(method));
// }
}
return new ImmutableClassDef(reType, classDef.getAccessFlags(), reSuperClass, newInterfaces, classDef.getSourceFile(), immutableAnnotations, newFields, newMethods);
}
use of org.jf.dexlib2.iface.Field in project android-classyshark by google.
the class MetaObjectDex method getDeclaredFields.
@Override
public FieldInfo[] getDeclaredFields() {
List<FieldInfo> result = new ArrayList<>();
Iterable<? extends Field> implFields = classDef.getFields();
for (Field field : implFields) {
FieldInfo fi = new FieldInfo();
fi.typeName = DexlibAdapter.getTypeName(field.getType());
fi.modifiers = field.getAccessFlags();
fi.annotations = convertAnnotations(field.getAnnotations());
fi.name = field.getName();
result.add(fi);
}
FieldInfo[] array = new FieldInfo[result.size()];
return result.toArray(array);
}
Aggregations