Class DexFileFactory


  • public final class DexFileFactory
    extends java.lang.Object
    • Method Detail

      • loadDexFile

        @Nonnull
        public static DexBackedDexFile loadDexFile​(@Nonnull
                                                   java.lang.String path,
                                                   @Nullable
                                                   Opcodes opcodes)
                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • loadDexFile

        @Nonnull
        public static DexBackedDexFile loadDexFile​(@Nonnull
                                                   java.io.File file,
                                                   @Nullable
                                                   Opcodes opcodes)
                                            throws java.io.IOException
        Loads a dex/apk/odex/oat file. For oat files with multiple dex files, the first will be opened. For zip/apk files, the "classes.dex" entry will be opened.
        Parameters:
        file - The file to open
        opcodes - The set of opcodes to use
        Returns:
        A DexBackedDexFile for the given file
        Throws:
        DexFileFactory.UnsupportedOatVersionException - If file refers to an unsupported oat file
        DexFileFactory.DexFileNotFoundException - If file does not exist, if file is a zip file but does not have a "classes.dex" entry, or if file is an oat file that has no dex entries.
        DexFileFactory.UnsupportedFileTypeException - If file is not a valid dex/zip/odex/oat file, or if the "classes.dex" entry in a zip file is not a valid dex file
        java.io.IOException
      • loadDexEntry

        public static MultiDexContainer.DexEntry<? extends DexBackedDexFile> loadDexEntry​(@Nonnull
                                                                                          java.io.File file,
                                                                                          @Nonnull
                                                                                          java.lang.String dexEntry,
                                                                                          boolean exactMatch,
                                                                                          @Nullable
                                                                                          Opcodes opcodes)
                                                                                   throws java.io.IOException
        Loads a dex entry from a container format (zip/oat) This has two modes of operation, depending on the exactMatch parameter. When exactMatch is true, it will only load an entry whose name exactly matches that provided by the dexEntry parameter. When exactMatch is false, then it will search for any entry that dexEntry is a path suffix of. "path suffix" meaning all the path components in dexEntry must fully match the corresponding path components in the entry name, but some path components at the beginning of entry name can be missing. For example, if an oat file contains a "/system/framework/framework.jar:classes2.dex" entry, then the following will match (not an exhaustive list): "/system/framework/framework.jar:classes2.dex" "system/framework/framework.jar:classes2.dex" "framework/framework.jar:classes2.dex" "framework.jar:classes2.dex" "classes2.dex" Note that partial path components specifically don't match. So something like "work/framework.jar:classes2.dex" would not match. If dexEntry contains an initial slash, it will be ignored for purposes of this suffix match -- but not when performing an exact match. If multiple entries match the given dexEntry, a MultipleMatchingDexEntriesException will be thrown
        Parameters:
        file - The container file. This must be either a zip (apk) file or an oat file.
        dexEntry - The name of the entry to load. This can either be the exact entry name, if exactMatch is true, or it can be a path suffix.
        exactMatch - If true, dexE
        opcodes - The set of opcodes to use
        Returns:
        A DexBackedDexFile for the given entry
        Throws:
        DexFileFactory.UnsupportedOatVersionException - If file refers to an unsupported oat file
        DexFileFactory.DexFileNotFoundException - If the file does not exist, or if no matching entry could be found
        DexFileFactory.UnsupportedFileTypeException - If file is not a valid zip/oat file, or if the matching entry is not a valid dex file
        DexFileFactory.MultipleMatchingDexEntriesException - If multiple entries match the given dexEntry
        java.io.IOException
      • loadDexContainer

        public static MultiDexContainer<? extends DexBackedDexFile> loadDexContainer​(@Nonnull
                                                                                     java.io.File file,
                                                                                     @Nullable
                                                                                     Opcodes opcodes)
                                                                              throws java.io.IOException
        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.
        Parameters:
        file - The file to open
        opcodes - The set of opcodes to use
        Returns:
        A MultiDexContainer
        Throws:
        DexFileFactory.DexFileNotFoundException - If the given file does not exist
        DexFileFactory.UnsupportedFileTypeException - If the given file is not a valid dex/zip/odex/oat file
        java.io.IOException
      • writeDexFile

        public static void writeDexFile​(@Nonnull
                                        java.lang.String path,
                                        @Nonnull
                                        DexFile dexFile)
                                 throws java.io.IOException
        Writes a DexFile out to disk
        Parameters:
        path - The path to write the dex file to
        dexFile - a DexFile to write
        Throws:
        java.io.IOException