com.android.dx.rop.cst.CstArray Java Examples

The following examples show how to use com.android.dx.rop.cst.CstArray. 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: ValueEncoder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} and not including a
 * {@code value_type} prefix. If the output stream keeps
 * (debugging) annotations and {@code topLevel} is
 * {@code true}, then this method will write (debugging)
 * annotations.
 *
 * @param array {@code non-null;} array instance to write
 * @param topLevel {@code true} iff the given annotation is the
 * top-level annotation or {@code false} if it is a sub-annotation
 * of some other annotation
 */
public void writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();

    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }

    out.writeUleb128(size);

    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " +
                    constantToHuman(cst));
        }
        writeConstant(cst);
    }

    if (annotates) {
        out.endAnnotation();
    }
}
 
Example #2
Source File: ValueEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} and not including a
 * {@code value_type} prefix. If the output stream keeps
 * (debugging) annotations and {@code topLevel} is
 * {@code true}, then this method will write (debugging)
 * annotations.
 *
 * @param array {@code non-null;} array instance to write
 * @param topLevel {@code true} iff the given annotation is the
 * top-level annotation or {@code false} if it is a sub-annotation
 * of some other annotation
 */
public void writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();

    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }

    out.writeUleb128(size);

    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " +
                    constantToHuman(cst));
        }
        writeConstant(cst);
    }

    if (annotates) {
        out.endAnnotation();
    }
}
 
Example #3
Source File: ValueEncoder.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} and not including a
 * {@code value_type} prefix. If the output stream keeps
 * (debugging) annotations and {@code topLevel} is
 * {@code true}, then this method will write (debugging)
 * annotations.
 *
 * @param array {@code non-null;} array instance to write
 * @param topLevel {@code true} iff the given annotation is the
 * top-level annotation or {@code false} if it is a sub-annotation
 * of some other annotation
 */
public void writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();

    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }

    out.writeUleb128(size);

    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " +
                    constantToHuman(cst));
        }
        writeConstant(cst);
    }

    if (annotates) {
        out.endAnnotation();
    }
}
 
Example #4
Source File: ValueEncoder.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} and not including a
 * {@code value_type} prefix. If the output stream keeps
 * (debugging) annotations and {@code topLevel} is
 * {@code true}, then this method will write (debugging)
 * annotations.
 *
 * @param array {@code non-null;} array instance to write
 * @param topLevel {@code true} iff the given annotation is the
 * top-level annotation or {@code false} if it is a sub-annotation
 * of some other annotation
 */
public void writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();

    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }

    out.writeUleb128(size);

    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " +
                    constantToHuman(cst));
        }
        writeConstant(cst);
    }

    if (annotates) {
        out.endAnnotation();
    }
}
 
Example #5
Source File: ClassDataItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a {@link CstArray} corresponding to {@link #staticValues} if
 * it contains any non-zero non-{@code null} values.
 *
 * @return {@code null-ok;} the corresponding constant or {@code null} if
 * there are no values to encode
 */
public CstArray getStaticValuesConstant() {
    if ((staticValuesConstant == null) && (staticFields.size() != 0)) {
        staticValuesConstant = makeStaticValuesConstant();
    }

    return staticValuesConstant;
}
 
Example #6
Source File: AnnotationUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code MemberClasses} annotation.
 *
 * @param types {@code non-null;} the list of (the types of) the member classes
 * @return {@code non-null;} the annotation
 */
public static Annotation makeMemberClasses(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #7
Source File: ValueEncoder.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@code addContents()} methods, which adds
 * contents for a particular constant, calling itself recursively
 * should it encounter a {@link CstArray} and calling {@link
 * #addContents(DexFile,Annotation)} recursively should it
 * encounter a {@link CstAnnotation}.
 *
 * @param file {@code non-null;} the file to add to
 * @param cst {@code non-null;} the constant to add contents for
 */
public static void addContents(DexFile file, Constant cst) {
    if (cst instanceof CstAnnotation) {
        addContents(file, ((CstAnnotation) cst).getAnnotation());
    } else if (cst instanceof CstArray) {
        CstArray.List list = ((CstArray) cst).getList();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            addContents(file, list.get(i));
        }
    } else {
        file.internIfAppropriate(cst);
    }
}
 
