use of jadx.core.dex.attributes.AttributeStorage in project jadx by skylot.
the class Smali method writeMethodDef.
private void writeMethodDef(SmaliWriter smali, IMethodData mth, LineInfo lineInfo) {
smali.add(AccessFlags.format(mth.getAccessFlags(), METHOD));
IMethodRef methodRef = mth.getMethodRef();
methodRef.load();
lineInfo.smaliMthNode.setDefPos(smali.getLength());
smali.add(methodRef.getName()).add('(');
methodRef.getArgTypes().forEach(smali::add);
smali.add(')');
smali.add(methodRef.getReturnType());
AnnotationsAttr annotationsAttr = new AttributeStorage(mth.getAttributes()).get(JadxAttrType.ANNOTATION_LIST);
if (annotationsAttr != null && !annotationsAttr.isEmpty()) {
smali.incIndent();
writeAnnotations(smali, annotationsAttr.getList());
smali.decIndent();
smali.startLine();
}
}
use of jadx.core.dex.attributes.AttributeStorage in project jadx by skylot.
the class Smali method writeClass.
private void writeClass(SmaliWriter smali, ClassNode cls) {
IClassData clsData = cls.getClsData();
if (clsData == null) {
smali.startLine(String.format("###### Class %s is created by jadx", cls.getFullName()));
return;
}
AttributeStorage attributes = new AttributeStorage();
attributes.add(clsData.getAttributes());
smali.startLine("Class: " + clsData.getType()).startLine("AccessFlags: " + AccessFlags.format(clsData.getAccessFlags(), AccessFlagsScope.CLASS)).startLine("SuperType: " + clsData.getSuperType()).startLine("Interfaces: " + clsData.getInterfacesTypes()).startLine("SourceFile: " + attributes.get(JadxAttrType.SOURCE_FILE));
AnnotationsAttr annotationsAttr = attributes.get(JadxAttrType.ANNOTATION_LIST);
if (annotationsAttr != null) {
Collection<IAnnotation> annos = annotationsAttr.getList();
if (!annos.isEmpty()) {
smali.startLine(String.format("# %d annotations", annos.size()));
writeAnnotations(smali, new ArrayList<>(annos));
smali.startLine();
}
}
List<RawField> fields = new ArrayList<>();
// first is access flag, second is name
int[] colWidths = new int[] { 0, 0 };
int[] mthIndex = new int[] { 0 };
LineInfo line = new LineInfo();
clsData.visitFieldsAndMethods(f -> {
RawField fld = RawField.make(f);
fields.add(fld);
if (fld.accessFlag.length() > colWidths[0]) {
colWidths[0] = fld.accessFlag.length();
}
if (fld.name.length() > colWidths[1]) {
colWidths[1] = fld.name.length();
}
}, m -> {
if (!fields.isEmpty()) {
writeFields(smali, clsData, fields, colWidths);
fields.clear();
}
writeMethod(smali, cls.getMethods().get(mthIndex[0]++), m, line);
line.reset();
});
if (!fields.isEmpty()) {
// in case there's no methods.
writeFields(smali, clsData, fields, colWidths);
}
for (ClassNode innerClass : cls.getInnerClasses()) {
writeClass(smali, innerClass);
}
}
Aggregations