Handle ARSC files with multiple ResPackages

- superseeds - 68c1809a48
This commit is contained in:
Connor Tumbleson 2014-10-03 11:31:43 -05:00
parent 9f2d6f35db
commit ce3c37c6ab
2 changed files with 29 additions and 4 deletions

View File

@ -43,6 +43,7 @@ v2.0.0 (TBA)
-Fixed (issue #512) - Fixed AndroidManifest missing attributes. -Fixed (issue #512) - Fixed AndroidManifest missing attributes.
-Fixed (issue #677) - Fixed ignoring formatted attribute in <string-array>. -Fixed (issue #677) - Fixed ignoring formatted attribute in <string-array>.
-Fixed (issue #675) - Fixed multiple overlapping catches. -Fixed (issue #675) - Fixed multiple overlapping catches.
-Fixed (issue #684) - Fixed issue with multiple ResPackages in ARSC file.
-Fixed issue with APKs with multiple dex files. -Fixed issue with APKs with multiple dex files.
-Fixed issue with using Apktool without smali/baksmali for ApktoolProperties (Thanks teprrr) -Fixed issue with using Apktool without smali/baksmali for ApktoolProperties (Thanks teprrr)
-Fixed issue with non-URI standard characters in apk name (Thanks rover12421) -Fixed issue with non-URI standard characters in apk name (Thanks rover12421)

View File

@ -74,7 +74,6 @@ final public class AndrolibResources {
ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken); ResPackage[] pkgs = getResPackagesFromApk(apkFile, resTable, sKeepBroken);
ResPackage pkg = null; ResPackage pkg = null;
// @todo handle multiple packages using findPackageWithMostResSpecs()
switch (pkgs.length) { switch (pkgs.length) {
case 1: case 1:
pkg = pkgs[0]; pkg = pkgs[0];
@ -83,21 +82,42 @@ final public class AndrolibResources {
if (pkgs[0].getName().equals("android")) { if (pkgs[0].getName().equals("android")) {
LOGGER.warning("Skipping \"android\" package group"); LOGGER.warning("Skipping \"android\" package group");
pkg = pkgs[1]; pkg = pkgs[1];
break;
} else if (pkgs[0].getName().equals("com.htc")) { } else if (pkgs[0].getName().equals("com.htc")) {
LOGGER.warning("Skipping \"htc\" package group"); LOGGER.warning("Skipping \"htc\" package group");
pkg = pkgs[1]; pkg = pkgs[1];
break;
} }
default:
pkg = selectPkgWithMostResSpecs(pkgs);
break; break;
} }
if (pkg == null) { if (pkg == null) {
throw new AndrolibException("Arsc files with zero or multiple packages"); throw new AndrolibException("arsc files with zero packages or no arsc file found.");
} }
resTable.addPackage(pkg, true); resTable.addPackage(pkg, true);
return pkg; return pkg;
} }
public ResPackage selectPkgWithMostResSpecs(ResPackage[] pkgs)
throws AndrolibException {
int id = 0;
int value = 0;
for (ResPackage resPackage : pkgs) {
if (resPackage.getResSpecCount() > value && ! resPackage.getName().equalsIgnoreCase("android")) {
value = resPackage.getResSpecCount();
id = resPackage.getId();
}
}
// if id is still 0, we only have one pkgId which is "android" -> 1
return (id == 0) ? pkgs[0] : pkgs[1];
}
public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag) public ResPackage loadFrameworkPkg(ResTable resTable, int id, String frameTag)
throws AndrolibException { throws AndrolibException {
File apk = getFrameworkApk(id, frameTag); File apk = getFrameworkApk(id, frameTag);
@ -105,11 +125,15 @@ final public class AndrolibResources {
LOGGER.info("Loading resource table from file: " + apk); LOGGER.info("Loading resource table from file: " + apk);
ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true); ResPackage[] pkgs = getResPackagesFromApk(new ExtFile(apk), resTable, true);
if (pkgs.length != 1) { ResPackage pkg;
if (pkgs.length > 1) {
pkg = selectPkgWithMostResSpecs(pkgs);
} else if (pkgs.length == 0) {
throw new AndrolibException("Arsc files with zero or multiple packages"); throw new AndrolibException("Arsc files with zero or multiple packages");
} else {
pkg = pkgs[0];
} }
ResPackage pkg = pkgs[0];
if (pkg.getId() != id) { if (pkg.getId() != id) {
throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId()); throw new AndrolibException("Expected pkg of id: " + String.valueOf(id) + ", got: " + pkg.getId());
} }