Example #8
Source File: AnnotationUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code Throws} annotation.
 *
 * @param types {@code non-null;} the list of thrown types
 * @return {@code non-null;} the annotation
 */
public static Annotation makeThrows(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(THROWS_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #9
Source File: ClassDataItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a {@link CstArray} corresponding to {@link #staticValues} if
 * it contains any non-zero non-{@code null} values.
 *
 * @return {@code null-ok;} the corresponding constant or {@code null} if
 * there are no values to encode
 */
public CstArray getStaticValuesConstant() {
    if ((staticValuesConstant == null) && (staticFields.size() != 0)) {
        staticValuesConstant = makeStaticValuesConstant();
    }

    return staticValuesConstant;
}
 
Example #10
Source File: EncodedArrayItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param array {@code non-null;} array to represent
 */
public EncodedArrayItem(CstArray array) {
    /*
     * The write size isn't known up-front because (the variable-lengthed)
     * leb128 type is used to represent some things.
     */
    super(ALIGNMENT, -1);

    if (array == null) {
        throw new NullPointerException("array == null");
    }

    this.array = array;
    this.encodedForm = null;
}
 
Example #11
Source File: AnnotationUtils.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link TypeList} to a {@link CstArray}.
 *
 * @param types {@code non-null;} the type list
 * @return {@code non-null;} the corresponding array constant
 */
private static CstArray makeCstArray(TypeList types) {
    int size = types.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, CstType.intern(types.getType(i)));
    }

    list.setImmutable();
    return new CstArray(list);
}
 
Example #12
Source File: AnnotationUtils.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code Throws} annotation.
 *
 * @param types {@code non-null;} the list of thrown types
 * @return {@code non-null;} the annotation
 */
public static Annotation makeThrows(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(THROWS_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #13
Source File: AnnotationUtils.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link TypeList} to a {@link CstArray}.
 *
 * @param types {@code non-null;} the type list
 * @return {@code non-null;} the corresponding array constant
 */
private static CstArray makeCstArray(TypeList types) {
    int size = types.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, CstType.intern(types.getType(i)));
    }

    list.setImmutable();
    return new CstArray(list);
}
 
Example #14
Source File: AnnotationUtils.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code MemberClasses} annotation.
 *
 * @param types {@code non-null;} the list of (the types of) the member classes
 * @return {@code non-null;} the annotation
 */
public static Annotation makeMemberClasses(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #15
Source File: EncodedArrayItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param array {@code non-null;} array to represent
 */
public EncodedArrayItem(CstArray array) {
    /*
     * The write size isn't known up-front because (the variable-lengthed)
     * leb128 type is used to represent some things.
     */
    super(ALIGNMENT, -1);

    if (array == null) {
        throw new NullPointerException("array == null");
    }

    this.array = array;
    this.encodedForm = null;
}
 
Example #16
Source File: ValueEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@code addContents()} methods, which adds
 * contents for a particular constant, calling itself recursively
 * should it encounter a {@link CstArray} and calling {@link
 * #addContents(DexFile,Annotation)} recursively should it
 * encounter a {@link CstAnnotation}.
 *
 * @param file {@code non-null;} the file to add to
 * @param cst {@code non-null;} the constant to add contents for
 */
public static void addContents(DexFile file, Constant cst) {
    if (cst instanceof CstAnnotation) {
        addContents(file, ((CstAnnotation) cst).getAnnotation());
    } else if (cst instanceof CstArray) {
        CstArray.List list = ((CstArray) cst).getList();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            addContents(file, list.get(i));
        }
    } else {
        file.internIfAppropriate(cst);
    }
}
 
