use of jadx.api.plugins.input.data.attributes.types.AnnotationsAttr in project jadx by skylot.
the class AnnotationGen method add.
private void add(IAttributeNode node, ICodeWriter code) {
AnnotationsAttr aList = node.get(JadxAttrType.ANNOTATION_LIST);
if (aList == null || aList.isEmpty()) {
return;
}
for (IAnnotation a : aList.getAll()) {
String aCls = a.getAnnotationClass();
if (!aCls.equals(Consts.OVERRIDE_ANNOTATION)) {
code.startLine();
formatAnnotation(code, a);
}
}
}
use of jadx.api.plugins.input.data.attributes.types.AnnotationsAttr in project jadx by skylot.
the class AnnotationGen method addForParameter.
public void addForParameter(ICodeWriter code, AnnotationMethodParamsAttr paramsAnnotations, int n) {
List<AnnotationsAttr> paramList = paramsAnnotations.getParamList();
if (n >= paramList.size()) {
return;
}
AnnotationsAttr aList = paramList.get(n);
if (aList == null || aList.isEmpty()) {
return;
}
for (IAnnotation a : aList.getAll()) {
formatAnnotation(code, a);
code.add(' ');
}
}
use of jadx.api.plugins.input.data.attributes.types.AnnotationsAttr 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.api.plugins.input.data.attributes.types.AnnotationsAttr in project jadx by skylot.
the class Smali method writeFields.
private void writeFields(SmaliWriter smali, IClassData classData, List<RawField> fields, int[] colWidths) {
int staticIdx = 0;
smali.startLine().startLine("# fields");
String whites = new String(new byte[Math.max(colWidths[0], colWidths[1])]).replace("\0", " ");
for (RawField fld : fields) {
smali.startLine();
int pad = colWidths[0] - fld.accessFlag.length();
if (pad > 0) {
fld.accessFlag += whites.substring(0, pad);
}
smali.add(".field ").add(fld.accessFlag);
pad = colWidths[1] - fld.name.length();
if (pad > 0) {
fld.name += whites.substring(0, pad);
}
smali.add(fld.name).add(" ");
smali.add(": ").add(fld.type);
if (fld.isStatic) {
EncodedValue constVal = fld.attributes.get(JadxAttrType.CONSTANT_VALUE);
if (constVal != null) {
smali.add(" # init val = ");
writeEncodedValue(smali, constVal, false);
}
}
AnnotationsAttr annotationsAttr = fld.attributes.get(JadxAttrType.ANNOTATION_LIST);
if (annotationsAttr != null) {
smali.incIndent();
writeAnnotations(smali, annotationsAttr.getList());
smali.decIndent();
}
}
smali.startLine();
}
use of jadx.api.plugins.input.data.attributes.types.AnnotationsAttr 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