Search in sources :

Example 1 with NotAnOdexFile

use of org.jf.dexlib2.dexbacked.DexBackedOdexFile.NotAnOdexFile in project smali by JesusFreke.

the class DexUtil method verifyOdexHeader.

/**
     * 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);
}
Also used : NotAnOdexFile(org.jf.dexlib2.dexbacked.DexBackedOdexFile.NotAnOdexFile) EOFException(java.io.EOFException)

Aggregations

EOFException (java.io.EOFException)1 NotAnOdexFile (org.jf.dexlib2.dexbacked.DexBackedOdexFile.NotAnOdexFile)1