Search in sources :

Example 1 with IClassData

use of jadx.api.plugins.input.data.IClassData 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);
    }
}
Also used : AnnotationsAttr(jadx.api.plugins.input.data.attributes.types.AnnotationsAttr) IAnnotation(jadx.api.plugins.input.data.annotations.IAnnotation) ClassNode(jadx.core.dex.nodes.ClassNode) AttributeStorage(jadx.core.dex.attributes.AttributeStorage) ArrayList(java.util.ArrayList) IClassData(jadx.api.plugins.input.data.IClassData)

Aggregations

IClassData (jadx.api.plugins.input.data.IClassData)1 IAnnotation (jadx.api.plugins.input.data.annotations.IAnnotation)1 AnnotationsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationsAttr)1 AttributeStorage (jadx.core.dex.attributes.AttributeStorage)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 ArrayList (java.util.ArrayList)1