When loading boot class path files, if a jar file doesn't have a classes.dex file, skip it and continue looking

git-svn-id: https://smali.googlecode.com/svn/trunk@670 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-03-04 07:45:01 +00:00
parent 8eaecd53d3
commit cf52e5cd48
2 changed files with 38 additions and 29 deletions

View File

@ -93,10 +93,9 @@ public class ClassPath {
private void loadBootClassPath(String[] classPathDirs, String bootClassPathEntry) { private void loadBootClassPath(String[] classPathDirs, String bootClassPathEntry) {
for (String classPathDir: classPathDirs) { for (String classPathDir: classPathDirs) {
File file = new File(classPathDir, bootClassPathEntry); File file = null;
DexFile dexFile = null;
if (!file.exists()) {
boolean found = false;
int extIndex = bootClassPathEntry.lastIndexOf("."); int extIndex = bootClassPathEntry.lastIndexOf(".");
String baseEntry; String baseEntry;
@ -106,30 +105,33 @@ public class ClassPath {
baseEntry = bootClassPathEntry.substring(0, extIndex); baseEntry = bootClassPathEntry.substring(0, extIndex);
} }
for (String ext: new String[]{".odex", ".jar", ".apk", ".zip"}) { for (String ext: new String[]{"", ".odex", ".jar", ".apk", ".zip"}) {
String newEntry = baseEntry + ext; if (ext.length() == 0) {
file = new File(classPathDir, newEntry); file = new File(classPathDir, bootClassPathEntry);
} else {
file = new File(classPathDir, baseEntry + ext);
}
if (file.exists()) { if (file.exists()) {
found = true; if (!file.canRead()) {
break; System.err.println(String.format("warning: cannot open %s for reading. Will continue " +
} "looking.", file.getPath()));
}
if (!found) {
continue; continue;
} }
}
if (!file.canRead()) {
throw new ExceptionWithContext("Cannot read ClassPath entry \"" + bootClassPathEntry + "\".");
}
DexFile dexFile;
try { try {
dexFile = new DexFile(file, false, true); dexFile = new DexFile(file, false, true);
} catch (DexFile.NoClassesDexException ex) {
continue;
} catch (Exception ex) { } catch (Exception ex) {
throw ExceptionWithContext.withContext(ex, "Error while reading boot class path entry \"" + throw ExceptionWithContext.withContext(ex, "Error while reading boot class path entry \"" +
bootClassPathEntry + "\"."); bootClassPathEntry + "\".");
} }
}
}
if (dexFile == null) {
continue;
}
try { try {
loadDexFile(file.getPath(), dexFile); loadDexFile(file.getPath(), dexFile);

View File

@ -305,7 +305,8 @@ public class DexFile
zipFile = new ZipFile(file); zipFile = new ZipFile(file);
ZipEntry zipEntry = zipFile.getEntry("classes.dex"); ZipEntry zipEntry = zipFile.getEntry("classes.dex");
if (zipEntry == null) { if (zipEntry == null) {
throw new RuntimeException("zip file " + file.getName() + " does not contain a classes.dex file"); throw new NoClassesDexException("zip file " + file.getName() + " does not contain a classes.dex " +
"file");
} }
fileLength = zipEntry.getSize(); fileLength = zipEntry.getSize();
if (fileLength < 40) { if (fileLength < 40) {
@ -866,4 +867,10 @@ public class DexFile
bytes[10] = (byte) (sum >> 16); bytes[10] = (byte) (sum >> 16);
bytes[11] = (byte) (sum >> 24); bytes[11] = (byte) (sum >> 24);
} }
public static class NoClassesDexException extends ExceptionWithContext {
public NoClassesDexException(String message) {
super(message);
}
}
} }