@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { int itemType = dexFile.readUshort(out.getCursor()); out.annotate(2, "type = 0x%x: %s", itemType, ItemType.getItemTypeName(itemType)); out.annotate(2, "unused"); int size = dexFile.readSmallUint(out.getCursor()); out.annotate(4, "size = %d", size); int offset = dexFile.readSmallUint(out.getCursor()); out.annotate(4, "offset = 0x%x", offset); }
@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { int startOffset = out.getCursor(); int headerSize; out.annotate(8, "magic: %s", StringUtils.escapeString(magicBuilder.toString())); out.annotate(4, "checksum"); out.annotate(20, "signature"); out.annotate(4, "file_size: %d", dexFile.readInt(out.getCursor())); headerSize = dexFile.readInt(out.getCursor()); out.annotate(4, "header_size: %d", headerSize); int endianTag = dexFile.readInt(out.getCursor()); out.annotate(4, "endian_tag: 0x%x (%s)", endianTag, getEndianText(endianTag)); out.annotate(4, "link_size: %d", dexFile.readInt(out.getCursor())); out.annotate(4, "link_offset: 0x%x", dexFile.readInt(out.getCursor())); out.annotate(4, "map_off: 0x%x", dexFile.readInt(out.getCursor())); out.annotate(4, "string_ids_size: %d", dexFile.readInt(out.getCursor())); out.annotate(4, "string_ids_off: 0x%x", dexFile.readInt(out.getCursor())); out.annotate(4, "type_ids_size: %d", dexFile.readInt(out.getCursor())); out.annotate(4, "type_ids_off: 0x%x", dexFile.readInt(out.getCursor())); out.annotate(4, "proto_ids_size: %d", dexFile.readInt(out.getCursor())); out.annotate(4, "proto_ids_off: 0x%x", dexFile.readInt(out.getCursor()));
public static void annotateEncodedArray(@Nonnull AnnotatedBytes out, @Nonnull DexReader reader) { assert out.getCursor() == reader.getOffset(); int size = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "size: %d", size); for (int i=0; i<size; i++) { out.annotate(0, "element[%d]", i); out.indent(); annotateEncodedValue(out, reader); out.deindent(); } }
@Override public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { try { DexReader reader = dexFile.readerAt(out.getCursor()); out.annotate(2, "registers_size = %d", registers); out.annotate(2, "ins_size = %d", inSize); out.annotate(2, "outs_size = %d", outSize); out.annotate(2, "tries_size = %d", triesCount); out.annotate(4, "debug_info_off = 0x%x", debugInfoOffset); out.annotate(4, "insns_size = 0x%x", instructionSize); out.annotate(0, "instructions:"); out.indent(); out.setLimit(out.getCursor(), out.getCursor() + instructionSize * 2); out.annotateTo(end, "truncated instruction"); reader.setOffset(end); } else { assert reader.getOffset() == out.getCursor(); out.annotate(0, "annotation error: %s", ex.getMessage()); out.moveTo(end);
private void annotatePackedSwitchPayload(@Nonnull AnnotatedBytes out, @Nonnull PackedSwitchPayload instruction) { List<? extends SwitchElement> elements = instruction.getSwitchElements(); out.annotate(2, instruction.getOpcode().name); out.indent(); out.annotate(2, "size = %d", elements.size()); if (elements.size() == 0) { out.annotate(4, "first_key"); } else { out.annotate(4, "first_key = %d", elements.get(0).getKey()); out.annotate(0, "targets:"); out.indent(); for (int i=0; i<elements.size(); i++) { out.annotate(4, "target[%d] = %d", i, elements.get(i).getOffset()); } out.deindent(); } out.deindent(); }
@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { DexReader reader = dexFile.readerAt(out.getCursor()); int utf16Length = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length); String value = reader.readString(utf16Length); out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value)); } };
public void annotateTo(int offset, @Nonnull String msg, Object... formatArgs) { annotate(offset - cursor, msg, formatArgs); }
private String formatAnnotation(int offset, String annotationMsg) { Integer endOffset = annotatations.higherKey(offset); return formatAnnotation(offset, endOffset, annotationMsg); }
private int annotateEncodedField(@Nonnull AnnotatedBytes out, @Nonnull RawDexFile dexFile, @Nonnull DexReader reader, int previousIndex) { // large values may be used for the index delta, which cause the cumulative index to overflow upon // addition, effectively allowing out of order entries. int indexDelta = reader.readLargeUleb128(); int fieldIndex = previousIndex + indexDelta; out.annotateTo(reader.getOffset(), "field_idx_diff = %d: %s", indexDelta, FieldIdItem.getReferenceAnnotation(dexFile, fieldIndex)); int accessFlags = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "access_flags = 0x%x: %s", accessFlags, Joiner.on('|').join(AccessFlags.getAccessFlagsForField(accessFlags))); return fieldIndex; }
@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { DexReader reader = dexFile.readerAt(out.getCursor()); EncodedValue.annotateEncodedArray(out, reader); } };
/** * Write out annotations for this section * * @param out The AnnotatedBytes object to annotate to */ public void annotateSection(@Nonnull AnnotatedBytes out) { out.moveTo(sectionOffset); annotateSectionInner(out, itemCount); }
int rightWidth = getAnnotationWidth(); int leftWidth = outputWidth - rightWidth - 1;
public static void annotateEncodedArray(@Nonnull AnnotatedBytes out, @Nonnull DexReader reader) { assert out.getCursor() == reader.getOffset(); int size = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "size: %d", size); for (int i=0; i<size; i++) { out.annotate(0, "element[%d]", i); out.indent(); annotateEncodedValue(out, reader); out.deindent(); } }
@Override public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { try { DexReader reader = dexFile.readerAt(out.getCursor()); out.annotate(2, "registers_size = %d", registers); out.annotate(2, "ins_size = %d", inSize); out.annotate(2, "outs_size = %d", outSize); out.annotate(2, "tries_size = %d", triesCount); out.annotate(4, "debug_info_off = 0x%x", debugInfoOffset); out.annotate(4, "insns_size = 0x%x", instructionSize); out.annotate(0, "instructions:"); out.indent(); out.setLimit(out.getCursor(), out.getCursor() + instructionSize * 2); out.annotateTo(end, "truncated instruction"); reader.setOffset(end); } else { assert reader.getOffset() == out.getCursor(); out.annotate(0, "annotation error: %s", ex.getMessage()); out.moveTo(end);
private void annotateSparseSwitchPayload(@Nonnull AnnotatedBytes out, @Nonnull SparseSwitchPayload instruction) { List<? extends SwitchElement> elements = instruction.getSwitchElements(); out.annotate(2, instruction.getOpcode().name); out.indent(); out.annotate(2, "size = %d", elements.size()); if (elements.size() > 0) { out.annotate(0, "keys:"); out.indent(); for (int i=0; i<elements.size(); i++) { out.annotate(4, "key[%d] = %d", i, elements.get(i).getKey()); } out.deindent(); out.annotate(0, "targets:"); out.indent(); for (int i=0; i<elements.size(); i++) { out.annotate(4, "target[%d] = %d", i, elements.get(i).getOffset()); } out.deindent(); } out.deindent(); }
@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { DexReader reader = dexFile.readerAt(out.getCursor()); int utf16Length = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "utf16_size = %d", utf16Length); String value = reader.readString(utf16Length); out.annotateTo(reader.getOffset() + 1, "data = \"%s\"", StringUtils.escapeString(value)); } };
public void annotateTo(int offset, @Nonnull String msg, Object... formatArgs) { annotate(offset - cursor, msg, formatArgs); }
private String formatAnnotation(int offset, String annotationMsg) { Integer endOffset = annotatations.higherKey(offset); return formatAnnotation(offset, endOffset, annotationMsg); }
private int annotateEncodedField(@Nonnull AnnotatedBytes out, @Nonnull RawDexFile dexFile, @Nonnull DexReader reader, int previousIndex) { // large values may be used for the index delta, which cause the cumulative index to overflow upon // addition, effectively allowing out of order entries. int indexDelta = reader.readLargeUleb128(); int fieldIndex = previousIndex + indexDelta; out.annotateTo(reader.getOffset(), "field_idx_diff = %d: %s", indexDelta, FieldIdItem.getReferenceAnnotation(dexFile, fieldIndex)); int accessFlags = reader.readSmallUleb128(); out.annotateTo(reader.getOffset(), "access_flags = 0x%x: %s", accessFlags, Joiner.on('|').join(AccessFlags.getAccessFlagsForField(accessFlags))); return fieldIndex; }