private void writeMethods(@Nonnull DexDataWriter writer) throws IOException { methodSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends MethodRefKey, Integer>> methodEntries = Lists.newArrayList(methodSection.getItems()); Collections.sort(methodEntries, DexWriter.<MethodRefKey>comparableKeyComparator()); for (Map.Entry<? extends MethodRefKey, Integer> entry: methodEntries) { entry.setValue(index++); MethodRefKey key = entry.getKey(); writer.writeUshort(typeSection.getItemIndex(methodSection.getDefiningClass(key))); writer.writeUshort(protoSection.getItemIndex(methodSection.getPrototype(key))); writer.writeInt(stringSection.getItemIndex(methodSection.getName(key))); } }
case MethodHandleType.INVOKE_DIRECT: case MethodHandleType.INVOKE_INTERFACE: memberIndex = methodSection.getItemIndex( methodHandleSection.getMethodReference(methodHandleReference)); break;
private void writeEncodedMethods(@Nonnull DexDataWriter writer, @Nonnull Collection<? extends MethodKey> methods) throws IOException { int prevIndex = 0; for (MethodKey key: methods) { int index = methodSection.getMethodIndex(key); writer.writeUleb128(index-prevIndex); writer.writeUleb128(classSection.getMethodAccessFlags(key)); writer.writeUleb128(classSection.getCodeItemOffset(key)); prevIndex = index; } }
@Nonnull public List<String> getMethodReferences() { List<String> methodReferences = Lists.newArrayList(); for (Entry<? extends MethodRefKey, Integer> methodReference: methodSection.getItems()) { methodReferences.add(ReferenceUtil.getMethodDescriptor(methodReference.getKey())); } return methodReferences; }
protoSection.getParameters(methodSection.getPrototype(methodKey)));
private int getDataSectionOffset() { return HeaderItem.ITEM_SIZE + stringSection.getItemCount() * StringIdItem.ITEM_SIZE + typeSection.getItemCount() * TypeIdItem.ITEM_SIZE + protoSection.getItemCount() * ProtoIdItem.ITEM_SIZE + fieldSection.getItemCount() * FieldIdItem.ITEM_SIZE + methodSection.getItemCount() * MethodIdItem.ITEM_SIZE + classSection.getItemCount() * ClassDefItem.ITEM_SIZE + callSiteSection.getItemCount() * CallSiteIdItem.ITEM_SIZE + methodHandleSection.getItemCount() * MethodHandleItem.ITEM_SIZE; }
} catch (RuntimeException ex) { throw new ExceptionWithContext(ex, "Exception occurred while writing code_item for method %s", methodSection.getMethodReference(methodKey));
numItems++; if (methodSection.getItems().size() > 0) { numItems++;
protoSection.getParameters(methodSection.getPrototype(methodKey)));
private int getDataSectionOffset() { return HeaderItem.ITEM_SIZE + stringSection.getItemCount() * StringIdItem.ITEM_SIZE + typeSection.getItemCount() * TypeIdItem.ITEM_SIZE + protoSection.getItemCount() * ProtoIdItem.ITEM_SIZE + fieldSection.getItemCount() * FieldIdItem.ITEM_SIZE + methodSection.getItemCount() * MethodIdItem.ITEM_SIZE + classSection.getItemCount() * ClassDefItem.ITEM_SIZE + callSiteSection.getItemCount() * CallSiteIdItem.ITEM_SIZE + methodHandleSection.getItemCount() * MethodHandleItem.ITEM_SIZE; }
} catch (RuntimeException ex) { throw new ExceptionWithContext(ex, "Exception occurred while writing code_item for method %s", methodSection.getMethodReference(methodKey));
private void writeMethods(@Nonnull DexDataWriter writer) throws IOException { methodSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends MethodRefKey, Integer>> methodEntries = Lists.newArrayList(methodSection.getItems()); Collections.sort(methodEntries, DexWriter.<MethodRefKey>comparableKeyComparator()); for (Map.Entry<? extends MethodRefKey, Integer> entry: methodEntries) { entry.setValue(index++); MethodRefKey key = entry.getKey(); writer.writeUshort(typeSection.getItemIndex(methodSection.getDefiningClass(key))); writer.writeUshort(protoSection.getItemIndex(methodSection.getPrototype(key))); writer.writeInt(stringSection.getItemIndex(methodSection.getName(key))); } }
private void writeHeader(@Nonnull DexDataWriter writer, int dataOffset, int fileSize) throws IOException { // Write the appropriate header. writer.write(HeaderItem.getMagicForApi(opcodes.api)); // checksum placeholder writer.writeInt(0); // signature placeholder writer.write(new byte[20]); writer.writeInt(fileSize); writer.writeInt(HeaderItem.ITEM_SIZE); writer.writeInt(HeaderItem.LITTLE_ENDIAN_TAG); // link writer.writeInt(0); writer.writeInt(0); // map writer.writeInt(mapSectionOffset); // index sections writeSectionInfo(writer, stringSection.getItems().size(), stringIndexSectionOffset); writeSectionInfo(writer, typeSection.getItems().size(), typeSectionOffset); writeSectionInfo(writer, protoSection.getItems().size(), protoSectionOffset); writeSectionInfo(writer, fieldSection.getItems().size(), fieldSectionOffset); writeSectionInfo(writer, methodSection.getItems().size(), methodSectionOffset); writeSectionInfo(writer, classSection.getItems().size(), classIndexSectionOffset); // data section writer.writeInt(fileSize - dataOffset); writer.writeInt(dataOffset); }
public void writeMethod(@Nonnull MethodRefKey value) throws IOException { writer.writeEncodedUint(ValueType.METHOD, methodSection.getItemIndex(value)); }
if (methodAnnotationsKey != null) { methodAnnotations++; tempBuffer.putInt(methodSection.getMethodIndex(method)); tempBuffer.putInt(annotationSetSection.getItemOffset(methodAnnotationsKey)); if (offset != DexWriter.NO_OFFSET) { parameterAnnotations++; tempBuffer.putInt(methodSection.getMethodIndex(method)); tempBuffer.putInt(offset);
protoSection.getParameters(methodSection.getPrototype(methodKey)));
private void writeMethods(@Nonnull DexDataWriter writer) throws IOException { methodSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends MethodRefKey, Integer>> methodEntries = Lists.newArrayList(methodSection.getItems()); Collections.sort(methodEntries, DexWriter.<MethodRefKey>comparableKeyComparator()); for (Map.Entry<? extends MethodRefKey, Integer> entry: methodEntries) { entry.setValue(index++); MethodRefKey key = entry.getKey(); writer.writeUshort(typeSection.getItemIndex(methodSection.getDefiningClass(key))); writer.writeUshort(protoSection.getItemIndex(methodSection.getPrototype(key))); writer.writeInt(stringSection.getItemIndex(methodSection.getName(key))); } }
writeMapItem(writer, ItemType.PROTO_ID_ITEM, protoSection.getItems().size(), protoSectionOffset); writeMapItem(writer, ItemType.FIELD_ID_ITEM, fieldSection.getItems().size(), fieldSectionOffset); writeMapItem(writer, ItemType.METHOD_ID_ITEM, methodSection.getItems().size(), methodSectionOffset); writeMapItem(writer, ItemType.CLASS_DEF_ITEM, classSection.getItems().size(), classIndexSectionOffset); writeMapItem(writer, ItemType.CALL_SITE_ID_ITEM, callSiteSection.getItems().size(), callSiteSectionOffset);
public void writeMethod(@Nonnull MethodRefKey value) throws IOException { writer.writeEncodedUint(ValueType.METHOD, methodSection.getItemIndex(value)); }
private void writeEncodedMethods(@Nonnull DexDataWriter writer, @Nonnull Collection<? extends MethodKey> methods) throws IOException { int prevIndex = 0; for (MethodKey key: methods) { int index = methodSection.getMethodIndex(key); writer.writeUleb128(index-prevIndex); writer.writeUleb128(classSection.getMethodAccessFlags(key)); writer.writeUleb128(classSection.getCodeItemOffset(key)); prevIndex = index; } }