/**
   * 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 = strings.size();
    int offset = (sz == 0) ? 0 : getFileOffset();

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

    out.writeInt(sz);
    out.writeInt(offset);
  }
Пример #2
0
  /** {@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);
  }