Example #17
Source File: ClassDataItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a {@link CstArray} corresponding to {@link #staticValues} if
 * it contains any non-zero non-{@code null} values.
 *
 * @return {@code null-ok;} the corresponding constant or {@code null} if
 * there are no values to encode
 */
public CstArray getStaticValuesConstant() {
    if ((staticValuesConstant == null) && (staticFields.size() != 0)) {
        staticValuesConstant = makeStaticValuesConstant();
    }

    return staticValuesConstant;
}
 
Example #18
Source File: EncodedArrayItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param array {@code non-null;} array to represent
 */
public EncodedArrayItem(CstArray array) {
    /*
     * The write size isn't known up-front because (the variable-lengthed)
     * leb128 type is used to represent some things.
     */
    super(ALIGNMENT, -1);

    if (array == null) {
        throw new NullPointerException("array == null");
    }

    this.array = array;
    this.encodedForm = null;
}
 
Example #19
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link TypeList} to a {@link CstArray}.
 *
 * @param types {@code non-null;} the type list
 * @return {@code non-null;} the corresponding array constant
 */
private static CstArray makeCstArray(TypeList types) {
    int size = types.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, CstType.intern(types.getType(i)));
    }

    list.setImmutable();
    return new CstArray(list);
}
 
Example #20
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code Throws} annotation.
 *
 * @param types {@code non-null;} the list of thrown types
 * @return {@code non-null;} the annotation
 */
public static Annotation makeThrows(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(THROWS_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #21
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code MemberClasses} annotation.
 *
 * @param types {@code non-null;} the list of (the types of) the member classes
 * @return {@code non-null;} the annotation
 */
public static Annotation makeMemberClasses(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #22
Source File: ValueEncoder.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@code addContents()} methods, which adds
 * contents for a particular constant, calling itself recursively
 * should it encounter a {@link CstArray} and calling {@link
 * #addContents(DexFile,Annotation)} recursively should it
 * encounter a {@link CstAnnotation}.
 *
 * @param file {@code non-null;} the file to add to
 * @param cst {@code non-null;} the constant to add contents for
 */
public static void addContents(DexFile file, Constant cst) {
    if (cst instanceof CstAnnotation) {
        addContents(file, ((CstAnnotation) cst).getAnnotation());
    } else if (cst instanceof CstArray) {
        CstArray.List list = ((CstArray) cst).getList();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            addContents(file, list.get(i));
        }
    } else {
        file.internIfAppropriate(cst);
    }
}
 
Example #23
Source File: ValueEncoder.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@code addContents()} methods, which adds
 * contents for a particular constant, calling itself recursively
 * should it encounter a {@link CstArray} and calling {@link
 * #addContents(DexFile,Annotation)} recursively should it
 * encounter a {@link CstAnnotation}.
 *
 * @param file {@code non-null;} the file to add to
 * @param cst {@code non-null;} the constant to add contents for
 */
public static void addContents(DexFile file, Constant cst) {
    if (cst instanceof CstAnnotation) {
        addContents(file, ((CstAnnotation) cst).getAnnotation());
    } else if (cst instanceof CstArray) {
        CstArray.List list = ((CstArray) cst).getList();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            addContents(file, list.get(i));
        }
    } else {
        file.internIfAppropriate(cst);
    }
}
 
Example #24
Source File: ClassDataItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a {@link CstArray} corresponding to {@link #staticValues} if
 * it contains any non-zero non-{@code null} values.
 *
 * @return {@code null-ok;} the corresponding constant or {@code null} if
 * there are no values to encode
 */
public CstArray getStaticValuesConstant() {
    if ((staticValuesConstant == null) && (staticFields.size() != 0)) {
        staticValuesConstant = makeStaticValuesConstant();
    }

    return staticValuesConstant;
}
 
Example #25
Source File: EncodedArrayItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param array {@code non-null;} array to represent
 */
public EncodedArrayItem(CstArray array) {
    /*
     * The write size isn't known up-front because (the variable-lengthed)
     * leb128 type is used to represent some things.
     */
    super(ALIGNMENT, -1);

    if (array == null) {
        throw new NullPointerException("array == null");
    }

    this.array = array;
    this.encodedForm = null;
}
 
Example #26
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link TypeList} to a {@link CstArray}.
 *
 * @param types {@code non-null;} the type list
 * @return {@code non-null;} the corresponding array constant
 */
