/** * Aligns the output of the given data to the alignment of this instance. * * @param out {@code non-null;} the output to align */ protected final void align(AnnotatedOutput out) { out.alignTo(alignment); }
/** {@inheritDoc} */ @Override public void writeTo0(DexFile file, AnnotatedOutput out) { ByteArray bytes = value.getBytes(); int utf16Size = value.getUtf16Size(); if (out.annotates()) { out.annotate(Leb128.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size)); out.annotate(bytes.size() + 1, value.toQuoted()); } out.writeUleb128(utf16Size); out.write(bytes); out.writeByte(0); }
/** {@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); }
int startCursor = out.getCursor(); int sz = size(); if (out.annotates()) { boolean verbose = out.isVerbose(); s = insn.listingString(" ", out.getAnnotationWidth(), true); } else { out.annotate(codeBytes, s); } else if (codeBytes != 0) { out.annotate(codeBytes, ""); int written = (out.getCursor() - startCursor) / 2; if (written != codeSize()) { throw new RuntimeException("write length mismatch; expected " +
boolean annotates = topLevel && out.annotates(); CstArray.List list = ((CstArray) array).getList(); int size = list.size(); out.annotate(" size: " + Hex.u4(size)); out.writeUleb128(size); out.annotate(" [" + Integer.toHexString(i) + "] " + constantToHuman(cst)); out.endAnnotation();
/** * 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(); } }
/** * 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); }
/** {@inheritDoc} */ @Override public final void writeTo(DexFile file, AnnotatedOutput out) { out.alignTo(alignment); try { if (writeSize < 0) { throw new UnsupportedOperationException( "writeSize is unknown"); } out.assertCursor(getAbsoluteOffset()); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, "...while writing " + this); } writeTo0(file, out); }
boolean annotates = topLevel && out.annotates(); CstArray.List list = ((CstArray) array).getList(); int size = list.size(); out.annotate(" size: " + Hex.u4(size)); out.writeUnsignedLeb128(size); out.annotate(" [" + Integer.toHexString(i) + "] " + constantToHuman(cst)); out.endAnnotation();
/** * Helper for {@link #writeConstant}, which writes out the value * for any unsigned integral type. * * @param type the type constant * @param value {@code long} bits of the value */ private void writeUnsignedIntegralValue(int type, long value) { // Figure out how many bits are needed to represent the value. int requiredBits = 64 - Long.numberOfLeadingZeros(value); if (requiredBits == 0) { requiredBits = 1; } // Round up the requiredBits to a number of bytes. int requiredBytes = (requiredBits + 0x07) >> 3; /* * Write the header byte, which includes the type and * requiredBytes - 1. */ out.writeByte(type | ((requiredBytes - 1) << 5)); // Write the value, per se. while (requiredBytes > 0) { out.writeByte((byte) value); value >>= 8; requiredBytes--; } }
/** * Writes this instance as an annotation. * * @param out {@code non-null;} where to write to */ public void writeAnnotation(AnnotatedOutput out) { out.annotate(toHuman()); }
int startCursor = out.getCursor(); int sz = size(); if (out.annotates()) { boolean verbose = out.isVerbose(); s = insn.listingString(" ", out.getAnnotationWidth(), true); } else { out.annotate(codeBytes, s); } else if (codeBytes != 0) { out.annotate(codeBytes, ""); int written = (out.getCursor() - startCursor) / 2; if (written != codeSize()) { throw new RuntimeException("write length mismatch; expected " +
boolean annotates = topLevel && out.annotates(); CstArray.List list = ((CstArray) array).getList(); int size = list.size(); out.annotate(" size: " + Hex.u4(size)); out.writeUleb128(size); out.annotate(" [" + Integer.toHexString(i) + "] " + constantToHuman(cst)); out.endAnnotation();
/** {@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); }
/** * 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(); } }
/** * 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); }
/** {@inheritDoc} */ @Override public final void writeTo(DexFile file, AnnotatedOutput out) { out.alignTo(alignment); try { if (writeSize < 0) { throw new UnsupportedOperationException( "writeSize is unknown"); } out.assertCursor(getAbsoluteOffset()); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, "...while writing " + this); } writeTo0(file, out); }
/** * Helper for {@link #writeConstant}, which writes out the value * for any unsigned integral type. * * @param type the type constant * @param value {@code long} bits of the value */ private void writeUnsignedIntegralValue(int type, long value) { // Figure out how many bits are needed to represent the value. int requiredBits = 64 - Long.numberOfLeadingZeros(value); if (requiredBits == 0) { requiredBits = 1; } // Round up the requiredBits to a number of bytes. int requiredBytes = (requiredBits + 0x07) >> 3; /* * Write the header byte, which includes the type and * requiredBytes - 1. */ out.writeByte(type | ((requiredBytes - 1) << 5)); // Write the value, per se. while (requiredBytes > 0) { out.writeByte((byte) value); value >>= 8; requiredBytes--; } }