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

The following examples show how to use com.android.dx.util.AnnotatedOutput#writeShort() . 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: MemberIdItem.java    From J2ME-Loader 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 2
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 3
Source File: TypeListItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    int sz = list.size();

    if (out.annotates()) {
        out.annotate(0, offsetString() + " type_list");
        out.annotate(HEADER_SIZE, "  size: " + Hex.u4(sz));
        for (int i = 0; i < sz; i++) {
            Type one = list.getType(i);
            int idx = typeIds.indexOf(one);
            out.annotate(ELEMENT_SIZE,
                         "  " + Hex.u2(idx) + " // " + one.toHuman());
        }
    }

    out.writeInt(sz);

    for (int i = 0; i < sz; i++) {
        out.writeShort(typeIds.indexOf(list.getType(i)));
    }
}
 
Example 4
Source File: TypeListItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    int sz = list.size();

    if (out.annotates()) {
        out.annotate(0, offsetString() + " type_list");
        out.annotate(HEADER_SIZE, "  size: " + Hex.u4(sz));
        for (int i = 0; i < sz; i++) {
            Type one = list.getType(i);
            int idx = typeIds.indexOf(one);
            out.annotate(ELEMENT_SIZE,
                         "  " + Hex.u2(idx) + " // " + one.toHuman());
        }
    }

    out.writeInt(sz);

    for (int i = 0; i < sz; i++) {
        out.writeShort(typeIds.indexOf(list.getType(i)));
    }
}
 
Example 5
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 6
Source File: TypeListItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    TypeIdsSection typeIds = file.getTypeIds();
    int sz = list.size();

    if (out.annotates()) {
        out.annotate(0, offsetString() + " type_list");
        out.annotate(HEADER_SIZE, "  size: " + Hex.u4(sz));
        for (int i = 0; i < sz; i++) {
            Type one = list.getType(i);
            int idx = typeIds.indexOf(one);
            out.annotate(ELEMENT_SIZE,
                         "  " + Hex.u2(idx) + " // " + one.toHuman());
        }
    }

    out.writeInt(sz);

    for (int i = 0; i < sz; i++) {
        out.writeShort(typeIds.indexOf(list.getType(i)));
    }
}
 
Example 7
Source File: OddSpacer.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out) {
    if (codeSize() != 0) {
        out.writeShort(InsnFormat.codeUnit(Opcodes.NOP, 0));
    }
}
 
Example 8
Source File: MapItem.java    From J2ME-Loader 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 9
Source File: CatchStructs.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 10
Source File: MapItem.java    From buck 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 11
Source File: CodeItem.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    int regSz = getRegistersSize();
    int outsSz = getOutsSize();
    int insSz = getInsSize();
    int insnsSz = code.getInsns().codeSize();
    boolean needPadding = (insnsSz & 1) != 0;
    int triesSz = (catches == null) ? 0 : catches.triesSize();
    int debugOff = (debugInfo == null) ? 0 : debugInfo.getAbsoluteOffset();

    if (annotates) {
        out.annotate(0, offsetString() + ' ' + ref.toHuman());
        out.annotate(2, "  registers_size: " + Hex.u2(regSz));
        out.annotate(2, "  ins_size:       " + Hex.u2(insSz));
        out.annotate(2, "  outs_size:      " + Hex.u2(outsSz));
        out.annotate(2, "  tries_size:     " + Hex.u2(triesSz));
        out.annotate(4, "  debug_off:      " + Hex.u4(debugOff));
        out.annotate(4, "  insns_size:     " + Hex.u4(insnsSz));

        // This isn't represented directly here, but it is useful to see.
        int size = throwsList.size();
        if (size != 0) {
            out.annotate(0, "  throws " + StdTypeList.toHuman(throwsList));
        }
    }

    out.writeShort(regSz);
    out.writeShort(insSz);
    out.writeShort(outsSz);
    out.writeShort(triesSz);
    out.writeInt(debugOff);
    out.writeInt(insnsSz);

    writeCodes(file, out);

    if (catches != null) {
        if (needPadding) {
            if (annotates) {
                out.annotate(2, "  padding: 0");
            }
            out.writeShort(0);
        }

        catches.writeTo(file, out);
    }

    if (annotates) {
        /*
         * These are pointed at in the code header (above), but it's less
         * distracting to expand on them at the bottom of the code.
         */
        if (debugInfo != null) {
            out.annotate(0, "  debug info");
            debugInfo.annotateTo(file, out, "    ");
        }
    }
}
 
Example 12
Source File: InsnFormat.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Writes three code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 * @param c2 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1,
        short c2) {
    out.writeShort(c0);
    out.writeShort(c1);
    out.writeShort(c2);
}
 
Example 13
Source File: InsnFormat.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Writes five code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 * @param c2 code unit to write
 * @param c3 code unit to write
 * @param c4 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1,
        short c2, short c3, short c4) {
    out.writeShort(c0);
    out.writeShort(c1);
    out.writeShort(c2);
    out.writeShort(c3);
    out.writeShort(c4);
}
 
Example 14
Source File: InsnFormat.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Writes three code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 * @param c2 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1,
        short c2) {
    out.writeShort(c0);
    out.writeShort(c1);
    out.writeShort(c2);
}
 
Example 15
Source File: InsnFormat.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Writes five code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 * @param c2 code unit to write
 * @param c3 code unit to write
 * @param c4 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1,
        short c2, short c3, short c4) {
    out.writeShort(c0);
    out.writeShort(c1);
    out.writeShort(c2);
    out.writeShort(c3);
    out.writeShort(c4);
}
 
Example 16
Source File: InsnFormat.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Writes five code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 * @param c2 code unit to write
 * @param c3 code unit to write
 * @param c4 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1,
        short c2, short c3, short c4) {
    out.writeShort(c0);
    out.writeShort(c1);
    out.writeShort(c2);
    out.writeShort(c3);
    out.writeShort(c4);
}
 
Example 17
Source File: InsnFormat.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Writes one code unit to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0) {
    out.writeShort(c0);
}
 
Example 18
Source File: InsnFormat.java    From J2ME-Loader with Apache License 2.0 2 votes vote down vote up
/**
 * Writes one code unit to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0) {
    out.writeShort(c0);
}
 
Example 19
Source File: InsnFormat.java    From buck with Apache License 2.0 2 votes vote down vote up
/**
 * Writes one code unit to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0) {
    out.writeShort(c0);
}
 
Example 20
Source File: InsnFormat.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Writes two code units to the given output destination.
 *
 * @param out {@code non-null;} where to write to
 * @param c0 code unit to write
 * @param c1 code unit to write
 */
protected static void write(AnnotatedOutput out, short c0, short c1) {
    out.writeShort(c0);
    out.writeShort(c1);
}