Java Code Examples for org.jf.dexlib2.util.AnnotatedBytes#annotateTo()

The following examples show how to use org.jf.dexlib2.util.AnnotatedBytes#annotateTo() . 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: StringDataItem.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @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));
        }
    };
}
 
Example 2
Source File: StringDataItem.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @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));
        }
    };
}
 
Example 3
Source File: StringDataItem.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @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));
        }
    };
}
 
Example 4
Source File: StringDataItem.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "string_data_item";
        }

        @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));
        }
    };
}
 
Example 5
Source File: HeaderItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "header_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int startOffset = out.getCursor();
            int headerSize;

            StringBuilder magicBuilder = new StringBuilder();
            for (int i=0; i<8; i++) {
                magicBuilder.append((char)dexFile.readUbyte(startOffset + i));
            }

            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()));

            out.annotate(4, "field_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "field_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "method_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "method_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "class_defs_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "class_defs_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "data_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "data_off: 0x%x", dexFile.readInt(out.getCursor()));

            if (headerSize > ITEM_SIZE) {
                out.annotateTo(headerSize, "header padding");
            }
        }
    };
}
 
Example 6
Source File: HeaderItem.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "header_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int startOffset = out.getCursor();
            int headerSize;

            StringBuilder magicBuilder = new StringBuilder();
            for (int i=0; i<8; i++) {
                magicBuilder.append((char)dexFile.readUbyte(startOffset + i));
            }

            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()));

            out.annotate(4, "field_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "field_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "method_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "method_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "class_defs_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "class_defs_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "data_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "data_off: 0x%x", dexFile.readInt(out.getCursor()));

            if (headerSize > ITEM_SIZE) {
                out.annotateTo(headerSize, "header padding");
            }
        }
    };
}
 
Example 7
Source File: HeaderItem.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "header_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int startOffset = out.getCursor();
            int headerSize;

            StringBuilder magicBuilder = new StringBuilder();
            for (int i=0; i<8; i++) {
                magicBuilder.append((char)dexFile.readUbyte(startOffset + i));
            }

            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()));

            out.annotate(4, "field_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "field_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "method_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "method_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "class_defs_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "class_defs_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "data_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "data_off: 0x%x", dexFile.readInt(out.getCursor()));

            if (headerSize > ITEM_SIZE) {
                out.annotateTo(headerSize, "header padding");
            }
        }
    };
}
 
Example 8
Source File: HeaderItem.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static SectionAnnotator makeAnnotator(@Nonnull DexAnnotator annotator, @Nonnull MapItem mapItem) {
    return new SectionAnnotator(annotator, mapItem) {
        @Nonnull @Override public String getItemName() {
            return "header_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int startOffset = out.getCursor();
            int headerSize;

            StringBuilder magicBuilder = new StringBuilder();
            for (int i=0; i<8; i++) {
                magicBuilder.append((char)dexFile.readUbyte(startOffset + i));
            }

            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()));

            out.annotate(4, "field_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "field_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "method_ids_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "method_ids_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "class_defs_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "class_defs_off: 0x%x", dexFile.readInt(out.getCursor()));

            out.annotate(4, "data_size: %d", dexFile.readInt(out.getCursor()));
            out.annotate(4, "data_off: 0x%x", dexFile.readInt(out.getCursor()));

            if (headerSize > ITEM_SIZE) {
                out.annotateTo(headerSize, "header padding");
            }
        }
    };
}