Package org.jf.dexlib2
Class DexFileFactory
- java.lang.Object
-
- org.jf.dexlib2.DexFileFactory
-
public final class DexFileFactory extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DexFileFactory.DexEntryFinder
static class
DexFileFactory.DexFileNotFoundException
static class
DexFileFactory.FilenameVdexProvider
static class
DexFileFactory.MultipleMatchingDexEntriesException
static class
DexFileFactory.UnsupportedFileTypeException
static class
DexFileFactory.UnsupportedOatVersionException
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MultiDexContainer<? extends DexBackedDexFile>
loadDexContainer(java.io.File file, Opcodes opcodes)
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.static MultiDexContainer.DexEntry<? extends DexBackedDexFile>
loadDexEntry(java.io.File file, java.lang.String dexEntry, boolean exactMatch, Opcodes opcodes)
Loads a dex entry from a container format (zip/oat) This has two modes of operation, depending on the exactMatch parameter.static DexBackedDexFile
loadDexFile(java.io.File file, Opcodes opcodes)
Loads a dex/apk/odex/oat file.static DexBackedDexFile
loadDexFile(java.lang.String path, Opcodes opcodes)
static void
writeDexFile(java.lang.String path, DexFile dexFile)
Writes a DexFile out to disk
-
-
-
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 openopcodes
- The set of opcodes to use- Returns:
- A DexBackedDexFile for the given file
- Throws:
DexFileFactory.UnsupportedOatVersionException
- If file refers to an unsupported oat fileDexFileFactory.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 filejava.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, dexEopcodes
- The set of opcodes to use- Returns:
- A DexBackedDexFile for the given entry
- Throws:
DexFileFactory.UnsupportedOatVersionException
- If file refers to an unsupported oat fileDexFileFactory.DexFileNotFoundException
- If the file does not exist, or if no matching entry could be foundDexFileFactory.UnsupportedFileTypeException
- If file is not a valid zip/oat file, or if the matching entry is not a valid dex fileDexFileFactory.MultipleMatchingDexEntriesException
- If multiple entries match the given dexEntryjava.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 openopcodes
- The set of opcodes to use- Returns:
- A MultiDexContainer
- Throws:
DexFileFactory.DexFileNotFoundException
- If the given file does not existDexFileFactory.UnsupportedFileTypeException
- If the given file is not a valid dex/zip/odex/oat filejava.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 todexFile
- a DexFile to write- Throws:
java.io.IOException
-
-