Package org.jf.dexlib2
Class DexFileFactory
java.lang.Object
org.jf.dexlib2.DexFileFactory
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic classstatic classstatic classprivate static classstatic classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanfullEntryMatch(String entry, String targetEntry) Matches two entries fully, ignoring any initial slash, if anystatic MultiDexContainer<? extends DexBackedDexFile> loadDexContainer(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(File file, 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 DexBackedDexFileloadDexFile(File file, Opcodes opcodes) Loads a dex/apk/odex/oat file.static DexBackedDexFileloadDexFile(String path, Opcodes opcodes) private static booleanpartialEntryMatch(String entry, String targetEntry) Performs a partial match against entry and targetEntry.static voidwriteDexFile(String path, DexFile dexFile) Writes a DexFile out to disk
-
Constructor Details
-
DexFileFactory
private DexFileFactory()
-
-
Method Details
-
loadDexFile
@Nonnull public static DexBackedDexFile loadDexFile(@Nonnull String path, @Nullable Opcodes opcodes) throws IOException - Throws:
IOException
-
loadDexFile
@Nonnull public static DexBackedDexFile loadDexFile(@Nonnull File file, @Nullable Opcodes opcodes) throws 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 fileIOException
-
loadDexEntry
public static MultiDexContainer.DexEntry<? extends DexBackedDexFile> loadDexEntry(@Nonnull File file, @Nonnull String dexEntry, boolean exactMatch, @Nullable Opcodes opcodes) throws 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 dexEntryIOException
-
loadDexContainer
public static MultiDexContainer<? extends DexBackedDexFile> loadDexContainer(@Nonnull File file, @Nullable Opcodes opcodes) throws 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 fileIOException
-
writeDexFile
Writes a DexFile out to disk- Parameters:
path- The path to write the dex file todexFile- a DexFile to write- Throws:
IOException
-
fullEntryMatch
Matches two entries fully, ignoring any initial slash, if any -
partialEntryMatch
Performs a partial match against entry and targetEntry. This is considered a partial match if targetEntry is a suffix of entry, and if the suffix starts on a path "part" (ignoring the initial separator, if any). '/' and ':' and '!' are considered separators for this. So entry="/blah/blah/something.dex" and targetEntry="lah/something.dex" shouldn't match, but both targetEntry="blah/something.dex" and "/blah/something.dex" should match.
-