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); } }
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); }
writer.write(0);
private void writeSpecialOpcode(int lineDelta, int addressDelta) throws IOException { writer.write((byte)(FIRST_SPECIAL + (addressDelta * LINE_RANGE) + (lineDelta - LINE_BASE))); currentLine += lineDelta; currentAddress += addressDelta; } }
protected void writeRightZeroExtendedInt(int valueType, int value) throws IOException { int index = 3; do { tempBuf[index--] = (byte)((value & 0xFF000000) >>> 24); value <<= 8; } while (value != 0); int firstElement = index+1; int encodedLength = 4-firstElement; writeEncodedValueHeader(valueType, encodedLength - 1); write(tempBuf, firstElement, encodedLength); }
public void write(@Nonnull Instruction4rcc instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterCount()); writer.writeUshort(getReferenceIndex(instruction)); writer.writeUshort(instruction.getStartRegister()); writer.writeUshort(getReference2Index(instruction)); } catch (IOException ex) { throw new RuntimeException(ex); } }
private void writeAdvancePC(int address) throws IOException { int addressDelta = address - currentAddress; if (addressDelta > 0) { writer.write(1); writer.writeUleb128(addressDelta); currentAddress = address; } /*else if (addressDelta < 0) { throw new ExceptionWithContext("debug info items must have non-decreasing code addresses"); }*/ }
writer.writeInt(methodAnnotations); writer.writeInt(parameterAnnotations); writer.write(tempBuffer.array(), 0, tempBuffer.position());
public void write(@Nonnull Instruction3rmi instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(instruction.getRegisterCount()); writer.writeUshort(instruction.getInlineIndex()); writer.writeUshort(instruction.getStartRegister()); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void writeEndLocal(int codeAddress, int register) throws IOException { writeAdvancePC(codeAddress); writer.write(DebugItemType.END_LOCAL); writer.writeUleb128(register); }
public void write(@Nonnull Instruction22cs instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(packNibbles(instruction.getRegisterA(), instruction.getRegisterB())); writer.writeUshort(instruction.getFieldOffset()); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void writeUbyte(int value) throws IOException { if (value < 0 || value > 0xFF) { throw new ExceptionWithContext("Unsigned byte value out of range: %d", value); } write(value); }
public void write(@Nonnull Instruction45cc instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(packNibbles(instruction.getRegisterG(), instruction.getRegisterCount())); writer.writeUshort(getReferenceIndex(instruction)); writer.write(packNibbles(instruction.getRegisterC(), instruction.getRegisterD())); writer.write(packNibbles(instruction.getRegisterE(), instruction.getRegisterF())); writer.writeUshort(getReference2Index(instruction)); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void align() throws IOException { int zeros = (-getPosition()) & 3; if (zeros > 0) { write(zeroBuf, 0, zeros); } }
public void write(@Nonnull Instruction35c instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(packNibbles(instruction.getRegisterG(), instruction.getRegisterCount())); writer.writeUshort(getReferenceIndex(instruction)); writer.write(packNibbles(instruction.getRegisterC(), instruction.getRegisterD())); writer.write(packNibbles(instruction.getRegisterE(), instruction.getRegisterF())); } catch (IOException ex) { throw new RuntimeException(ex); } }
public void write(@Nonnull Instruction35mi instruction) { try { writer.write(getOpcodeValue(instruction.getOpcode())); writer.write(packNibbles(instruction.getRegisterG(), instruction.getRegisterCount())); writer.writeUshort(instruction.getInlineIndex()); writer.write(packNibbles(instruction.getRegisterC(), instruction.getRegisterD())); writer.write(packNibbles(instruction.getRegisterE(), instruction.getRegisterF())); } catch (IOException ex) { throw new RuntimeException(ex); } }