Пример #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);
      }
    }
  }
Пример #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);
   }
 }
Пример #3
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();
 }