Java Code Examples for org.jf.dexlib2.util.AnnotatedBytes

The following examples show how to use org.jf.dexlib2.util.AnnotatedBytes. These examples are extracted from open source projects. 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 Project: ZjDroid   Author: KB5201314   File: AnnotationSetItem.java    License: 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 "annotation_set_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, AnnotationItem.getReferenceAnnotation(dexFile, annotationOffset));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #2
Source Project: ZjDroid   Author: KB5201314   File: ProtoIdItem.java    License: 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 "proto_id_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int shortyIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "shorty_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, shortyIndex));

            int returnTypeIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, returnTypeIndex));

            int parametersOffset = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "parameters_off = %s", TypeListItem.getReferenceAnnotation(dexFile, parametersOffset));
        }
    };
}
 
Example #3
Source Project: ZjDroid   Author: KB5201314   File: SectionAnnotator.java    License: Apache License 2.0 6 votes vote down vote up
protected void annotateSectionInner(@Nonnull AnnotatedBytes out, int itemCount) {
    String itemName = getItemName();
    int itemAlignment = getItemAlignment();
    if (itemCount > 0) {
        out.annotate(0, "");
        out.annotate(0, "-----------------------------");
        out.annotate(0, "%s section", itemName);
        out.annotate(0, "-----------------------------");
        out.annotate(0, "");

        for (int i=0; i<itemCount; i++) {
            out.moveTo(AlignmentUtils.alignOffset(out.getCursor(), itemAlignment));

            String itemIdentity = getItemIdentity(out.getCursor());
            if (itemIdentity != null) {
                out.annotate(0, "[%d] %s: %s", i, itemName, itemIdentity);
            } else {
                out.annotate(0, "[%d] %s", i, itemName);
            }
            out.indent();
            annotateItem(out, i, itemIdentity);
            out.deindent();
        }
    }
}
 
Example #4
Source Project: ZjDroid   Author: KB5201314   File: AnnotationSetRefList.java    License: 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 "annotation_set_ref_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationSetOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, "annotation_set_item[0x%x]", annotationSetOffset);
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #5
Source Project: ZjDroid   Author: KB5201314   File: StringIdItem.java    License: 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_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example #6
Source Project: ZjDroid   Author: KB5201314   File: EncodedValue.java    License: Apache License 2.0 6 votes vote down vote up
public static void annotateEncodedAnnotation(@Nonnull AnnotatedBytes out, @Nonnull DexReader reader) {
    assert out.getCursor() == reader.getOffset();

    int typeIndex = reader.readSmallUleb128();
    out.annotateTo(reader.getOffset(), TypeIdItem.getReferenceAnnotation(reader.dexBuf, typeIndex));

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

        int nameIndex = reader.readSmallUleb128();
        out.annotateTo(reader.getOffset(), "name = %s",
                StringIdItem.getReferenceAnnotation(reader.dexBuf, nameIndex));

        annotateEncodedValue(out, reader);

        out.deindent();
    }
}
 
Example #7
Source Project: ZjDroid   Author: KB5201314   File: MethodIdItem.java    License: 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 "method_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int classIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "class_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, classIndex));

            int protoIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "proto_idx = %s", ProtoIdItem.getReferenceAnnotation(dexFile, protoIndex));

            int nameIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "name_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, nameIndex));
        }
    };
}
 
Example #8
Source Project: ZjDroid   Author: KB5201314   File: TypeListItem.java    License: 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 "type_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size: %d", size);

            for (int i=0; i<size; i++) {
                int typeIndex = dexFile.readUshort(out.getCursor());
                out.annotate(2, TypeIdItem.getReferenceAnnotation(dexFile, typeIndex));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #9
Source Project: ZjDroid   Author: KB5201314   File: StringDataItem.java    License: 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 #10
Source Project: ZjDroid   Author: KB5201314   File: FieldIdItem.java    License: 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 "field_id_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int classIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "class_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, classIndex));

            int typeIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, typeIndex));

            int nameIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "name_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, nameIndex));
        }
    };
}
 
Example #11
Source Project: ZjDroid   Author: KB5201314   File: AnnotationItem.java    License: 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 "annotation_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int visibility = dexFile.readUbyte(out.getCursor());
            out.annotate(1, "visibility = %d: %s", visibility, getAnnotationVisibility(visibility));

            DexReader reader = dexFile.readerAt(out.getCursor());

            EncodedValue.annotateEncodedAnnotation(out, reader);
        }
    };
}
 
