🎨 Patch any application

This commit is contained in:
Nikhil Badyal
2023-08-24 20:13:02 +05:30
parent 0544b64ae5
commit 7d0e83eed1
3 changed files with 21 additions and 23 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ def main() -> None:
logger.info(app) logger.info(app)
parser.patch_app(app) parser.patch_app(app)
except AppNotFound as e: except AppNotFound as e:
logger.info(f"Invalid app requested to build {e}") logger.info(e)
except PatchesJsonLoadFailed: except PatchesJsonLoadFailed:
logger.exception("Patches.json not found") logger.exception("Patches.json not found")
except PatchingFailed as e: except PatchingFailed as e:
+6 -4
View File
@@ -50,9 +50,8 @@ class APP(object):
self.download_dl = config.env.str(f"{app_name}_DL".upper(), "") self.download_dl = config.env.str(f"{app_name}_DL".upper(), "")
self.download_patch_resources(config) self.download_patch_resources(config)
self.download_source = config.env.str(f"{app_name}_DL_SOURCE".upper(), "") self.download_source = config.env.str(f"{app_name}_DL_SOURCE".upper(), "")
self.package_name = config.env.str( env_package_name = config.env.str(f"{app_name}_PACKAGE_NAME".upper(), None)
f"{app_name}_PACKAGE_NAME".upper(), Patches.get_package_name(app_name) self.package_name = env_package_name or Patches.get_package_name(app_name)
)
def download_apk_for_patching(self, config: RevancedConfig) -> None: def download_apk_for_patching(self, config: RevancedConfig) -> None:
"""Download apk to be patched.""" """Download apk to be patched."""
@@ -73,7 +72,10 @@ class APP(object):
self.package_name self.package_name
) )
except KeyError: except KeyError:
raise DownloadFailure(f"No download source found for {self.app_name}") raise DownloadFailure(
f"App {self.app_name} not supported officially yet. Please provide download "
f"source in env."
)
downloader = DownloaderFactory.create_downloader( downloader = DownloaderFactory.create_downloader(
config=config, apk_source=self.download_source config=config, apk_source=self.download_source
) )
+8 -12
View File
@@ -75,7 +75,9 @@ class Patches(object):
for package, app_name in Patches.revanced_package_names.items(): for package, app_name in Patches.revanced_package_names.items():
if app_name == app: if app_name == app:
return package return package
raise AppNotFound(f"App {app} not supported yet.") raise AppNotFound(
f"App {app} not supported officially yet. Please provide package name in env to proceed."
)
@staticmethod @staticmethod
def support_app() -> Dict[str, str]: def support_app() -> Dict[str, str]:
@@ -100,6 +102,7 @@ class Patches(object):
app : APP app : APP
The `app` parameter is of type `APP`. It represents an instance of the `APP` class. The `app` parameter is of type `APP`. It represents an instance of the `APP` class.
""" """
self.patches_dict[app.app_name] = []
patch_loader = PatchLoader() patch_loader = PatchLoader()
patches = patch_loader.load_patches( patches = patch_loader.load_patches(
f'{config.temp_folder}/{app.resource["patches_json"]}' f'{config.temp_folder}/{app.resource["patches_json"]}'
@@ -111,20 +114,17 @@ class Patches(object):
p["app"] = "universal" p["app"] = "universal"
p["version"] = "all" p["version"] = "all"
self.patches_dict["universal_patch"].append(p) self.patches_dict["universal_patch"].append(p)
else:
for compatible_package, version in [ for compatible_package, version in [
(x["name"], x["versions"]) for x in patch["compatiblePackages"] (x["name"], x["versions"]) for x in patch["compatiblePackages"]
]: ]:
if compatible_package in self.revanced_package_names.keys(): if app.package_name == compatible_package:
app_name = self.revanced_package_names[compatible_package]
if not self.patches_dict.get(app_name, None):
self.patches_dict[app_name] = []
p = {x: patch[x] for x in ["name", "description"]} p = {x: patch[x] for x in ["name", "description"]}
p["app"] = compatible_package p["app"] = compatible_package
p["version"] = version[-1] if version else "all" p["version"] = version[-1] if version else "all"
self.patches_dict[app_name].append(p) self.patches_dict[app.app_name].append(p)
n_patches = len(self.patches_dict[app.app_name]) app.no_of_patches = len(self.patches_dict[app.app_name])
app.no_of_patches = n_patches
def __init__(self, config: RevancedConfig, app: APP) -> None: def __init__(self, config: RevancedConfig, app: APP) -> None:
self.patches_dict: Dict[str, Any] = {"universal_patch": []} self.patches_dict: Dict[str, Any] = {"universal_patch": []}
@@ -146,10 +146,6 @@ class Patches(object):
patches for the given app. The second element is a string representing the version of the patches for the given app. The second element is a string representing the version of the
patches. patches.
""" """
app_names = self.revanced_package_names
if app not in app_names.values():
raise AppNotFound(f"App {app} not supported yet.")
patches = self.patches_dict[app] patches = self.patches_dict[app]
version = "latest" version = "latest"