Java Code Examples for com.android.dx.util.AnnotatedOutput#annotates()

The following examples show how to use com.android.dx.util.AnnotatedOutput#annotates() . 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: ClassDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        encodeOutput(file, out);
    } else {
        out.write(encodedForm);
    }
}
 
Example 2
Source File: MethodHandleItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int targetIndex = getTargetIndex(file);
    int mhType = methodHandle.getMethodHandleType();
    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + methodHandle.toString());
        String typeComment = " // " + CstMethodHandle.getMethodHandleTypeName(mhType);
        out.annotate(2, "type:     " + Hex.u2(mhType) + typeComment);
        out.annotate(2, "reserved: " + Hex.u2(0));
        String targetComment = " // " +  methodHandle.getRef().toString();
        if (methodHandle.isAccessor()) {
            out.annotate(2, "fieldId:  " + Hex.u2(targetIndex) + targetComment);
        } else {
            out.annotate(2, "methodId: " + Hex.u2(targetIndex) + targetComment);
        }
        out.annotate(2, "reserved: " + Hex.u2(0));
    }
    out.writeShort(mhType);
    out.writeShort(0);
    out.writeShort(getTargetIndex(file));
    out.writeShort(0);
}
 
Example 3
Source File: ClassDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        encodeOutput(file, out);
    } else {
        out.write(encodedForm);
    }
}
 
Example 4
Source File: UniformListItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    int size = items.size();

    if (out.annotates()) {
        out.annotate(0, offsetString() + " " + typeName());
        out.annotate(4, "  size: " + Hex.u4(size));
    }

    out.writeInt(size);

    for (OffsettedItem i : items) {
        i.writeTo(file, out);
    }
}
 
Example 5
Source File: AnnotationSetItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    int size = items.length;

    if (annotates) {
        out.annotate(0, offsetString() + " annotation set");
        out.annotate(4, "  size: " + Hex.u4(size));
    }

    out.writeInt(size);

    for (int i = 0; i < size; i++) {
        AnnotationItem item = items[i];
        int offset = item.getAbsoluteOffset();

        if (annotates) {
            out.annotate(4, "  entries[" + Integer.toHexString(i) + "]: " +
                    Hex.u4(offset));
            items[i].annotateTo(out, "    ");
        }

        out.writeInt(offset);
    }
}
 
Example 6
Source File: MemberIdItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public final void writeTo(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    StringIdsSection stringIds = file.getStringIds();
    CstNat nat = cst.getNat();
    int classIdx = typeIds.indexOf(getDefiningClass());
    int nameIdx = stringIds.indexOf(nat.getName());
    int typoidIdx = getTypoidIdx(file);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + cst.toHuman());
        out.annotate(2, "  class_idx: " + Hex.u2(classIdx));
        out.annotate(2, String.format("  %-10s %s", getTypoidName() + ':',
                        Hex.u2(typoidIdx)));
        out.annotate(4, "  name_idx:  " + Hex.u4(nameIdx));
    }

    out.writeShort(classIdx);
    out.writeShort(typoidIdx);
    out.writeInt(nameIdx);
}
 
Example 7
Source File: TypeIdsSection.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Writes the portion of the file header that refers to this instance.
 *
 * @param out {@code non-null;} where to write
 */
public void writeHeaderPart(AnnotatedOutput out) {
    throwIfNotPrepared();

    int sz = typeIds.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

    if (sz > DexFormat.MAX_TYPE_IDX + 1) {
        throw new DexIndexOverflowException("Too many type references: " + sz +
                "; max is " + (DexFormat.MAX_TYPE_IDX + 1) + ".\n" +
                Main.getTooManyIdsErrorMessage());
    }

    if (out.annotates()) {
        out.annotate(4, "type_ids_size:   " + Hex.u4(sz));
        out.annotate(4, "type_ids_off:    " + Hex.u4(offset));
    }

    out.writeInt(sz);
    out.writeInt(offset);
}
 
Example 8
Source File: EncodedArrayItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        out.annotate(0, offsetString() + " encoded array");

        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeArray(array, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 9
Source File: ClassDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Writes out the encoded form of this instance.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
private void encodeOutput(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        out.annotate(0, offsetString() + " class data for " +
                thisClass.toHuman());
    }

    encodeSize(file, out, "static_fields", staticFields.size());
    encodeSize(file, out, "instance_fields", instanceFields.size());
    encodeSize(file, out, "direct_methods", directMethods.size());
    encodeSize(file, out, "virtual_methods", virtualMethods.size());

    encodeList(file, out, "static_fields", staticFields);
    encodeList(file, out, "instance_fields", instanceFields);
    encodeList(file, out, "direct_methods", directMethods);
    encodeList(file, out, "virtual_methods", virtualMethods);

    if (annotates) {
        out.endAnnotation();
    }
}
 
Example 10
Source File: EncodedMethod.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int encode(DexFile file, AnnotatedOutput out,
        int lastIndex, int dumpSeq) {
    int methodIdx = file.getMethodIds().indexOf(method);
    int diff = methodIdx - lastIndex;
    int accessFlags = getAccessFlags();
    int codeOff = OffsettedItem.getAbsoluteOffsetOr0(code);
    boolean hasCode = (codeOff != 0);
    boolean shouldHaveCode = (accessFlags &
            (AccessFlags.ACC_ABSTRACT | AccessFlags.ACC_NATIVE)) == 0;

    /*
     * Verify that code appears if and only if a method is
     * declared to have it.
     */
    if (hasCode != shouldHaveCode) {
        throw new UnsupportedOperationException(
                "code vs. access_flags mismatch");
    }

    if (out.annotates()) {
        out.annotate(0, String.format("  [%x] %s", dumpSeq,
                        method.toHuman()));
        out.annotate(Leb128.unsignedLeb128Size(diff),
                "    method_idx:   " + Hex.u4(methodIdx));
        out.annotate(Leb128.unsignedLeb128Size(accessFlags),
                "    access_flags: " +
                AccessFlags.methodString(accessFlags));
        out.annotate(Leb128.unsignedLeb128Size(codeOff),
                "    code_off:     " + Hex.u4(codeOff));
    }

    out.writeUleb128(diff);
    out.writeUleb128(accessFlags);
    out.writeUleb128(codeOff);

    return methodIdx;
}
 