Example #12
Source Project: zjdroid   Author: Miracle963   File: AnnotationSetItem.java    License: 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 "annotation_set_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, AnnotationItem.getReferenceAnnotation(dexFile, annotationOffset));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #13
Source Project: zjdroid   Author: Miracle963   File: ProtoIdItem.java    License: 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 "proto_id_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int shortyIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "shorty_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, shortyIndex));

            int returnTypeIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, returnTypeIndex));

            int parametersOffset = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "parameters_off = %s", TypeListItem.getReferenceAnnotation(dexFile, parametersOffset));
        }
    };
}
 
Example #14
Source Project: zjdroid   Author: Miracle963   File: SectionAnnotator.java    License: Apache License 2.0 6 votes vote down vote up
protected void annotateSectionInner(@Nonnull AnnotatedBytes out, int itemCount) {
    String itemName = getItemName();
    int itemAlignment = getItemAlignment();
    if (itemCount > 0) {
        out.annotate(0, "");
        out.annotate(0, "-----------------------------");
        out.annotate(0, "%s section", itemName);
        out.annotate(0, "-----------------------------");
        out.annotate(0, "");

        for (int i=0; i<itemCount; i++) {
            out.moveTo(AlignmentUtils.alignOffset(out.getCursor(), itemAlignment));

            String itemIdentity = getItemIdentity(out.getCursor());
            if (itemIdentity != null) {
                out.annotate(0, "[%d] %s: %s", i, itemName, itemIdentity);
            } else {
                out.annotate(0, "[%d] %s", i, itemName);
            }
            out.indent();
            annotateItem(out, i, itemIdentity);
            out.deindent();
        }
    }
}
 
Example #15
Source Project: zjdroid   Author: Miracle963   File: AnnotationSetRefList.java    License: 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 "annotation_set_ref_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationSetOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, "annotation_set_item[0x%x]", annotationSetOffset);
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #16
Source Project: zjdroid   Author: Miracle963   File: StringIdItem.java    License: 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_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example #17
Source Project: zjdroid   Author: Miracle963   File: EncodedValue.java    License: Apache License 2.0 6 votes vote down vote up
public static void annotateEncodedAnnotation(@Nonnull AnnotatedBytes out, @Nonnull DexReader reader) {
    assert out.getCursor() == reader.getOffset();

    int typeIndex = reader.readSmallUleb128();
    out.annotateTo(reader.getOffset(), TypeIdItem.getReferenceAnnotation(reader.dexBuf, typeIndex));

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

        int nameIndex = reader.readSmallUleb128();
        out.annotateTo(reader.getOffset(), "name = %s",
                StringIdItem.getReferenceAnnotation(reader.dexBuf, nameIndex));

        annotateEncodedValue(out, reader);

        out.deindent();
    }
}
 
Example #18
Source Project: zjdroid   Author: Miracle963   File: MethodIdItem.java    License: 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 "method_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int classIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "class_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, classIndex));

            int protoIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "proto_idx = %s", ProtoIdItem.getReferenceAnnotation(dexFile, protoIndex));

            int nameIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "name_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, nameIndex));
        }
    };
}
 
Example #19
Source Project: zjdroid   Author: Miracle963   File: TypeListItem.java    License: 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 "type_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size: %d", size);

            for (int i=0; i<size; i++) {
                int typeIndex = dexFile.readUshort(out.getCursor());
                out.annotate(2, TypeIdItem.getReferenceAnnotation(dexFile, typeIndex));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #20
Source Project: zjdroid   Author: Miracle963   File: StringDataItem.java    License: 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 #21
Source Project: zjdroid   Author: Miracle963   File: FieldIdItem.java    License: 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 "field_id_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int classIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "class_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, classIndex));

            int typeIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, typeIndex));

            int nameIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "name_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, nameIndex));
        }
    };
}
 
Example #22
Source Project: zjdroid   Author: Miracle963   File: AnnotationItem.java    License: 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 "annotation_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int visibility = dexFile.readUbyte(out.getCursor());
            out.annotate(1, "visibility = %d: %s", visibility, getAnnotationVisibility(visibility));

            DexReader reader = dexFile.readerAt(out.getCursor());

            EncodedValue.annotateEncodedAnnotation(out, reader);
        }
    };
}
 
