private static EncodedMethod findMethodByMethodIdInternal(int methodIdItemIndex, EncodedMethod[] encodedMethods) { int min = 0; int max = encodedMethods.length; while (min<max) { int index = (min+max)>>1; EncodedMethod encodedMethod = encodedMethods[index]; int encodedMethodIndex = encodedMethod.method.getIndex(); if (encodedMethodIndex == methodIdItemIndex) { return encodedMethod; } else if (encodedMethodIndex < methodIdItemIndex) { if (min == index) { break; } min = index; } else { if (max == index) { break; } max = index; } } return null; }
/** {@inheritDoc} */ public int placeValue(int offset) { return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1; }
/** * 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; }
/** * 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()); } }
/** {@inheritDoc} */ public void writeValue(AnnotatedOutput out) { byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex()); if (out.annotates()) { out.annotate(1, "value_type=" + ValueType.VALUE_METHOD.name() + ",value_arg=" + (bytes.length - 1)); out.annotate(bytes.length, "value: " + value.getMethodString()); } out.writeByte(ValueType.VALUE_METHOD.value | ((bytes.length - 1) << 5)); out.write(bytes); }
/** * 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); } }
private static EncodedMethod findMethodByMethodIdInternal(int methodIdItemIndex, EncodedMethod[] encodedMethods) { int min = 0; int max = encodedMethods.length; while (min<max) { int index = (min+max)>>1; EncodedMethod encodedMethod = encodedMethods[index]; int encodedMethodIndex = encodedMethod.method.getIndex(); if (encodedMethodIndex == methodIdItemIndex) { return encodedMethod; } else if (encodedMethodIndex < methodIdItemIndex) { if (min == index) { break; } min = index; } else { if (max == index) { break; } max = index; } } return null; }
/** * 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; }
/** {@inheritDoc} */ public int placeValue(int offset) { return offset + EncodedValueUtils.getRequiredBytesForUnsignedIntegralValue(value.getIndex()) + 1; }
/** * 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()); } }
/** {@inheritDoc} */ public void writeValue(AnnotatedOutput out) { byte[] bytes = EncodedValueUtils.encodeUnsignedIntegralValue(value.getIndex()); if (out.annotates()) { out.annotate(1, "value_type=" + ValueType.VALUE_METHOD.name() + ",value_arg=" + (bytes.length - 1)); out.annotate(bytes.length, "value: " + value.getMethodString()); } out.writeByte(ValueType.VALUE_METHOD.value | ((bytes.length - 1) << 5)); out.write(bytes); }