diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index 08978eb3..1d6f6363 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -332,21 +332,30 @@ final public class AndrolibResources { // path for aapt binary if (!aaptPath.isEmpty()) { - File aaptFile = new File(aaptPath); - if (aaptFile.canRead() && aaptFile.exists()) { - aaptFile.setExecutable(true); - cmd.add(aaptFile.getPath()); + File aaptFile = new File(aaptPath); + if (aaptFile.canRead() && aaptFile.exists()) { + aaptFile.setExecutable(true); + cmd.add(aaptFile.getPath()); - if (flags.get("verbose")) { - LOGGER.info(aaptFile.getPath() - + " being used as aapt location."); - } - } else { - LOGGER.warning("aapt location could not be found. Defaulting back to default"); - cmd.add("aapt"); - } + if (flags.get("verbose")) { + LOGGER.info(aaptFile.getPath() + + " being used as aapt location."); + } + } else { + LOGGER.warning("aapt location could not be found. Defaulting back to default"); + + try { + cmd.add(getAaptBinaryFile().getAbsolutePath()); + } catch (BrutException ignored) { + cmd.add("aapt"); + } + } } else { - cmd.add("aapt"); + try { + cmd.add(getAaptBinaryFile().getAbsolutePath()); + } catch (BrutException ignored) { + cmd.add("aapt"); + } } cmd.add("p"); @@ -728,7 +737,7 @@ final public class AndrolibResources { // if a framework path was specified on the command line, use it if (sFrameworkFolder != null) { path = sFrameworkFolder; - } else if (System.getProperty("os.name").equals("Mac OS X")) { + } else if (OSDetection.isMacOSX()) { // store in user-home, for Mac OS X path = System.getProperty("user.home") + File.separatorChar + "Library/apktool/framework"; } else { @@ -747,6 +756,33 @@ final public class AndrolibResources { } return dir; } + + /** + * + * @see https://github.com/iBotPeaches/platform_frameworks_base + * @return + * @throws AndrolibException + */ + public File getAaptBinaryFile() throws AndrolibException { + try { + if (OSDetection.isMacOSX()) { + mAaptBinary = Jar + .getResourceAsFile("/aapt/macosx/aapt"); + } else if (OSDetection.isUnix()) { + mAaptBinary = Jar + .getResourceAsFile("/aapt/linux/aapt"); + } else if (OSDetection.isWindows()) { + mAaptBinary = Jar + .getResourceAsFile("/aapt/windows/aapt.exe"); + } else { + return null; + } + } catch (BrutException ex) { + throw new AndrolibException(ex); + } + mAaptBinary.setExecutable(true); + return mAaptBinary; + } public File getAndroidResourcesFile() throws AndrolibException { try { @@ -776,5 +812,6 @@ final public class AndrolibResources { private String mVersionName = null; private String mPackageRenamed = null; + private File mAaptBinary = null; } diff --git a/brut.apktool/apktool-lib/src/main/resources/prebuilt/aapt/linux/aapt b/brut.apktool/apktool-lib/src/main/resources/prebuilt/aapt/linux/aapt new file mode 100755 index 00000000..71022e94 Binary files /dev/null and b/brut.apktool/apktool-lib/src/main/resources/prebuilt/aapt/linux/aapt differ diff --git a/brut.j.util/src/main/java/brut/util/OSDetection.java b/brut.j.util/src/main/java/brut/util/OSDetection.java new file mode 100644 index 00000000..781a7249 --- /dev/null +++ b/brut.j.util/src/main/java/brut/util/OSDetection.java @@ -0,0 +1,33 @@ +/** + * Copyright 2010 Ryszard Wiśniewski + * Copyright 2013 Connor Tumbleson + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brut.util; + +public class OSDetection { + private static String OS = System.getProperty("os.name").toLowerCase(); + + public static boolean isWindows() { + return (OS.indexOf("win") >= 0); + } + + public static boolean isMacOSX() { + return (OS.indexOf("mac") >= 0); + } + + public static boolean isUnix() { + return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 || (OS.indexOf("sunos") >= 0)); + } +}