pass api to DexFileFactory

This commit is contained in:
Connor Tumbleson 2013-06-21 08:19:43 -05:00
parent af32d4da3e
commit fb7fbf0805
3 changed files with 13 additions and 7 deletions

View File

@ -66,13 +66,13 @@ public class Androlib {
} }
public void decodeSourcesSmali(File apkFile, File outDir, boolean debug, String debugLinePrefix, public void decodeSourcesSmali(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) throws AndrolibException { boolean bakdeb, int api) throws AndrolibException {
try { try {
File smaliDir = new File(outDir, SMALI_DIRNAME); File smaliDir = new File(outDir, SMALI_DIRNAME);
OS.rmdir(smaliDir); OS.rmdir(smaliDir);
smaliDir.mkdirs(); smaliDir.mkdirs();
LOGGER.info("Baksmaling..."); LOGGER.info("Baksmaling...");
SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb); SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb, api);
} catch (BrutException ex) { } catch (BrutException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }

View File

@ -119,13 +119,16 @@ public class ApkDecoder {
} }
} }
Map<String, String> sdkInfo = mAndrolib.getResTable(mApkFile).getSdkInfo();
int api = (sdkInfo.get("targetSdkVersion") != null) ? Integer.parseInt(sdkInfo.get("targetSdkVersion")) : mDefaultApi;
if (hasSources()) { if (hasSources()) {
switch (mDecodeSources) { switch (mDecodeSources) {
case DECODE_SOURCES_NONE: case DECODE_SOURCES_NONE:
mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug); mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug);
break; break;
case DECODE_SOURCES_SMALI: case DECODE_SOURCES_SMALI:
mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb); mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb, api);
break; break;
case DECODE_SOURCES_JAVA: case DECODE_SOURCES_JAVA:
mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug); mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug);
@ -350,6 +353,7 @@ public class ApkDecoder {
private String mFrameTag; private String mFrameTag;
private boolean mKeepBrokenResources = false; private boolean mKeepBrokenResources = false;
private String mFrameworkDir = null; private String mFrameworkDir = null;
private int mDefaultApi = 15;
private boolean mBakDeb = true; private boolean mBakDeb = true;
private boolean mCompressResources = false; private boolean mCompressResources = false;
private boolean mAnalysisMode = false; private boolean mAnalysisMode = false;

View File

@ -40,17 +40,18 @@ import java.nio.file.attribute.BasicFileAttributes;
public class SmaliDecoder { public class SmaliDecoder {
public static void decode(File apkFile, File outDir, boolean debug, String debugLinePrefix, public static void decode(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) throws AndrolibException { boolean bakdeb, int api) throws AndrolibException {
new SmaliDecoder(apkFile, outDir, debug, debugLinePrefix, bakdeb).decode(); new SmaliDecoder(apkFile, outDir, debug, debugLinePrefix, bakdeb, api).decode();
} }
private SmaliDecoder(File apkFile, File outDir, boolean debug, String debugLinePrefix, private SmaliDecoder(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) { boolean bakdeb, int api) {
mApkFile = apkFile; mApkFile = apkFile;
mOutDir = outDir.toPath(); mOutDir = outDir.toPath();
mDebug = debug; mDebug = debug;
mDebugLinePrefix = debugLinePrefix; mDebugLinePrefix = debugLinePrefix;
mBakDeb = bakdeb; mBakDeb = bakdeb;
mApi = api;
} }
private void decode() throws AndrolibException { private void decode() throws AndrolibException {
@ -73,7 +74,7 @@ public class SmaliDecoder {
options.inlineResolver = null; options.inlineResolver = null;
options.checkPackagePrivateAccess = false; options.checkPackagePrivateAccess = false;
baksmali.disassembleDexFile(DexFileFactory.loadDexFile(mApkFile, 0), options); baksmali.disassembleDexFile(DexFileFactory.loadDexFile(mApkFile, mApi), options);
if (mDebug) { if (mDebug) {
Files.walkFileTree(mOutDir, new SmaliFileVisitor()); Files.walkFileTree(mOutDir, new SmaliFileVisitor());
@ -88,6 +89,7 @@ public class SmaliDecoder {
private final boolean mDebug; private final boolean mDebug;
private final String mDebugLinePrefix; private final String mDebugLinePrefix;
private final boolean mBakDeb; private final boolean mBakDeb;
private final int mApi;
private class SmaliFileVisitor extends SimpleFileVisitor<Path> { private class SmaliFileVisitor extends SimpleFileVisitor<Path> {