예제 #1
0
 /**
  * Constructs a new <code>EncodedMethod</code> with the given values
  *
  * @param method The <code>MethodIdItem</code> that this <code>EncodedMethod</code> is
  *     associated with
  * @param accessFlags The access flags for this method
  * @param codeItem The <code>CodeItem</code> containing the code for this method, or null if
  *     there is no code for this method (i.e. an abstract method)
  */
 public EncodedMethod(MethodIdItem method, int accessFlags, CodeItem codeItem) {
   this.method = method;
   this.accessFlags = accessFlags;
   this.codeItem = codeItem;
   if (codeItem != null) {
     codeItem.setParent(this);
   }
 }
예제 #2
0
    /**
     * Calculates the size of this <code>EncodedMethod</code> and returns the offset immediately
     * following it
     *
     * @param offset the offset of this <code>EncodedMethod</code> in the <code>DexFile</code>
     * @param previousEncodedMethod The previous <code>EncodedMethod</code> in the list containing
     *     this <code>EncodedMethod</code>.
     * @return the offset immediately following this <code>EncodedField</code>
     */
    private int place(int offset, EncodedMethod previousEncodedMethod) {
      int previousIndex =
          previousEncodedMethod == null ? 0 : previousEncodedMethod.method.getIndex();

      offset += Leb128Utils.unsignedLeb128Size(method.getIndex() - previousIndex);
      offset += Leb128Utils.unsignedLeb128Size(accessFlags);
      offset += codeItem == null ? 1 : Leb128Utils.unsignedLeb128Size(codeItem.getOffset());
      return offset;
    }
예제 #3
0
    /**
     * Writes the <code>EncodedMethod</code> to the given <code>AnnotatedOutput</code> object
     *
     * @param out the <code>AnnotatedOutput</code> object to write to
     * @param previousEncodedMethod The previous <code>EncodedMethod</code> in the list containing
     *     this <code>EncodedMethod</code>.
     */
    private void writeTo(AnnotatedOutput out, EncodedMethod previousEncodedMethod) {
      int previousIndex =
          previousEncodedMethod == null ? 0 : previousEncodedMethod.method.getIndex();

      if (out.annotates()) {
        out.annotate("method: " + method.getMethodString());
        out.writeUnsignedLeb128(method.getIndex() - previousIndex);
        out.annotate("access_flags: " + AccessFlags.formatAccessFlagsForMethod(accessFlags));
        out.writeUnsignedLeb128(accessFlags);
        if (codeItem != null) {
          out.annotate("code_off: 0x" + Integer.toHexString(codeItem.getOffset()));
          out.writeUnsignedLeb128(codeItem.getOffset());
        } else {
          out.annotate("code_off: 0x0");
          out.writeUnsignedLeb128(0);
        }
      } else {
        out.writeUnsignedLeb128(method.getIndex() - previousIndex);
        out.writeUnsignedLeb128(accessFlags);
        out.writeUnsignedLeb128(codeItem == null ? 0 : codeItem.getOffset());
      }
    }
예제 #4
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);
   }
 }