public RawDexFile(@Nonnull Opcodes opcodes, @Nonnull BaseDexBuffer buf) { super(opcodes, buf); this.headerItem = new HeaderItem(this); }
/** * Gets the dex version from a dex header * * @param buf A byte array containing at least the first 7 bytes of a dex file * @param offset The offset within the buffer to the beginning of the dex header * @return The dex version if the header is valid or -1 if the header is invalid */ public static int getVersion(byte[] buf, int offset) { if (!verifyMagic(buf, offset)) { return -1; } return getVersionUnchecked(buf, offset); }
/** * Get the highest magic number supported by Android for this api level. * @return The dex file magic number */ public static byte[] getMagicForApi(int api) { return getMagicForDexVersion(VersionMap.mapApiToDexVersion(api)); }
int dexVersion = HeaderItem.getVersion(buf, offset); if (dexVersion == -1) { StringBuilder sb = new StringBuilder("Not a valid dex magic value:"); if (!HeaderItem.isSupportedDexVersion(dexVersion)) { throw new UnsupportedFile(String.format("Dex version %03d is not supported", dexVersion)); int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new UnsupportedFile("Big endian dex files are not supported");
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) { if (!HeaderItem.verifyMagic(buf, offset)) { StringBuilder sb = new StringBuilder("Invalid magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotADexFile(sb.toString()); } int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new ExceptionWithContext("Big endian dex files are not currently supported"); } if (endian != HeaderItem.LITTLE_ENDIAN_TAG) { throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian); } }
protected DexBackedDexFile(@Nullable Opcodes opcodes, @Nonnull byte[] buf, int offset, boolean verifyMagic) { super(buf, offset); int dexVersion; if (verifyMagic) { dexVersion = DexUtil.verifyDexHeader(buf, offset); } else { dexVersion = HeaderItem.getVersion(buf, offset); } if (opcodes == null) { this.opcodes = Opcodes.forDexVersion(dexVersion); } else { this.opcodes = opcodes; } stringCount = readSmallUint(HeaderItem.STRING_COUNT_OFFSET); stringStartOffset = readSmallUint(HeaderItem.STRING_START_OFFSET); typeCount = readSmallUint(HeaderItem.TYPE_COUNT_OFFSET); typeStartOffset = readSmallUint(HeaderItem.TYPE_START_OFFSET); protoCount = readSmallUint(HeaderItem.PROTO_COUNT_OFFSET); protoStartOffset = readSmallUint(HeaderItem.PROTO_START_OFFSET); fieldCount = readSmallUint(HeaderItem.FIELD_COUNT_OFFSET); fieldStartOffset = readSmallUint(HeaderItem.FIELD_START_OFFSET); methodCount = readSmallUint(HeaderItem.METHOD_COUNT_OFFSET); methodStartOffset = readSmallUint(HeaderItem.METHOD_START_OFFSET); classCount = readSmallUint(HeaderItem.CLASS_COUNT_OFFSET); classStartOffset = readSmallUint(HeaderItem.CLASS_START_OFFSET); mapOffset = readSmallUint(HeaderItem.MAP_OFFSET); }
switch (mapItem.getType()) { case ItemType.HEADER_ITEM: annotators.put(mapItem.getType(), HeaderItem.makeAnnotator(this, mapItem)); break; case ItemType.STRING_ID_ITEM:
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); }
int dexVersion = HeaderItem.getVersion(buf, offset); if (dexVersion == -1) { StringBuilder sb = new StringBuilder("Not a valid dex magic value:"); if (!HeaderItem.isSupportedDexVersion(dexVersion)) { throw new UnsupportedFile(String.format("Dex version %03d is not supported", dexVersion)); int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new UnsupportedFile("Big endian dex files are not supported");
public static boolean verifyMagic(byte[] buf, int offset) { // verifies the magic value return getVersion(buf, offset) != 0; }
switch (mapItem.getType()) { case ItemType.HEADER_ITEM: annotators.put(mapItem.getType(), HeaderItem.makeAnnotator(this, mapItem)); break; case ItemType.STRING_ID_ITEM:
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 RawDexFile(@Nonnull Opcodes opcodes, @Nonnull byte[] buf) { super(opcodes, buf); this.headerItem = new HeaderItem(this); }
/** * Gets the dex version from a dex header * * @param buf A byte array containing at least the first 7 bytes of a dex file * @param offset The offset within the buffer to the beginning of the dex header * @return The dex version if the header is valid or -1 if the header is invalid */ public static int getVersion(byte[] buf, int offset) { if (!verifyMagic(buf, offset)) { return -1; } return getVersionUnchecked(buf, offset); }
protected DexBackedDexFile(@Nullable Opcodes opcodes, @Nonnull byte[] buf, int offset, boolean verifyMagic) { super(buf, offset); int dexVersion; if (verifyMagic) { dexVersion = DexUtil.verifyDexHeader(buf, offset); } else { dexVersion = HeaderItem.getVersion(buf, offset); } if (opcodes == null) { this.opcodes = Opcodes.forDexVersion(dexVersion); } else { this.opcodes = opcodes; } stringCount = readSmallUint(HeaderItem.STRING_COUNT_OFFSET); stringStartOffset = readSmallUint(HeaderItem.STRING_START_OFFSET); typeCount = readSmallUint(HeaderItem.TYPE_COUNT_OFFSET); typeStartOffset = readSmallUint(HeaderItem.TYPE_START_OFFSET); protoCount = readSmallUint(HeaderItem.PROTO_COUNT_OFFSET); protoStartOffset = readSmallUint(HeaderItem.PROTO_START_OFFSET); fieldCount = readSmallUint(HeaderItem.FIELD_COUNT_OFFSET); fieldStartOffset = readSmallUint(HeaderItem.FIELD_START_OFFSET); methodCount = readSmallUint(HeaderItem.METHOD_COUNT_OFFSET); methodStartOffset = readSmallUint(HeaderItem.METHOD_START_OFFSET); classCount = readSmallUint(HeaderItem.CLASS_COUNT_OFFSET); classStartOffset = readSmallUint(HeaderItem.CLASS_START_OFFSET); mapOffset = readSmallUint(HeaderItem.MAP_OFFSET); }
switch (mapItem.getType()) { case ItemType.HEADER_ITEM: annotators.put(mapItem.getType(), HeaderItem.makeAnnotator(this, mapItem)); break; case ItemType.STRING_ID_ITEM:
/** * Get the highest magic number supported by Android for this api level. * @return The dex file magic number */ public static byte[] getMagicForApi(int api) { return getMagicForDexVersion(VersionMap.mapApiToDexVersion(api)); }
public RawDexFile(@Nonnull Opcodes opcodes, @Nonnull BaseDexBuffer buf) { super(opcodes, buf); this.headerItem = new HeaderItem(this); }
public RawDexFile(@Nonnull Opcodes opcodes, @Nonnull BaseDexBuffer buf) { super(opcodes, buf); this.headerItem = new HeaderItem(this); }
public RawDexFile(@Nonnull Opcodes opcodes, @Nonnull byte[] buf) { super(opcodes, buf); this.headerItem = new HeaderItem(this); }