Java Code Examples for com.android.dx.rop.cst.CstArray#List

The following examples show how to use com.android.dx.rop.cst.CstArray#List . 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 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 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 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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: AnnotationUtils.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);

    /*
     * Split the string into pieces that are likely to be common
     * across many signatures and the rest of the file.
     */

    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);

    for (int at = 0; at < rawLength; /*at*/) {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }

        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }

    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }

    list.setImmutable();

    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}
 
Example 14
Source File: AnnotationUtils.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);

    /*
     * Split the string into pieces that are likely to be common
     * across many signatures and the rest of the file.
     */

    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);

    for (int at = 0; at < rawLength; /*at*/) {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }

        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }

    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }

    list.setImmutable();

    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}
 
Example 15
Source File: AnnotationUtils.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);

    /*
     * Split the string into pieces that are likely to be common
     * across many signatures and the rest of the file.
     */

    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);

    for (int at = 0; at < rawLength; /*at*/) {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }

        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }

    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }

    list.setImmutable();

    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}
 
Example 16
Source File: AnnotationUtils.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);

    /*
     * Split the string into pieces that are likely to be common
     * across many signatures and the rest of the file.
     */

    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);

    for (int at = 0; at < rawLength; /*at*/) {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }

        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }

    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);

    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }

    list.setImmutable();

    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}