Ejemplo 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);
      }
    }
  }
Ejemplo n.º 2
0
 /**
  * This is used internally to construct a new <code>EncodedMethod</code> while reading in a
  * <code>DexFile</code>
  *
  * @param dexFile The <code>DexFile</code> that is being read in
  * @param readContext a <code>ReadContext</code> object to hold information that is only needed
  *     while reading in a file
  * @param in the Input object to read the <code>EncodedMethod</code> from
  * @param previousEncodedMethod The previous <code>EncodedMethod</code> in the list containing
  *     this <code>EncodedMethod</code>.
  */
 public EncodedMethod(
     DexFile dexFile, ReadContext readContext, Input in, EncodedMethod previousEncodedMethod) {
   int previousIndex =
       previousEncodedMethod == null ? 0 : previousEncodedMethod.method.getIndex();
   method = dexFile.MethodIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
   accessFlags = in.readUnsignedLeb128();
   if (dexFile.skipInstructions()) {
     in.readUnsignedLeb128();
     codeItem = null;
   } else {
     codeItem =
         (CodeItem)
             readContext.getOptionalOffsettedItemByOffset(
                 ItemType.TYPE_CODE_ITEM, in.readUnsignedLeb128());
   }
   if (codeItem != null) {
     codeItem.setParent(this);
   }
 }
Ejemplo n.º 3
0
  public void readItems(Input in, ReadContext readContext) {
    ArrayList<T> items = this.items;

    for (int i = 0, len = items.size(); i < len; i++) {
      assert items.get(i) == null;

      in.alignTo(ItemType.ItemAlignment);

      T item = (T) ItemFactory.makeItem(ItemType, DexFile);

      items.set(i, item);
      item.readFrom(in, i, readContext);
    }

    readContext.setItemsForSection(ItemType, items);
  }
Ejemplo n.º 4
0
 /**
  * This is used internally to construct a new <code>EncodedField</code> while reading in a
  * <code>DexFile</code>
  *
  * @param dexFile The <code>DexFile</code> that is being read in
  * @param in the Input object to read the <code>EncodedField</code> from
  * @param previousEncodedField The previous <code>EncodedField</code> in the list containing
  *     this <code>EncodedField</code>.
  */
 private EncodedField(DexFile dexFile, Input in, EncodedField previousEncodedField) {
   int previousIndex = previousEncodedField == null ? 0 : previousEncodedField.field.getIndex();
   field = dexFile.FieldIdsSection.getItemByIndex(in.readUnsignedLeb128() + previousIndex);
   accessFlags = in.readUnsignedLeb128();
 }
  /** {@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);
        }
      }
    }
  }