private static CstArray makeCstArray(TypeList types) {
    int size = types.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, CstType.intern(types.getType(i)));
    }

    list.setImmutable();
    return new CstArray(list);
}
 
Example #27
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code Throws} annotation.
 *
 * @param types {@code non-null;} the list of thrown types
 * @return {@code non-null;} the annotation
 */
public static Annotation makeThrows(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(THROWS_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #28
Source File: AnnotationUtils.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a standard {@code MemberClasses} annotation.
 *
 * @param types {@code non-null;} the list of (the types of) the member classes
 * @return {@code non-null;} the annotation
 */
public static Annotation makeMemberClasses(TypeList types) {
    CstArray array = makeCstArray(types);
    Annotation result = new Annotation(MEMBER_CLASSES_TYPE, SYSTEM);
    result.put(new NameValuePair(VALUE_STRING, array));
    result.setImmutable();
    return result;
}
 
Example #29
Source File: ClassDefItem.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void addContents(DexFile file) {
    TypeIdsSection typeIds = file.getTypeIds();
    MixedItemSection byteData = file.getByteData();
    MixedItemSection wordData = file.getWordData();
    MixedItemSection typeLists = file.getTypeLists();
    StringIdsSection stringIds = file.getStringIds();

    typeIds.intern(thisClass);

    if (!classData.isEmpty()) {
        MixedItemSection classDataSection = file.getClassData();
        classDataSection.add(classData);

        CstArray staticValues = classData.getStaticValuesConstant();
        if (staticValues != null) {
            staticValuesItem =
                byteData.intern(new EncodedArrayItem(staticValues));
        }
    }

    if (superclass != null) {
        typeIds.intern(superclass);
    }

    if (interfaces != null) {
        interfaces = typeLists.intern(interfaces);
    }

    if (sourceFile != null) {
        stringIds.intern(sourceFile);
    }

    if (! annotationsDirectory.isEmpty()) {
        if (annotationsDirectory.isInternable()) {
            annotationsDirectory = wordData.intern(annotationsDirectory);
        } else {
            wordData.add(annotationsDirectory);
        }
    }
}
 
Example #30
Source File: ValueEncoder.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value type for the given constant.
 *
 * @param cst {@code non-null;} the constant
 * @return the value type; one of the {@code VALUE_*} constants
 * defined by this class
 */
private static int constantToValueType(Constant cst) {
    /*
     * TODO: Constant should probable have an associated enum, so this
     * can be a switch().
     */
    if (cst instanceof CstByte) {
        return VALUE_BYTE;
    } else if (cst instanceof CstShort) {
        return VALUE_SHORT;
    } else if (cst instanceof CstChar) {
        return VALUE_CHAR;
    } else if (cst instanceof CstInteger) {
        return VALUE_INT;
    } else if (cst instanceof CstLong) {
        return VALUE_LONG;
    } else if (cst instanceof CstFloat) {
        return VALUE_FLOAT;
    } else if (cst instanceof CstDouble) {
        return VALUE_DOUBLE;
    } else if (cst instanceof CstString) {
        return VALUE_STRING;
    } else if (cst instanceof CstType) {
        return VALUE_TYPE;
    } else if (cst instanceof CstFieldRef) {
        return VALUE_FIELD;
    } else if (cst instanceof CstMethodRef) {
        return VALUE_METHOD;
    } else if (cst instanceof CstEnumRef) {
        return VALUE_ENUM;
    } else if (cst instanceof CstArray) {
        return VALUE_ARRAY;
    } else if (cst instanceof CstAnnotation) {
        return VALUE_ANNOTATION;
    } else if (cst instanceof CstKnownNull) {
        return VALUE_NULL;
    } else if (cst instanceof CstBoolean) {
        return VALUE_BOOLEAN;
    } else {
        throw new RuntimeException("Shouldn't happen");
    }
}