From 25e9ed7281b7a50dd86c0913326b06d46bb39b3d Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Wed, 19 Mar 2014 16:23:45 -0500 Subject: [PATCH] add more modular support for renamed packages -- There is no "set" rules for renaming a manifest, so we must adapt to patterns. There are some apks that have original package names as "android", "miui", "com.htc", etc. These are not meant for renaming, but exist to align that apk to a specific OEM framework system. (EX HTC system apks have a package id of com.htc). However, this pattern isn't true when framework apks are involved, as the intended behavior is to rename the package from xxx to com.htc (as an example). -- We solve this by first identifying the active package via the packageId instead of package with most ResSpecs (we fall back on that though) -- then with two hardcoded arrays of UNKNOWN_PACKAGES and ALLOWED_PACKAGES --- .../java/brut/androlib/res/AndrolibResources.java | 14 ++++++++++---- .../main/java/brut/androlib/res/data/ResTable.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) 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 7b5e6ade..6ede4d48 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 @@ -177,20 +177,23 @@ final public class AndrolibResources { throws AndrolibException { // compare resources.arsc package name to the one present in AndroidManifest - ResPackage resPackage = resTable.getHighestSpecPackage(); + ResPackage resPackage = resTable.getCurrentResPackage(); mPackageOriginal = resPackage.getName(); mPackageRenamed = resTable.getPackageRenamed(); resTable.setPackageId(resPackage.getId()); resTable.setPackageOriginal(mPackageOriginal); + // 1) Check if mPackageOriginal === mPackageRenamed + // 2) Check if mPackageOriginal is ignored via IGNORED_PACKAGES + // 2a) If its ignored, make sure the mPackageRenamed isn't explicitly allowed if (mPackageOriginal.equalsIgnoreCase(mPackageRenamed) || - Arrays.asList(IGNORED_PACKAGES).contains(mPackageOriginal)) { + (Arrays.asList(IGNORED_PACKAGES).contains(mPackageOriginal) && + ! Arrays.asList(ALLOWED_PACKAGES).contains(mPackageRenamed))) { LOGGER.info("Regular manifest package..."); } else { try { - - LOGGER.info("Renamed manifest package found! Fixing..."); + LOGGER.info("Renamed manifest package found! Replacing " + mPackageRenamed + " with " + mPackageOriginal); Document doc = loadDocument(filePath); // Get the manifest line @@ -853,4 +856,7 @@ final public class AndrolibResources { private final static String[] IGNORED_PACKAGES = new String[] { "android", "com.htc", "miui" }; + + private final static String[] ALLOWED_PACKAGES = new String[] { + "com.miui" }; } diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTable.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTable.java index 6d0eff3c..22b727c4 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTable.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/ResTable.java @@ -90,6 +90,16 @@ public class ResTable { return (id == 0) ? getPackage(1) : getPackage(id); } + public ResPackage getCurrentResPackage() throws AndrolibException { + ResPackage pkg = mPackagesById.get(mPackageId); + + if (pkg != null) { + return pkg; + } else { + return getHighestSpecPackage(); + } + } + public ResPackage getPackage(String name) throws AndrolibException { ResPackage pkg = mPackagesByName.get(name); if (pkg == null) {