mirror of
https://github.com/revanced/Apktool.git
synced 2024-11-11 15:09:24 +01:00
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
This commit is contained in:
parent
74153661df
commit
25e9ed7281
@ -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" };
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user