mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-12 05:47:46 +01:00
[dexlib2] allow disassemble of apks with non classes.dex files
This commit is contained in:
parent
c476ce16be
commit
292e49de0a
@ -46,16 +46,21 @@ import java.util.zip.ZipFile;
|
|||||||
public final class DexFileFactory {
|
public final class DexFileFactory {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static DexBackedDexFile loadDexFile(String path, int api) throws IOException {
|
public static DexBackedDexFile loadDexFile(String path, int api) throws IOException {
|
||||||
return loadDexFile(new File(path), new Opcodes(api));
|
return loadDexFile(new File(path), "classes.dex", new Opcodes(api));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static DexBackedDexFile loadDexFile(File dexFile, int api) throws IOException {
|
public static DexBackedDexFile loadDexFile(File dexFile, int api) throws IOException {
|
||||||
return loadDexFile(dexFile, new Opcodes(api));
|
return loadDexFile(dexFile, "classes.dex", new Opcodes(api));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static DexBackedDexFile loadDexFile(File dexFile, @Nonnull Opcodes opcodes) throws IOException {
|
public static DexBackedDexFile loadDexFile(File dexFile, String dexEntry, int api) throws IOException {
|
||||||
|
return loadDexFile(dexFile, dexEntry, new Opcodes(api));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static DexBackedDexFile loadDexFile(File dexFile, String filename, @Nonnull Opcodes opcodes) throws IOException {
|
||||||
ZipFile zipFile = null;
|
ZipFile zipFile = null;
|
||||||
boolean isZipFile = false;
|
boolean isZipFile = false;
|
||||||
try {
|
try {
|
||||||
@ -63,16 +68,16 @@ public final class DexFileFactory {
|
|||||||
// if we get here, it's safe to assume we have a zip file
|
// if we get here, it's safe to assume we have a zip file
|
||||||
isZipFile = true;
|
isZipFile = true;
|
||||||
|
|
||||||
ZipEntry zipEntry = zipFile.getEntry("classes.dex");
|
ZipEntry zipEntry = zipFile.getEntry(filename);
|
||||||
if (zipEntry == null) {
|
if (zipEntry == null) {
|
||||||
throw new NoClassesDexException("zip file %s does not contain a classes.dex file", dexFile.getName());
|
throw new NoClassesDexException("zip file %s does not contain a classes.dex file", dexFile.getName());
|
||||||
}
|
}
|
||||||
long fileLength = zipEntry.getSize();
|
long fileLength = zipEntry.getSize();
|
||||||
if (fileLength < 40) {
|
if (fileLength < 40) {
|
||||||
throw new ExceptionWithContext(
|
throw new ExceptionWithContext(
|
||||||
"The classes.dex file in %s is too small to be a valid dex file", dexFile.getName());
|
"The " + filename + " file in %s is too small to be a valid dex file", dexFile.getName());
|
||||||
} else if (fileLength > Integer.MAX_VALUE) {
|
} else if (fileLength > Integer.MAX_VALUE) {
|
||||||
throw new ExceptionWithContext("The classes.dex file in %s is too large to read in", dexFile.getName());
|
throw new ExceptionWithContext("The " + filename + " file in %s is too large to read in", dexFile.getName());
|
||||||
}
|
}
|
||||||
byte[] dexBytes = new byte[(int)fileLength];
|
byte[] dexBytes = new byte[(int)fileLength];
|
||||||
ByteStreams.readFully(zipFile.getInputStream(zipEntry), dexBytes);
|
ByteStreams.readFully(zipFile.getInputStream(zipEntry), dexBytes);
|
||||||
|
Loading…
Reference in New Issue
Block a user