private void writeTypes(@Nonnull DexDataWriter writer) throws IOException { typeSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends TypeKey, Integer>> typeEntries = Lists.newArrayList(typeSection.getItems()); Collections.sort(typeEntries, toStringKeyComparator); for (Map.Entry<? extends TypeKey, Integer> entry : typeEntries) { entry.setValue(index++); writer.writeInt(stringSection.getItemIndex(typeSection.getString(entry.getKey()))); } }
private void writeStrings(@Nonnull DexDataWriter indexWriter, @Nonnull DexDataWriter offsetWriter) throws IOException { stringIndexSectionOffset = indexWriter.getPosition(); stringDataSectionOffset = offsetWriter.getPosition(); int index = 0; List<Entry<? extends StringKey, Integer>> stringEntries = Lists.newArrayList(stringSection.getItems()); Collections.sort(stringEntries, toStringKeyComparator); for (Map.Entry<? extends StringKey, Integer> entry: stringEntries) { entry.setValue(index++); indexWriter.writeInt(offsetWriter.getPosition()); String stringValue = entry.getKey().toString(); offsetWriter.writeUleb128(stringValue.length()); offsetWriter.writeString(stringValue); offsetWriter.write(0); } }
writer.writeUleb128(stringSection.getNullableItemIndex(parameterName) + 1);
Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey); if (instructions != null && stringSection.hasJumboIndexes()) { boolean needsFix = false; for (Instruction instruction: instructions) { if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { needsFix = true;
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; }
Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey); if (instructions != null && stringSection.hasJumboIndexes()) { boolean needsFix = false; for (Instruction instruction: instructions) { if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { needsFix = true;
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; }
private void fixInstructions(@Nonnull MutableMethodImplementation methodImplementation) { List<? extends Instruction> instructions = methodImplementation.getInstructions(); for (int i=0; i<instructions.size(); i++) { Instruction instruction = instructions.get(i); if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { methodImplementation.replaceInstruction(i, new BuilderInstruction31c(Opcode.CONST_STRING_JUMBO, ((OneRegisterInstruction)instruction).getRegisterA(), ((ReferenceInstruction)instruction).getReference())); } } } }
if (stringSection.getItems().size() > 0) { numItems += 2; // index and data
indexWriter.writeInt(typeSection.getNullableItemIndex(classSection.getSuperclass(key))); indexWriter.writeInt(typeListSection.getNullableItemOffset(classSection.getInterfaces(key))); indexWriter.writeInt(stringSection.getNullableItemIndex(classSection.getSourceFile(key))); indexWriter.writeInt(classSection.getAnnotationDirectoryOffset(key));
Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey); if (instructions != null && stringSection.hasJumboIndexes()) { boolean needsFix = false; for (Instruction instruction: instructions) { if (instruction.getOpcode() == Opcode.CONST_STRING) { if (stringSection.getItemIndex( (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) { needsFix = true;
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.STRING_ID_ITEM, stringSection.getItems().size(), stringIndexSectionOffset); writeMapItem(writer, ItemType.TYPE_ID_ITEM, typeSection.getItems().size(), typeSectionOffset); writeMapItem(writer, ItemType.PROTO_ID_ITEM, protoSection.getItems().size(), protoSectionOffset); writeMapItem(writer, ItemType.STRING_DATA_ITEM, stringSection.getItems().size(), stringDataSectionOffset); writeMapItem(writer, ItemType.TYPE_LIST, typeListSection.getItems().size(), typeListSectionOffset); writeMapItem(writer, ItemType.ENCODED_ARRAY_ITEM, encodedArraySection.getItems().size(),
public void writeSetSourceFile(int codeAddress, @Nullable StringKey sourceFile) throws IOException { writeAdvancePC(codeAddress); writer.write(DebugItemType.SET_SOURCE_FILE); writer.writeUleb128(stringSection.getNullableItemIndex(sourceFile) + 1); }
private void writeProtos(@Nonnull DexDataWriter writer) throws IOException { protoSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends ProtoRefKey, Integer>> protoEntries = Lists.newArrayList(protoSection.getItems()); Collections.sort(protoEntries, DexWriter.<ProtoRefKey>comparableKeyComparator()); for (Map.Entry<? extends ProtoRefKey, Integer> entry: protoEntries) { entry.setValue(index++); ProtoRefKey key = entry.getKey(); writer.writeInt(stringSection.getItemIndex(protoSection.getShorty(key))); writer.writeInt(typeSection.getItemIndex(protoSection.getReturnType(key))); writer.writeInt(typeListSection.getNullableItemOffset(protoSection.getParameters(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 writeSetSourceFile(int codeAddress, @Nullable StringKey sourceFile) throws IOException { writeAdvancePC(codeAddress); writer.write(DebugItemType.SET_SOURCE_FILE); writer.writeUleb128(stringSection.getNullableItemIndex(sourceFile) + 1); }
private void writeFields(@Nonnull DexDataWriter writer) throws IOException { fieldSectionOffset = writer.getPosition(); int index = 0; List<Map.Entry<? extends FieldRefKey, Integer>> fieldEntries = Lists.newArrayList(fieldSection.getItems()); Collections.sort(fieldEntries, DexWriter.<FieldRefKey>comparableKeyComparator()); for (Map.Entry<? extends FieldRefKey, Integer> entry: fieldEntries) { entry.setValue(index++); FieldRefKey key = entry.getKey(); writer.writeUshort(typeSection.getItemIndex(fieldSection.getDefiningClass(key))); writer.writeUshort(typeSection.getItemIndex(fieldSection.getFieldType(key))); writer.writeInt(stringSection.getItemIndex(fieldSection.getName(key))); } }
private int getDataSectionOffset() { return HeaderItem.ITEM_SIZE + stringSection.getItems().size() * StringIdItem.ITEM_SIZE + typeSection.getItems().size() * TypeIdItem.ITEM_SIZE + protoSection.getItems().size() * ProtoIdItem.ITEM_SIZE + fieldSection.getItems().size() * FieldIdItem.ITEM_SIZE + methodSection.getItems().size() * MethodIdItem.ITEM_SIZE + classSection.getItems().size() * ClassDefItem.ITEM_SIZE; }
public void writeSetSourceFile(int codeAddress, @Nullable StringKey sourceFile) throws IOException { writeAdvancePC(codeAddress); writer.write(DebugItemType.SET_SOURCE_FILE); writer.writeUleb128(stringSection.getNullableItemIndex(sourceFile) + 1); }