@Nonnull public List<String> getDependencies() { final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf); final int dependencyOffset = OdexHeaderItem.getDependenciesOffset(odexBuf) - dexOffset; BaseDexBuffer buf = new BaseDexBuffer(this.buf); int dependencyCount = buf.readInt(dependencyOffset + DEPENDENCY_COUNT_OFFSET); return new VariableSizeList<String>(this, dependencyOffset + DEPENDENCY_START_OFFSET, dependencyCount) { @Override protected String readNextItem(@Nonnull DexReader reader, int index) { int length = reader.readInt(); int offset = reader.getOffset(); reader.moveRelative(length + 20); try { return new String(DexBackedOdexFile.this.buf, offset, length-1, "US-ASCII"); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } } }; }
public int getOdexVersion() { return OdexHeaderItem.getVersion(odexBuf, 0); }
/** * Gets the dex version from an odex header * * @param buf A byte array containing at least the first 7 bytes of an odex file * @param offset The offset within the buffer to the beginning of the odex header * @return The odex 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); }
/** * Verifies that the odex header is valid and a supported version * * @param buf A byte array containing at least the first 8 bytes of an odex file * @param offset The offset within the array to the odex header * @throws NotAnOdexFile If the file is not an odex file * @throws UnsupportedFile If the odex header is valid, but uses unsupported functionality */ public static void verifyOdexHeader(@Nonnull byte[] buf, int offset) { int odexVersion = OdexHeaderItem.getVersion(buf, offset); if (odexVersion == -1) { StringBuilder sb = new StringBuilder("Not a valid odex magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotAnOdexFile(sb.toString()); } if (!OdexHeaderItem.isSupportedOdexVersion(odexVersion)) { throw new UnsupportedFile(String.format("Odex version %03d is not supported", odexVersion)); } }
@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); }
private static void verifyMagic(byte[] buf) { if (!OdexHeaderItem.verifyMagic(buf)) { StringBuilder sb = new StringBuilder("Invalid magic value:"); for (int i = 0; i < 8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotAnOdexFile(sb.toString()); } }
/** * Gets the dex version from an odex header * * @param buf A byte array containing at least the first 7 bytes of an odex file * @param offset The offset within the buffer to the beginning of the odex header * @return The odex 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); }
/** * Verifies that the odex header is valid and a supported version * * @param buf A byte array containing at least the first 8 bytes of an odex file * @param offset The offset within the array to the odex header * @throws NotAnOdexFile If the file is not an odex file * @throws UnsupportedFile If the odex header is valid, but uses unsupported functionality */ public static void verifyOdexHeader(@Nonnull byte[] buf, int offset) { int odexVersion = OdexHeaderItem.getVersion(buf, offset); if (odexVersion == -1) { StringBuilder sb = new StringBuilder("Not a valid odex magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotAnOdexFile(sb.toString()); } if (!OdexHeaderItem.isSupportedOdexVersion(odexVersion)) { throw new UnsupportedFile(String.format("Odex version %03d is not supported", odexVersion)); } }
@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); }
@Nonnull public List<String> getDependencies() { final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf); final int dependencyOffset = OdexHeaderItem.getDependenciesOffset(odexBuf) - dexOffset; BaseDexBuffer buf = new BaseDexBuffer(this.buf); int dependencyCount = buf.readInt(dependencyOffset + DEPENDENCY_COUNT_OFFSET); return new VariableSizeList<String>(this, dependencyOffset + DEPENDENCY_START_OFFSET, dependencyCount) { @Override protected String readNextItem(@Nonnull DexReader reader, int index) { int length = reader.readInt(); int offset = reader.getOffset(); reader.moveRelative(length + 20); try { return new String(DexBackedOdexFile.this.buf, offset, length-1, "US-ASCII"); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } } }; }
public static boolean verifyMagic(byte[] buf) { // verifies the magic value return getVersion(buf) != 0; }
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is) throws IOException { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must support mark"); } is.mark(8); byte[] partialHeader = new byte[8]; try { ByteStreams.readFully(is, partialHeader); } catch (EOFException ex) { throw new NotADexFile("File is too short"); } finally { is.reset(); } verifyMagic(partialHeader); 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); }
public List<String> getDependencies() { if (this.getReader() == null) { final int dexOffset = OdexHeaderItem.getDexOffset(odexBuf); final int dependencyOffset = OdexHeaderItem .getDependenciesOffset(odexBuf) - dexOffset;
public int getOdexVersion() { return OdexHeaderItem.getVersion(odexBuf); }
public int getOdexVersion() { return OdexHeaderItem.getVersion(odexBuf, 0); }