Esempio n. 1
0
  /** {@inheritDoc} */
  protected void readItem(Input in, ReadContext readContext) {
    staticFields = new EncodedField[in.readUnsignedLeb128()];
    instanceFields = new EncodedField[in.readUnsignedLeb128()];
    directMethods = new EncodedMethod[in.readUnsignedLeb128()];
    virtualMethods = new EncodedMethod[in.readUnsignedLeb128()];

    EncodedField previousEncodedField = null;
    for (int i = 0, len = staticFields.length; i < len; i++) {
      try {
        staticFields[i] =
            previousEncodedField = new EncodedField(dexFile, in, previousEncodedField);
      } catch (Exception ex) {
        throw ExceptionWithContext.withContext(
            ex, "Error while reading static field at index " + i);
      }
    }

    previousEncodedField = null;
    for (int i = 0, len = instanceFields.length; i < len; i++) {
      try {
        instanceFields[i] =
            previousEncodedField = new EncodedField(dexFile, in, previousEncodedField);
      } catch (Exception ex) {
        throw ExceptionWithContext.withContext(
            ex, "Error while reading instance field at index " + i);
      }
    }

    EncodedMethod previousEncodedMethod = null;
    for (int i = 0, len = directMethods.length; i < len; i++) {
      try {
        directMethods[i] =
            previousEncodedMethod =
                new EncodedMethod(dexFile, readContext, in, previousEncodedMethod);
      } catch (Exception ex) {
        throw ExceptionWithContext.withContext(
            ex, "Error while reading direct method at index " + i);
      }
    }

    previousEncodedMethod = null;
    for (int i = 0, len = virtualMethods.length; i < len; i++) {
      try {
        virtualMethods[i] =
            previousEncodedMethod =
                new EncodedMethod(dexFile, readContext, in, previousEncodedMethod);
      } catch (Exception ex) {
        throw ExceptionWithContext.withContext(
            ex, "Error while reading virtual method at index " + i);
      }
    }
  }
  /** {@inheritDoc} */
  protected void readItem(Input in, ReadContext readContext) {
    classAnnotations =
        (AnnotationSetItem)
            readContext.getOptionalOffsettedItemByOffset(
                ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());

    int fieldAnnotationCount = in.readInt();
    if (fieldAnnotationCount > 0) {
      fieldAnnotations = new FieldAnnotation[fieldAnnotationCount];
    } else {
      fieldAnnotations = null;
    }

    int methodAnnotationCount = in.readInt();
    if (methodAnnotationCount > 0) {
      methodAnnotations = new MethodAnnotation[methodAnnotationCount];
    } else {
      methodAnnotations = null;
    }

    int parameterAnnotationCount = in.readInt();
    if (parameterAnnotationCount > 0) {
      parameterAnnotations = new ParameterAnnotation[parameterAnnotationCount];
    } else {
      parameterAnnotations = null;
    }

    if (fieldAnnotations != null) {
      for (int i = 0; i < fieldAnnotations.length; i++) {
        try {
          FieldIdItem fieldIdItem = dexFile.FieldIdsSection.getItemByIndex(in.readInt());
          AnnotationSetItem fieldAnnotationSet =
              (AnnotationSetItem)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());
          fieldAnnotations[i] = new FieldAnnotation(fieldIdItem, fieldAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading FieldAnnotation at index " + i);
        }
      }
    }

    if (methodAnnotations != null) {
      for (int i = 0; i < methodAnnotations.length; i++) {
        try {
          MethodIdItem methodIdItem = dexFile.MethodIdsSection.getItemByIndex(in.readInt());
          AnnotationSetItem methodAnnotationSet =
              (AnnotationSetItem)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_ITEM, in.readInt());
          methodAnnotations[i] = new MethodAnnotation(methodIdItem, methodAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading MethodAnnotation at index " + i);
        }
      }
    }

    if (parameterAnnotations != null) {
      for (int i = 0; i < parameterAnnotations.length; i++) {
        try {
          MethodIdItem methodIdItem = dexFile.MethodIdsSection.getItemByIndex(in.readInt());
          AnnotationSetRefList paramaterAnnotationSet =
              (AnnotationSetRefList)
                  readContext.getOffsettedItemByOffset(
                      ItemType.TYPE_ANNOTATION_SET_REF_LIST, in.readInt());
          parameterAnnotations[i] = new ParameterAnnotation(methodIdItem, paramaterAnnotationSet);
        } catch (Exception ex) {
          throw ExceptionWithContext.withContext(
              ex, "Error occured while reading ParameterAnnotation at index " + i);
        }
      }
    }
  }