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

The following examples show how to use com.android.dx.util.AnnotatedOutput#annotate() . 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: EncodedArrayItem.java    From buck 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 2
Source File: ClassDataItem.java    From J2ME-Loader 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 3
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 4
Source File: Section.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Writes this instance to the given raw data object.
 *
 * @param out {@code non-null;} where to write to
 */
public final void writeTo(AnnotatedOutput out) {
    throwIfNotPrepared();
    align(out);

    int cursor = out.getCursor();

    if (fileOffset < 0) {
        fileOffset = cursor;
    } else if (fileOffset != cursor) {
        throw new RuntimeException("alignment mismatch: for " + this +
                                   ", at " + cursor +
                                   ", but expected " + fileOffset);
    }

    if (out.annotates()) {
        if (name != null) {
            out.annotate(0, "\n" + name + ":");
        } else if (cursor != 0) {
            out.annotate(0, "\n");
        }
    }

    writeTo0(out);
}
 
Example 5
Source File: EncodedField.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public int encode(DexFile file, AnnotatedOutput out,
        int lastIndex, int dumpSeq) {
    int fieldIdx = file.getFieldIds().indexOf(field);
    int diff = fieldIdx - lastIndex;
    int accessFlags = getAccessFlags();

    if (out.annotates()) {
        out.annotate(0, String.format("  [%x] %s", dumpSeq,
                        field.toHuman()));
        out.annotate(Leb128.unsignedLeb128Size(diff),
                "    field_idx:    " + Hex.u4(fieldIdx));
        out.annotate(Leb128.unsignedLeb128Size(accessFlags),
                "    access_flags: " +
                AccessFlags.fieldString(accessFlags));
    }

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

    return fieldIdx;
}
 
Example 6
Source File: ClassDefsSection.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 = classDefs.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

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

    out.writeInt(sz);
    out.writeInt(offset);
}
 
Example 7
Source File: FieldIdsSection.java    From buck 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 8
Source File: TypeIdItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }

    out.writeInt(idx);
}
 
Example 9
Source File: CatchStructs.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #annotateEntries} to annotate a catch handler list
 * while consuming it.
 *
 * @param handlers {@code non-null;} handlers to annotate
 * @param offset {@code >= 0;} the offset of this handler
 * @param size {@code >= 1;} the number of bytes the handlers consume
 * @param prefix {@code non-null;} prefix for each line
 * @param printTo {@code null-ok;} where to print to
 * @param annotateTo {@code non-null;} where to annotate to
 */
private static void annotateAndConsumeHandlers(CatchHandlerList handlers,
        int offset, int size, String prefix, PrintWriter printTo,
        AnnotatedOutput annotateTo) {
    String s = handlers.toHuman(prefix, Hex.u2(offset) + ": ");

    if (printTo != null) {
        printTo.println(s);
    }

    annotateTo.annotate(size, s);
}
 
Example 10
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 11
Source File: CallSiteIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int offset = data.getAbsoluteOffset();
    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + invokeDynamicRef.toString());
        out.annotate(4, "call_site_off: " + Hex.u4(offset));
    }
    out.writeInt(offset);
}
 
Example 12
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 13
Source File: MixedItemSection.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(AnnotatedOutput out) {
    boolean annotates = out.annotates();
    boolean first = true;
    DexFile file = getFile();
    int at = 0;

    for (OffsettedItem one : items) {
        if (annotates) {
            if (first) {
                first = false;
            } else {
                out.annotate(0, "\n");
            }
        }

        int alignMask = one.getAlignment() - 1;
        int writeAt = (at + alignMask) & ~alignMask;

        if (at != writeAt) {
            out.writeZeroes(writeAt - at);
            at = writeAt;
        }

        one.writeTo(file, out);
        at += one.writeSize();
    }

    if (at != writeSize) {
        throw new RuntimeException("output size mismatch");
    }
}
 
Example 14
Source File: TypeIdItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);

    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }

    out.writeInt(idx);
}
 
Example 15
Source File: StringIdItem.java    From Box 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);
}
 
Example 16
Source File: ParameterAnnotationStruct.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 = annotationsItem.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: 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 18
Source File: MixedItemSection.java    From buck 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 19
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 20
Source File: MethodIdsSection.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 = methodIds.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

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

    out.writeInt(sz);
    out.writeInt(offset);
}