From f2935deb160a8e99cdbfc71a2f424525a298a7d1 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sat, 15 Oct 2016 15:39:11 -0700 Subject: [PATCH] Fix classpath loading for pre-art odex files --- .../java/org/jf/baksmali/AnalysisArguments.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java b/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java index 83c4b13f..fa3bb855 100644 --- a/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java +++ b/baksmali/src/main/java/org/jf/baksmali/AnalysisArguments.java @@ -46,6 +46,8 @@ import java.io.File; import java.io.IOException; import java.util.List; +import static org.jf.dexlib2.analysis.ClassPath.NOT_ART; + public class AnalysisArguments { @Parameter(names = {"-a", "--api"}, description = "The numeric api level of the file being disassembled.") @@ -86,7 +88,7 @@ public class AnalysisArguments { @Nonnull public ClassPath loadClassPathForDexFile(@Nonnull File dexFileDir, @Nonnull DexFile dexFile, boolean checkPackagePrivateAccess) throws IOException { - return loadClassPathForDexFile(dexFileDir, dexFile, checkPackagePrivateAccess, 0); + return loadClassPathForDexFile(dexFileDir, dexFile, checkPackagePrivateAccess, NOT_ART); } @Nonnull @@ -95,7 +97,16 @@ public class AnalysisArguments { throws IOException { ClassPathResolver resolver; - if (dexFile instanceof OatDexFile) { + // By default, oatVersion should be NOT_ART, and we'll automatically set it if dexFile is an oat file. In some + // cases the caller may choose to override the oat version, in which case we should use the given oat version + // regardless of the actual version of the oat file + if (oatVersion == NOT_ART) { + if (dexFile instanceof OatDexFile) { + checkPackagePrivateAccess = true; + oatVersion = ((OatDexFile)dexFile).getContainer().getOatVersion(); + } + } else { + // this should always be true for ART checkPackagePrivateAccess = true; }