/** * 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); }
/** * 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); }
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); } }