Search in sources :

Example 1 with OatFile

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

the class ListDependenciesCommand method run.

@Override
public void run() {
    if (help || inputList == null || inputList.isEmpty()) {
        usage();
        return;
    }
    if (inputList.size() > 1) {
        System.err.println("Too many files specified");
        usage();
        return;
    }
    String input = inputList.get(0);
    InputStream inputStream = null;
    try {
        inputStream = new BufferedInputStream(new FileInputStream(input));
    } catch (FileNotFoundException ex) {
        System.err.println("Could not find file: " + input);
        System.exit(-1);
    }
    try {
        OatFile oatFile = OatFile.fromInputStream(inputStream);
        for (String entry : oatFile.getBootClassPath()) {
            System.out.println(entry);
        }
        return;
    } catch (OatFile.NotAnOatFileException ex) {
    // ignore
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    try {
        DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(Opcodes.getDefault(), inputStream);
        for (String entry : odexFile.getDependencies()) {
            System.out.println(entry);
        }
        return;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (DexBackedOdexFile.NotAnOdexFile ex) {
    // handled below
    } catch (DexBackedDexFile.NotADexFile ex) {
    // handled below
    }
    System.err.println(input + " is not an odex or oat file.");
    System.exit(-1);
}
Also used : DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) OatFile(org.jf.dexlib2.dexbacked.OatFile) DexBackedOdexFile(org.jf.dexlib2.dexbacked.DexBackedOdexFile)

Example 2 with OatFile

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

the class DexFileFactory method loadDexContainer.

/**
     * Loads a file containing 1 or more dex files
     *
     * If the given file is a dex or odex file, it will return a MultiDexContainer containing that single entry.
     * Otherwise, for an oat or zip file, it will return an OatFile or ZipDexContainer respectively.
     *
     * @param file The file to open
     * @param opcodes The set of opcodes to use
     * @return A MultiDexContainer
     * @throws DexFileNotFoundException If the given file does not exist
     * @throws UnsupportedFileTypeException If the given file is not a valid dex/zip/odex/oat file
     */
public static MultiDexContainer<? extends DexBackedDexFile> loadDexContainer(@Nonnull File file, @Nonnull final Opcodes opcodes) throws IOException {
    if (!file.exists()) {
        throw new DexFileNotFoundException("%s does not exist", file.getName());
    }
    ZipDexContainer zipDexContainer = new ZipDexContainer(file, opcodes);
    if (zipDexContainer.isZipFile()) {
        return zipDexContainer;
    }
    InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
    try {
        try {
            DexBackedDexFile dexFile = DexBackedDexFile.fromInputStream(opcodes, inputStream);
            return new SingletonMultiDexContainer(file.getPath(), dexFile);
        } catch (DexBackedDexFile.NotADexFile ex) {
        // just eat it
        }
        try {
            DexBackedOdexFile odexFile = DexBackedOdexFile.fromInputStream(opcodes, inputStream);
            return new SingletonMultiDexContainer(file.getPath(), odexFile);
        } catch (DexBackedOdexFile.NotAnOdexFile ex) {
        // just eat it
        }
        // Note: DexBackedDexFile.fromInputStream and DexBackedOdexFile.fromInputStream will reset inputStream
        // back to the same position, if they fails
        OatFile oatFile = null;
        try {
            oatFile = OatFile.fromInputStream(inputStream);
        } catch (NotAnOatFileException ex) {
        // just eat it
        }
        if (oatFile != null) {
            // TODO: we should support loading earlier oat files, just not deodexing them
            if (oatFile.isSupportedVersion() == OatFile.UNSUPPORTED) {
                throw new UnsupportedOatVersionException(oatFile);
            }
            return oatFile;
        }
    } finally {
        inputStream.close();
    }
    throw new UnsupportedFileTypeException("%s is not an apk, dex, odex or oat file.", file.getPath());
}
Also used : NotAnOatFileException(org.jf.dexlib2.dexbacked.OatFile.NotAnOatFileException) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) OatFile(org.jf.dexlib2.dexbacked.OatFile) NotADexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile.NotADexFile) ZipDexContainer(org.jf.dexlib2.dexbacked.ZipDexContainer) DexBackedOdexFile(org.jf.dexlib2.dexbacked.DexBackedOdexFile)

Aggregations

DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)2 DexBackedOdexFile (org.jf.dexlib2.dexbacked.DexBackedOdexFile)2 OatFile (org.jf.dexlib2.dexbacked.OatFile)2 NotADexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile.NotADexFile)1 NotAnOatFileException (org.jf.dexlib2.dexbacked.OatFile.NotAnOatFileException)1 ZipDexContainer (org.jf.dexlib2.dexbacked.ZipDexContainer)1