Search in sources :

Example 11 with BaksmaliWriter

use of org.jf.baksmali.formatter.BaksmaliWriter in project smali by JesusFreke.

the class ClassDefinition method writeInstanceFields.

private void writeInstanceFields(BaksmaliWriter writer, Set<String> staticFields) throws IOException {
    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');
        BaksmaliWriter fieldWriter = writer;
        String fieldString = formatter.getShortFieldDescriptor(field);
        if (!writtenFields.add(fieldString)) {
            writer.write("# duplicate field ignored\n");
            fieldWriter = getCommentingWriter(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(fieldWriter, field, false);
    }
}
Also used : BaksmaliWriter(org.jf.baksmali.formatter.BaksmaliWriter) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef) HashSet(java.util.HashSet)

Aggregations

BaksmaliWriter (org.jf.baksmali.formatter.BaksmaliWriter)11 ClassDefinition (org.jf.baksmali.Adaptors.ClassDefinition)5 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)5 StringWriter (java.io.StringWriter)4 HashSet (java.util.HashSet)4 IOException (java.io.IOException)2 DebugMethodItem (org.jf.baksmali.Adaptors.Debug.DebugMethodItem)2 AnalyzedInstruction (org.jf.dexlib2.analysis.AnalyzedInstruction)2 DexFile (org.jf.dexlib2.iface.DexFile)2 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 InstructionMethodItem (org.jf.baksmali.Adaptors.Format.InstructionMethodItem)1 MethodDefinition (org.jf.baksmali.Adaptors.MethodDefinition)1 RegisterFormatter (org.jf.baksmali.Adaptors.RegisterFormatter)1 BaksmaliOptions (org.jf.baksmali.BaksmaliOptions)1 AnalysisException (org.jf.dexlib2.analysis.AnalysisException)1 ClassPath (org.jf.dexlib2.analysis.ClassPath)1 MethodAnalyzer (org.jf.dexlib2.analysis.MethodAnalyzer)1 BaseStringReference (org.jf.dexlib2.base.reference.BaseStringReference)1