Add better error messages when finding embedded dex files for oat files

This commit is contained in:
Ben Gruver 2019-08-23 14:19:07 -07:00
parent bdbea44b98
commit 3b70c36296
3 changed files with 21 additions and 0 deletions

View File

@ -298,6 +298,10 @@ public final class DexFileFactory {
public DexFileNotFoundException(@Nullable String message, Object... formatArgs) {
super(message, formatArgs);
}
public DexFileNotFoundException(Throwable cause, @Nullable String message, Object... formatArgs) {
super(cause, message, formatArgs);
}
}
public static class UnsupportedOatVersionException extends ExceptionWithContext {

View File

@ -58,6 +58,10 @@ public class CDexBackedDexFile extends DexBackedDexFile {
}
public static boolean isCdex(byte[] buf, int offset) {
if (offset + 4 > buf.length) {
return false;
}
byte[] cdexMagic;
try {
cdexMagic = "cdex".getBytes("US-ASCII");

View File

@ -35,10 +35,12 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.google.common.io.ByteStreams;
import org.jf.dexlib2.DexFileFactory;
import org.jf.dexlib2.Opcodes;
import org.jf.dexlib2.dexbacked.OatFile.SymbolTable.Symbol;
import org.jf.dexlib2.dexbacked.raw.HeaderItem;
import org.jf.dexlib2.iface.MultiDexContainer;
import org.jf.dexlib2.util.DexUtil;
import org.jf.util.AbstractForwardSequentialList;
import javax.annotation.Nonnull;
@ -571,6 +573,17 @@ public class OatFile extends DexBuffer implements MultiDexContainer<DexBackedDex
if (CDexBackedDexFile.isCdex(buf, dexOffset)) {
return new OatCDexFile(buf, dexOffset);
} else {
try {
DexUtil.verifyDexHeader(buf, dexOffset);
} catch (DexBackedDexFile.NotADexFile ex) {
if (getOatVersion() >= 87) {
throw new DexFileFactory.DexFileNotFoundException(ex,
"Could not locate the embedded dex file %s. Is the vdex file missing?", entryName);
} else {
throw new DexFileFactory.DexFileNotFoundException(ex,
"The embedded dex file %s does not appear to be a valid dex file.", entryName);
}
}
return new OatDexFile(buf, dexOffset);
}
}