From cf52e5cd48247090a83fe65e04d3b1f09b47dcfe Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Thu, 4 Mar 2010 07:45:01 +0000 Subject: [PATCH] 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 --- .../jf/dexlib/Code/Analysis/ClassPath.java | 58 ++++++++++--------- .../src/main/java/org/jf/dexlib/DexFile.java | 9 ++- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java index 29842c2a..53df5d7c 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Analysis/ClassPath.java @@ -93,42 +93,44 @@ public class ClassPath { private void loadBootClassPath(String[] classPathDirs, String bootClassPathEntry) { 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; - if (extIndex == -1) { - baseEntry = bootClassPathEntry; + String baseEntry; + if (extIndex == -1) { + baseEntry = bootClassPathEntry; + } else { + baseEntry = bootClassPathEntry.substring(0, extIndex); + } + + for (String ext: new String[]{"", ".odex", ".jar", ".apk", ".zip"}) { + if (ext.length() == 0) { + file = new File(classPathDir, bootClassPathEntry); } else { - baseEntry = bootClassPathEntry.substring(0, extIndex); + file = new File(classPathDir, baseEntry + ext); } - for (String ext: new String[]{".odex", ".jar", ".apk", ".zip"}) { - String newEntry = baseEntry + ext; - file = new File(classPathDir, newEntry); - if (file.exists()) { - found = true; - break; + if (file.exists()) { + if (!file.canRead()) { + System.err.println(String.format("warning: cannot open %s for reading. Will continue " + + "looking.", file.getPath())); + continue; + } + + try { + dexFile = new DexFile(file, false, true); + } catch (DexFile.NoClassesDexException ex) { + continue; + } catch (Exception ex) { + throw ExceptionWithContext.withContext(ex, "Error while reading boot class path entry \"" + + bootClassPathEntry + "\"."); } } - if (!found) { - continue; - } } - - if (!file.canRead()) { - throw new ExceptionWithContext("Cannot read ClassPath entry \"" + bootClassPathEntry + "\"."); - } - - DexFile dexFile; - try { - dexFile = new DexFile(file, false, true); - } catch (Exception ex) { - throw ExceptionWithContext.withContext(ex, "Error while reading boot class path entry \"" + - bootClassPathEntry + "\"."); + if (dexFile == null) { + continue; } try { diff --git a/dexlib/src/main/java/org/jf/dexlib/DexFile.java b/dexlib/src/main/java/org/jf/dexlib/DexFile.java index ff0c751e..bf046255 100644 --- a/dexlib/src/main/java/org/jf/dexlib/DexFile.java +++ b/dexlib/src/main/java/org/jf/dexlib/DexFile.java @@ -305,7 +305,8 @@ public class DexFile zipFile = new ZipFile(file); ZipEntry zipEntry = zipFile.getEntry("classes.dex"); 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(); if (fileLength < 40) { @@ -866,4 +867,10 @@ public class DexFile bytes[10] = (byte) (sum >> 16); bytes[11] = (byte) (sum >> 24); } + + public static class NoClassesDexException extends ExceptionWithContext { + public NoClassesDexException(String message) { + super(message); + } + } } \ No newline at end of file