@Nonnull public AnnotationIterator getMethodAnnotationIterator() { int methodCount = getMethodAnnotationCount(); if (methodCount == 0) { return AnnotationIterator.EMPTY; } int fieldCount = getFieldAnnotationCount(); int methodAnnotationsOffset = directoryOffset + ANNOTATIONS_START_OFFSET + fieldCount * FIELD_ANNOTATION_SIZE; return new AnnotationIteratorImpl(methodAnnotationsOffset, methodCount); }
@Nonnull public AnnotationIterator getParameterAnnotationIterator() { int parameterAnnotationCount = getParameterAnnotationCount(); if (parameterAnnotationCount == 0) { return AnnotationIterator.EMPTY; } int fieldCount = getFieldAnnotationCount(); int methodCount = getMethodAnnotationCount(); int parameterAnnotationsOffset = directoryOffset + ANNOTATIONS_START_OFFSET + fieldCount * FIELD_ANNOTATION_SIZE + methodCount * METHOD_ANNOTATION_SIZE; return new AnnotationIteratorImpl(parameterAnnotationsOffset, parameterAnnotationCount); }
@Nonnull public AnnotationIterator getFieldAnnotationIterator() { int fieldAnnotationCount = getFieldAnnotationCount(); if (fieldAnnotationCount == 0) { return AnnotationIterator.EMPTY; } return new AnnotationIteratorImpl(directoryOffset + ANNOTATIONS_START_OFFSET, fieldAnnotationCount); }
public Iterator<DexBackedMethod> iterator() { final AnnotationsDirectory.AnnotationIterator methodAnnotationIterator = annotationsDirectory.getMethodAnnotationIterator(); final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator = annotationsDirectory.getParameterAnnotationIterator();
public Iterator<DexBackedField> iterator() { final AnnotationsDirectory.AnnotationIterator annotationIterator = annotationsDirectory.getFieldAnnotationIterator(); final EncodedArrayItemIterator staticInitialValueIterator = EncodedArrayItemIterator.newOrEmpty(dexFile, staticInitialValuesOffset);
/** * Calculate and return the private size of a method implementation. * * Calculated as: debug info size + instructions size + try-catch size * * @return size in bytes */ public int getSize() { int debugSize = getDebugInfo().getSize(); //set last offset just before bytecode instructions (after insns_size) int lastOffset = codeOffset + CodeItem.INSTRUCTION_START_OFFSET; //set code_item ending offset to the end of instructions list (insns_size * ushort) lastOffset += dexFile.readSmallUint(codeOffset + CodeItem.INSTRUCTION_COUNT_OFFSET) * 2; //read any exception handlers and move code_item offset to the end for (DexBackedTryBlock tryBlock: getTryBlocks()) { Iterator<? extends DexBackedExceptionHandler> tryHandlerIter = tryBlock.getExceptionHandlers().iterator(); while (tryHandlerIter.hasNext()) { tryHandlerIter.next(); } lastOffset = ((VariableSizeListIterator)tryHandlerIter).getReaderOffset(); } //method impl size = debug block size + code_item size return debugSize + (lastOffset - codeOffset); } }
@Nonnull @Override public Set<? extends Annotation> getAnnotations() { return AnnotationsDirectory.getAnnotations(dexFile, methodAnnotationSetOffset); }
@Nonnull @Override public Set<? extends DexBackedAnnotation> getAnnotations() { return getAnnotationsDirectory().getClassAnnotations(); }
@Nonnull public List<? extends Set<? extends DexBackedAnnotation>> getParameterAnnotations() { return AnnotationsDirectory.getParameterAnnotations(dexFile, parameterAnnotationSetListOffset); }
@Nonnull public static AnnotationsDirectory newOrEmpty(@Nonnull DexBackedDexFile dexFile, int directoryAnnotationsOffset) { if (directoryAnnotationsOffset == 0) { return EMPTY; } return new AnnotationsDirectoryImpl(dexFile, directoryAnnotationsOffset); }
public Iterator<DexBackedField> iterator() { final AnnotationsDirectory.AnnotationIterator annotationIterator = annotationsDirectory.getFieldAnnotationIterator();
private AnnotationsDirectory getAnnotationsDirectory() { if (annotationsDirectory == null) { int annotationsDirectoryOffset = dexFile.readSmallUint(classDefOffset + ClassDefItem.ANNOTATIONS_OFFSET); annotationsDirectory = AnnotationsDirectory.newOrEmpty(dexFile, annotationsDirectoryOffset); } return annotationsDirectory; }
@Nonnull public Set<? extends DexBackedAnnotation> getClassAnnotations() { return getAnnotations(dexFile, dexFile.readSmallUint(directoryOffset)); }
@Nonnull private DebugInfo getDebugInfo() { int debugOffset = dexFile.readInt(codeOffset + CodeItem.DEBUG_INFO_OFFSET); if (debugOffset == -1 || debugOffset == 0) { return DebugInfo.newOrEmpty(dexFile, 0, this); } if (debugOffset < 0) { System.err.println(String.format("%s: Invalid debug offset", method)); return DebugInfo.newOrEmpty(dexFile, 0, this); } if (debugOffset >= dexFile.buf.length) { System.err.println(String.format("%s: Invalid debug offset", method)); return DebugInfo.newOrEmpty(dexFile, 0, this); } return DebugInfo.newOrEmpty(dexFile, debugOffset, this); }
@Nonnull public Iterator<String> getParameterNames(@Nullable DexReader dexReader) { return getDebugInfo().getParameterNames(dexReader); }
@Nonnull @Override public Iterator<MethodParameter> iterator() { return new ParameterIterator(parameterTypes, getParameterAnnotations(), getParameterNames()); }
public DexBackedMethod(@Nonnull DexReader reader, @Nonnull DexBackedClassDef classDef, int previousMethodIndex, @Nonnull AnnotationsDirectory.AnnotationIterator methodAnnotationIterator, @Nonnull AnnotationsDirectory.AnnotationIterator paramaterAnnotationIterator) { this.dexFile = reader.dexBuf; this.classDef = classDef; startOffset = reader.getOffset(); // 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 methodIndexDiff = reader.readLargeUleb128(); this.methodIndex = methodIndexDiff + previousMethodIndex; this.accessFlags = reader.readSmallUleb128(); this.codeOffset = reader.readSmallUleb128(); this.methodAnnotationSetOffset = methodAnnotationIterator.seekTo(methodIndex); this.parameterAnnotationSetListOffset = paramaterAnnotationIterator.seekTo(methodIndex); }
annotationsDirectory.getMethodAnnotationIterator(); final AnnotationsDirectory.AnnotationIterator parameterAnnotationIterator = annotationsDirectory.getParameterAnnotationIterator();
@Nonnull @Override public Set<? extends DexBackedAnnotation> readItem(int index) { int annotationSetOffset = dexFile.readSmallUint(annotationSetListOffset + 4 + index * 4); return getAnnotations(dexFile, annotationSetOffset); }
if (!AnnotationsDirectory.EMPTY.equals(directory)) { size += 4 * 4; //4 uints in annotations_directory_item Set<? extends DexBackedAnnotation> classAnnotations = directory.getClassAnnotations(); if (!classAnnotations.isEmpty()) { size += 4; //uint for size