Example #23
Source Project: HeyGirl   Author: mikusjelly   File: AnnotationSetItem.java    License: 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 "annotation_set_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, AnnotationItem.getReferenceAnnotation(dexFile, annotationOffset));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #24
Source Project: HeyGirl   Author: mikusjelly   File: ProtoIdItem.java    License: 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 "proto_id_item";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int shortyIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "shorty_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, shortyIndex));

            int returnTypeIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "return_type_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, returnTypeIndex));

            int parametersOffset = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "parameters_off = %s", TypeListItem.getReferenceAnnotation(dexFile, parametersOffset));
        }
    };
}
 
Example #25
Source Project: HeyGirl   Author: mikusjelly   File: SectionAnnotator.java    License: Apache License 2.0 6 votes vote down vote up
protected void annotateSectionInner(@Nonnull AnnotatedBytes out, int itemCount) {
    String itemName = getItemName();
    int itemAlignment = getItemAlignment();
    if (itemCount > 0) {
        out.annotate(0, "");
        out.annotate(0, "-----------------------------");
        out.annotate(0, "%s section", itemName);
        out.annotate(0, "-----------------------------");
        out.annotate(0, "");

        for (int i=0; i<itemCount; i++) {
            out.moveTo(AlignmentUtils.alignOffset(out.getCursor(), itemAlignment));

            String itemIdentity = getItemIdentity(out.getCursor());
            if (itemIdentity != null) {
                out.annotate(0, "[%d] %s: %s", i, itemName, itemIdentity);
            } else {
                out.annotate(0, "[%d] %s", i, itemName);
            }
            out.indent();
            annotateItem(out, i, itemIdentity);
            out.deindent();
        }
    }
}
 
Example #26
Source Project: HeyGirl   Author: mikusjelly   File: AnnotationSetRefList.java    License: 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 "annotation_set_ref_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size = %d", size);

            for (int i=0; i<size; i++) {
                int annotationSetOffset = dexFile.readSmallUint(out.getCursor());
                out.annotate(4, "annotation_set_item[0x%x]", annotationSetOffset);
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}
 
Example #27
Source Project: HeyGirl   Author: mikusjelly   File: StringIdItem.java    License: 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_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int stringDataOffset = dexFile.readSmallUint(out.getCursor());
            try {
                String stringValue = dexFile.getString(itemIndex);
                out.annotate(4, "string_data_item[0x%x]: \"%s\"", stringDataOffset,
                        StringUtils.escapeString(stringValue));
                return;
            } catch (Exception ex) {
                System.err.print("Error while resolving string value at index: ");
                System.err.print(itemIndex);
                ex.printStackTrace(System.err);
            }

            out.annotate(4, "string_id_item[0x%x]", stringDataOffset);
        }
    };
}
 
Example #28
Source Project: HeyGirl   Author: mikusjelly   File: EncodedValue.java    License: Apache License 2.0 6 votes vote down vote up
public static void annotateEncodedAnnotation(@Nonnull AnnotatedBytes out, @Nonnull DexReader reader) {
    assert out.getCursor() == reader.getOffset();

    int typeIndex = reader.readSmallUleb128();
    out.annotateTo(reader.getOffset(), TypeIdItem.getReferenceAnnotation(reader.dexBuf, typeIndex));

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

        int nameIndex = reader.readSmallUleb128();
        out.annotateTo(reader.getOffset(), "name = %s",
                StringIdItem.getReferenceAnnotation(reader.dexBuf, nameIndex));

        annotateEncodedValue(out, reader);

        out.deindent();
    }
}
 
Example #29
Source Project: HeyGirl   Author: mikusjelly   File: MethodIdItem.java    License: 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 "method_id_item";
        }

        @Override
        public void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int classIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "class_idx = %s", TypeIdItem.getReferenceAnnotation(dexFile, classIndex));

            int protoIndex = dexFile.readUshort(out.getCursor());
            out.annotate(2, "proto_idx = %s", ProtoIdItem.getReferenceAnnotation(dexFile, protoIndex));

            int nameIndex = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "name_idx = %s", StringIdItem.getReferenceAnnotation(dexFile, nameIndex));
        }
    };
}
 
Example #30
Source Project: HeyGirl   Author: mikusjelly   File: TypeListItem.java    License: 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 "type_list";
        }

        @Override
        protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) {
            int size = dexFile.readSmallUint(out.getCursor());
            out.annotate(4, "size: %d", size);

            for (int i=0; i<size; i++) {
                int typeIndex = dexFile.readUshort(out.getCursor());
                out.annotate(2, TypeIdItem.getReferenceAnnotation(dexFile, typeIndex));
            }
        }

        @Override public int getItemAlignment() {
            return 4;
        }
    };
}