@Nonnull public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is) throws IOException { DexUtil.verifyOdexHeader(is); is.reset(); byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE]; ByteStreams.readFully(is, odexBuf); int dexOffset = OdexHeaderItem.getDexOffset(odexBuf); if (dexOffset > OdexHeaderItem.ITEM_SIZE) { ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE); } byte[] dexBuf = ByteStreams.toByteArray(is); return new DexBackedOdexFile(opcodes, odexBuf, dexBuf); }
/** * Reads in the odex header from the given input stream and verifies that it is valid and a supported version * * The inputStream must support mark(), and will be reset to initial position upon exiting the method * * @param inputStream An input stream that is positioned at an odex header * @throws NotAnOdexFile If the file is not an odex file * @throws UnsupportedFile If the odex header is valid, but is an unsupported version */ public static void verifyOdexHeader(@Nonnull InputStream inputStream) throws IOException { if (!inputStream.markSupported()) { throw new IllegalArgumentException("InputStream must support mark"); } inputStream.mark(8); byte[] partialHeader = new byte[8]; try { ByteStreams.readFully(inputStream, partialHeader); } catch (EOFException ex) { throw new NotAnOdexFile("File is too short"); } finally { inputStream.reset(); } verifyOdexHeader(partialHeader, 0); }
@Nonnull public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is) throws IOException { DexUtil.verifyOdexHeader(is); is.reset(); byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE]; ByteStreams.readFully(is, odexBuf); int dexOffset = OdexHeaderItem.getDexOffset(odexBuf); if (dexOffset > OdexHeaderItem.ITEM_SIZE) { ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE); } byte[] dexBuf = ByteStreams.toByteArray(is); return new DexBackedOdexFile(opcodes, odexBuf, dexBuf); }
/** * Reads in the odex header from the given input stream and verifies that it is valid and a supported version * * The inputStream must support mark(), and will be reset to initial position upon exiting the method * * @param inputStream An input stream that is positioned at an odex header * @throws NotAnOdexFile If the file is not an odex file * @throws UnsupportedFile If the odex header is valid, but is an unsupported version */ public static void verifyOdexHeader(@Nonnull InputStream inputStream) throws IOException { if (!inputStream.markSupported()) { throw new IllegalArgumentException("InputStream must support mark"); } inputStream.mark(8); byte[] partialHeader = new byte[8]; try { ByteStreams.readFully(inputStream, partialHeader); } catch (EOFException ex) { throw new NotAnOdexFile("File is too short"); } finally { inputStream.reset(); } verifyOdexHeader(partialHeader, 0); }