Java Code Examples for org.jf.dexlib2.util.ReferenceUtil#getShortFieldDescriptor()

The following examples show how to use org.jf.dexlib2.util.ReferenceUtil#getShortFieldDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassDefinition.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    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(fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
 
Example 2
Source File: ClassDefinition.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void writeInstanceFields(IndentingWriter 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');

        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(fieldWriter, field, false);
    }
}
 
Example 3
Source File: ClassDefinition.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    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(fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
 
Example 4
Source File: ClassDefinition.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
private void writeInstanceFields(IndentingWriter 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');

        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(fieldWriter, field, false);
    }
}
 
Example 5
Source File: ClassDefinition.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    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(fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
 
Example 6
Source File: ClassDefinition.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
private void writeInstanceFields(IndentingWriter 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');

        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(fieldWriter, field, false);
    }
}
 
Example 7
Source File: ClassDefinition.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    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(fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
 
Example 8
Source File: ClassDefinition.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void writeInstanceFields(IndentingWriter 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');

        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(fieldWriter, field, false);
    }
}
 
Example 9
Source File: ClassPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);

    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }

    typePool.intern(poolClassDef.getType());
    typePool.internNullable(poolClassDef.getSuperclass());
    typeListPool.intern(poolClassDef.getInterfaces());
    stringPool.internNullable(poolClassDef.getSourceFile());

    HashSet<String> fields = new HashSet<String>();
    for (Field field: poolClassDef.getFields()) {
        String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s",
                    poolClassDef.getType(), fieldDescriptor);
        }
        fieldPool.intern(field);

        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            DexPool.internEncodedValue(initialValue, stringPool, typePool, fieldPool, methodPool);
        }

        annotationSetPool.intern(field.getAnnotations());
    }

    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method: poolClassDef.getMethods()) {
        String methodDescriptor = ReferenceUtil.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s",
                    poolClassDef.getType(), methodDescriptor);
        }
        methodPool.intern(method);
        internCode(method);
        internDebug(method);
        annotationSetPool.intern(method.getAnnotations());

        for (MethodParameter parameter: method.getParameters()) {
            annotationSetPool.intern(parameter.getAnnotations());
        }
    }

    annotationSetPool.intern(poolClassDef.getAnnotations());
}
 
Example 10
Source File: ClassPool.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);

    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }

    typePool.intern(poolClassDef.getType());
    typePool.internNullable(poolClassDef.getSuperclass());
    typeListPool.intern(poolClassDef.getInterfaces());
    stringPool.internNullable(poolClassDef.getSourceFile());

    HashSet<String> fields = new HashSet<String>();
    for (Field field: poolClassDef.getFields()) {
        String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s",
                    poolClassDef.getType(), fieldDescriptor);
        }
        fieldPool.intern(field);

        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            DexPool.internEncodedValue(initialValue, stringPool, typePool, fieldPool, methodPool);
        }

        annotationSetPool.intern(field.getAnnotations());
    }

    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method: poolClassDef.getMethods()) {
        String methodDescriptor = ReferenceUtil.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s",
                    poolClassDef.getType(), methodDescriptor);
        }
        methodPool.intern(method);
        internCode(method);
        internDebug(method);
        annotationSetPool.intern(method.getAnnotations());

        for (MethodParameter parameter: method.getParameters()) {
            annotationSetPool.intern(parameter.getAnnotations());
        }
    }

    annotationSetPool.intern(poolClassDef.getAnnotations());
}
 
Example 11
Source File: ClassPool.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);

    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }

    typePool.intern(poolClassDef.getType());
    typePool.internNullable(poolClassDef.getSuperclass());
    typeListPool.intern(poolClassDef.getInterfaces());
    stringPool.internNullable(poolClassDef.getSourceFile());

    HashSet<String> fields = new HashSet<String>();
    for (Field field: poolClassDef.getFields()) {
        String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s",
                    poolClassDef.getType(), fieldDescriptor);
        }
        fieldPool.intern(field);

        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            DexPool.internEncodedValue(initialValue, stringPool, typePool, fieldPool, methodPool);
        }

        annotationSetPool.intern(field.getAnnotations());
    }

    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method: poolClassDef.getMethods()) {
        String methodDescriptor = ReferenceUtil.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s",
                    poolClassDef.getType(), methodDescriptor);
        }
        methodPool.intern(method);
        internCode(method);
        internDebug(method);
        annotationSetPool.intern(method.getAnnotations());

        for (MethodParameter parameter: method.getParameters()) {
            annotationSetPool.intern(parameter.getAnnotations());
        }
    }

    annotationSetPool.intern(poolClassDef.getAnnotations());
}
 
Example 12
Source File: ClassPool.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
public void intern(@Nonnull ClassDef classDef) {
    PoolClassDef poolClassDef = new PoolClassDef(classDef);

    PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
    if (prev != null) {
        throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
    }

    typePool.intern(poolClassDef.getType());
    typePool.internNullable(poolClassDef.getSuperclass());
    typeListPool.intern(poolClassDef.getInterfaces());
    stringPool.internNullable(poolClassDef.getSourceFile());

    HashSet<String> fields = new HashSet<String>();
    for (Field field: poolClassDef.getFields()) {
        String fieldDescriptor = ReferenceUtil.getShortFieldDescriptor(field);
        if (!fields.add(fieldDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for field %s->%s",
                    poolClassDef.getType(), fieldDescriptor);
        }
        fieldPool.intern(field);

        EncodedValue initialValue = field.getInitialValue();
        if (initialValue != null) {
            DexPool.internEncodedValue(initialValue, stringPool, typePool, fieldPool, methodPool);
        }

        annotationSetPool.intern(field.getAnnotations());
    }

    HashSet<String> methods = new HashSet<String>();
    for (PoolMethod method: poolClassDef.getMethods()) {
        String methodDescriptor = ReferenceUtil.getShortMethodDescriptor(method);
        if (!methods.add(methodDescriptor)) {
            throw new ExceptionWithContext("Multiple definitions for method %s->%s",
                    poolClassDef.getType(), methodDescriptor);
        }
        methodPool.intern(method);
        internCode(method);
        internDebug(method);
        annotationSetPool.intern(method.getAnnotations());

        for (MethodParameter parameter: method.getParameters()) {
            annotationSetPool.intern(parameter.getAnnotations());
        }
    }

    annotationSetPool.intern(poolClassDef.getAnnotations());
}