Example 11
Source File: MixedItemSection.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the portion of the file header that refers to this instance.
 *
 * @param out {@code non-null;} where to write
 */
public void writeHeaderPart(AnnotatedOutput out) {
    throwIfNotPrepared();

    if (writeSize == -1) {
        throw new RuntimeException("write size not yet set");
    }

    int sz = writeSize;
    int offset = (sz == 0) ? 0 : getFileOffset();
    String name = getName();

    if (name == null) {
        name = "<unnamed>";
    }

    int spaceCount = 15 - name.length();
    char[] spaceArr = new char[spaceCount];
    Arrays.fill(spaceArr, ' ');
    String spaces = new String(spaceArr);

    if (out.annotates()) {
        out.annotate(4, name + "_size:" + spaces + Hex.u4(sz));
        out.annotate(4, name + "_off: " + spaces + Hex.u4(offset));
    }

    out.writeInt(sz);
    out.writeInt(offset);
}
 
Example 12
Source File: MapItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    int value = type.getMapValue();
    int offset;

    if (firstItem == null) {
        offset = section.getFileOffset();
    } else {
        offset = section.getAbsoluteItemOffset(firstItem);
    }

    if (out.annotates()) {
        out.annotate(0, offsetString() + ' ' + type.getTypeName() +
                " map");
        out.annotate(2, "  type:   " + Hex.u2(value) + " // " +
                type.toString());
        out.annotate(2, "  unused: 0");
        out.annotate(4, "  size:   " + Hex.u4(itemCount));
        out.annotate(4, "  offset: " + Hex.u4(offset));
    }

    out.writeShort(value);
    out.writeShort(0); // unused
    out.writeInt(itemCount);
    out.writeInt(offset);
}
 
Example 13
Source File: MapItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    int value = type.getMapValue();
    int offset;

    if (firstItem == null) {
        offset = section.getFileOffset();
    } else {
        offset = section.getAbsoluteItemOffset(firstItem);
    }

    if (out.annotates()) {
        out.annotate(0, offsetString() + ' ' + type.getTypeName() +
                " map");
        out.annotate(2, "  type:   " + Hex.u2(value) + " // " +
                type.toString());
        out.annotate(2, "  unused: 0");
        out.annotate(4, "  size:   " + Hex.u4(itemCount));
        out.annotate(4, "  offset: " + Hex.u4(offset));
    }

    out.writeShort(value);
    out.writeShort(0); // unused
    out.writeInt(itemCount);
    out.writeInt(offset);
}
 
Example 14
Source File: FieldIdsSection.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the portion of the file header that refers to this instance.
 *
 * @param out {@code non-null;} where to write
 */
public void writeHeaderPart(AnnotatedOutput out) {
    throwIfNotPrepared();

    int sz = fieldIds.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

    if (out.annotates()) {
        out.annotate(4, "field_ids_size:  " + Hex.u4(sz));
        out.annotate(4, "field_ids_off:   " + Hex.u4(offset));
    }

    out.writeInt(sz);
    out.writeInt(offset);
}
 
Example 15
Source File: DebugInfoItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        /*
         * Re-run the encoder to generate the annotations,
         * but write the bits from the original encode
         */

        out.annotate(offsetString() + " debug info");
        encode(file, null, null, out, true);
    }

    out.write(encoded);
}
 
Example 16
Source File: MethodAnnotationStruct.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void writeTo(DexFile file, AnnotatedOutput out) {
    int methodIdx = file.getMethodIds().indexOf(method);
    int annotationsOff = annotations.getAbsoluteOffset();

    if (out.annotates()) {
        out.annotate(0, "    " + method.toHuman());
        out.annotate(4, "      method_idx:      " + Hex.u4(methodIdx));
        out.annotate(4, "      annotations_off: " +
                Hex.u4(annotationsOff));
    }

    out.writeInt(methodIdx);
    out.writeInt(annotationsOff);
}
 
Example 17
Source File: AnnotationSetRefItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    int annotationsOff = annotations.getAbsoluteOffset();

    if (out.annotates()) {
        out.annotate(4, "  annotations_off: " + Hex.u4(annotationsOff));
    }

    out.writeInt(annotationsOff);
}
 
Example 18
Source File: DebugInfoItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        /*
         * Re-run the encoder to generate the annotations,
         * but write the bits from the original encode
         */

        out.annotate(offsetString() + " debug info");
        encode(file, null, null, out, true);
    }

    out.write(encoded);
}
 
Example 19
Source File: FieldIdsSection.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the portion of the file header that refers to this instance.
 *
 * @param out {@code non-null;} where to write
 */
public void writeHeaderPart(AnnotatedOutput out) {
    throwIfNotPrepared();

    int sz = fieldIds.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

    if (out.annotates()) {
        out.annotate(4, "field_ids_size:  " + Hex.u4(sz));
        out.annotate(4, "field_ids_off:   " + Hex.u4(offset));
    }

    out.writeInt(sz);
    out.writeInt(offset);
}
 
Example 20
Source File: StringIdItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int dataOff = data.getAbsoluteOffset();

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + value.toQuoted(100));
        out.annotate(4, "  string_data_off: " + Hex.u4(dataOff));
    }

    out.writeInt(dataOff);
}