From 2ef25fe5e2b4acf272aea94bcf2de022fb531949 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Wed, 16 Oct 2013 19:48:43 -0500 Subject: [PATCH] fix jar disassembling --- CHANGES | 1 + .../src/main/java/brut/apktool/Main.java | 10 ++++++++++ .../main/java/brut/androlib/ApkDecoder.java | 19 ++++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index b43b1bd9..0950efb9 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,7 @@ v2.0.0 (TBA) -Fixed (issue #426) - Filename too long (JesusFreke) -Fixed (issue #524) - INSTALL_FAILED_DEXOPT fix (JesusFreke) -Fixed (issue #473) - multiple package frameworks are treated correctly. +-Fixed (issue #531) - JAR disassembling borking is fixed -Added output to list Apktool version to help debugging. -Updated known bytes for configurations to 38 (from addition of layout direction) -Fixed NPE when handling odex apks even with --no-src specified. (Thanks Rodrigo Chiossi) diff --git a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java index 4696c230..234a44dc 100644 --- a/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java +++ b/brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java @@ -144,6 +144,9 @@ public class Main { if (cli.hasOption("m") || cli.hasOption("match-original")) { decoder.setAnalysisMode(true, false); } + if (cli.hasOption("api")) { + decoder.setApi(Integer.parseInt(cli.getOptionValue("api"))); + } if (cli.hasOption("o") || cli.hasOption("output")) { outDir = new File(cli.getOptionValue("o")); decoder.setOutDir(outDir); @@ -295,6 +298,12 @@ public class Main { .withArgName("prefix") .create(); + Option apiLevelOption = OptionBuilder.withLongOpt("api") + .withDescription("The numeric api-level of the file to generate, e.g. 14 for ICS.") + .hasArg(true) + .withArgName("API") + .create(); + Option debugBuiOption = OptionBuilder.withLongOpt("debug") .withDescription("Builds in debug mode. Check project page for more info.") .create("d"); @@ -377,6 +386,7 @@ public class Main { DecodeOptions.addOption(noDbgOption); DecodeOptions.addOption(keepResOption); DecodeOptions.addOption(analysisOption); + DecodeOptions.addOption(apiLevelOption); BuildOptions.addOption(debugBuiOption); BuildOptions.addOption(aaptOption); diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java index 3d6b4d98..fc9999f9 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java @@ -64,6 +64,10 @@ public class ApkDecoder { mOutDir = outDir; } + public void setApi(int api) { + mApi = api; + } + public void decode() throws AndrolibException, IOException { File outDir = getOutDir(); @@ -85,9 +89,15 @@ public class ApkDecoder { LOGGER.info("Using Apktool " + Androlib.getVersion() + " on " + mApkFile.getName()); if (hasResources()) { + + Map sdkInfo = mAndrolib.getResTable(mApkFile).getSdkInfo(); + + if (sdkInfo.get("targetSdkVersion") != null) { + mApi = Integer.parseInt(sdkInfo.get("targetSdkVersion")); + } + setAnalysisMode(mAnalysisMode, true); // read the resources.arsc checking for STORED vs DEFLATE - // compression // this will determine whether we compress on rebuild or not. ZipExtFile zef = new ZipExtFile(mApkFile.getAbsolutePath()); ZipArchiveEntry ze = zef.getEntry("resources.arsc"); @@ -122,8 +132,7 @@ public class ApkDecoder { } } - Map sdkInfo = mAndrolib.getResTable(mApkFile).getSdkInfo(); - int api = (sdkInfo.get("targetSdkVersion") != null) ? Integer.parseInt(sdkInfo.get("targetSdkVersion")) : mDefaultApi; + if (hasSources()) { switch (mDecodeSources) { @@ -131,7 +140,7 @@ public class ApkDecoder { mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug); break; case DECODE_SOURCES_SMALI: - mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb, api); + mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb, mApi); break; case DECODE_SOURCES_JAVA: mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug); @@ -359,7 +368,7 @@ public class ApkDecoder { private String mFrameTag; private boolean mKeepBrokenResources = false; private String mFrameworkDir = null; - private int mDefaultApi = 15; + private int mApi = 15; private boolean mBakDeb = true; private boolean mCompressResources = false; private boolean mAnalysisMode = false;