🔥 CLI v4

This commit is contained in:
Nikhil Badyal
2023-10-06 09:01:18 +05:30
committed by Nikhil Badyal
parent d3595e0ce8
commit 152b0619db
5 changed files with 84 additions and 47 deletions
+18 -2
View File
@@ -104,16 +104,18 @@ You can use any of the following methods to build.
### Global Config ### Global Config
| **Env Name** | **Description** | **Default** | | **Env Name** | **Description** | **Default** |
|:---------------------------------------------------------|:-------------------------------------------------:|:---------------------------------------------------------------------------------------------------------| |:---------------------------------------------------------|:-------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------|
| [PATCH_APPS](#patch-apps) | Apps to patch/build | youtube | | [PATCH_APPS](#patch-apps) | Apps to patch/build | youtube |
| [EXISTING_DOWNLOADED_APKS ](#existing-downloaded-apks) | Already downloaded clean apks | [] | | [EXISTING_DOWNLOADED_APKS ](#existing-downloaded-apks) | Already downloaded clean apks | [] |
| [PERSONAL_ACCESS_TOKEN](#personal-access-token) | Github Token to be used | None | | [PERSONAL_ACCESS_TOKEN](#personal-access-token) | Github Token to be used | None |
| DRY_RUN | Do a dry run | False | | DRY_RUN | Do a dry run | False |
| [GLOBAL_CLI_DL*](#global-resources) | DL for CLI to be used for patching apps. | [Revanced CLI](https://github.com/revanced/revanced-cli) | | [GLOBAL_CLI_DL*](#global-resources) | DL for CLI to be used for patching apps. | [Revanced CLI](https://github.com/revanced/revanced-cli) |
| [GLOBAL_PATCHES_DL*](#global-resources) | DL for Patches to be used for patching apps. | [Revanced Patches](https://github.com/revanced/revanced-patches) | | [GLOBAL_PATCHES_DL*](#global-resources) | DL for Patches to be used for patching apps. | [Revanced Patches](https://github.com/revanced/revanced-patches) |
| [GLOBAL_SPACE_FORMATTED_PATCHES*](#global-resources) | Whether patches are space formatted. | True |
| [GLOBAL_PATCHES_JSON_DL*](#global-resources) | DL for Patches Json to be used for patching apps. | [Revanced Patches](https://github.com/revanced/revanced-patches) | | [GLOBAL_PATCHES_JSON_DL*](#global-resources) | DL for Patches Json to be used for patching apps. | [Revanced Patches](https://github.com/revanced/revanced-patches) |
| [GLOBAL_INTEGRATIONS_DL*](#global-resources) | DL for Integrations to be used for patching apps. | [Revanced Integrations](https://github.com/revanced/revanced-integrations) | | [GLOBAL_INTEGRATIONS_DL*](#global-resources) | DL for Integrations to be used for patching apps. | [Revanced Integrations](https://github.com/revanced/revanced-integrations) |
| [GLOBAL_KEYSTORE_FILE_NAME*](#global-keystore-file-name) | Key file to be used for signing apps | [Builder's own key](https://github.com/nikhilbadyal/docker-py-revanced/blob/main/apks/revanced.keystore) | | [GLOBAL_KEYSTORE_FILE_NAME*](#global-keystore-file-name) | Key file to be used for signing apps | [Builder's own key](https://github.com/nikhilbadyal/docker-py-revanced/blob/main/apks/revanced.keystore) |
| [GLOBAL_OLK_KEY*](#global-keystore-file-name) | Whether key was generated with cli v4(new) or not | <br/>[Builder's v3(old) own key](https://github.com/nikhilbadyal/docker-py-revanced/blob/main/apks/revanced.keystore) |
| [GLOBAL_ARCHS_TO_BUILD*](#global-archs-to-build) | Arch to keep in the patched apk. | All | | [GLOBAL_ARCHS_TO_BUILD*](#global-archs-to-build) | Arch to keep in the patched apk. | All |
| REDDIT_CLIENT_ID | Reddit Client ID to patch reddit apps | None | | REDDIT_CLIENT_ID | Reddit Client ID to patch reddit apps | None |
| VT_API_KEY | Virus Total Key to scan APKs | None | | VT_API_KEY | Virus Total Key to scan APKs | None |
@@ -127,12 +129,14 @@ You can use any of the following methods to build.
### App Level Config ### App Level Config
| Env Name | Description | Default | | Env Name | Description | Default |
|:------------------------------------------------------------|:---------------------------------------------------------:|:-------------------------------| |:------------------------------------------------------------|:--------------------------------------------------------------------------------------------:|:-------------------------------|
| [*APP_NAME*_CLI_DL](#global-resources) | DL for CLI to be used for patching **APP_NAME**. | GLOBAL_CLI_DL | | [*APP_NAME*_CLI_DL](#global-resources) | DL for CLI to be used for patching **APP_NAME**. | GLOBAL_CLI_DL |
| [*APP_NAME*_PATCHES_DL](#global-resources) | DL for Patches to be used for patching **APP_NAME**. | GLOBAL_PATCHES_DL | | [*APP_NAME*_PATCHES_DL](#global-resources) | DL for Patches to be used for patching **APP_NAME**. | GLOBAL_PATCHES_DL |
| [*APP_NAME*_PATCHES_JSON_DL](#global-resources) | DL for Patches Json to be used for patching **APP_NAME**. | GLOBAL_PATCHES_JSON_DL | | [*APP_NAME*_PATCHES_JSON_DL](#global-resources) | DL for Patches Json to be used for patching **APP_NAME**. | GLOBAL_PATCHES_JSON_DL |
| [*APP_NAME*_SPACE_FORMATTED_PATCHES](#global-resources) | Whether patches are space formatted. **APP_NAME**. | GLOBAL_SPACE_FORMATTED_PATCHES |
| [*APP_NAME*_INTEGRATIONS_DL](#global-resources) | DL for Integrations to be used for patching **APP_NAME**. | GLOBAL_INTEGRATIONS_DL | | [*APP_NAME*_INTEGRATIONS_DL](#global-resources) | DL for Integrations to be used for patching **APP_NAME**. | GLOBAL_INTEGRATIONS_DL |
| [*APP_NAME*_KEYSTORE_FILE_NAME](#global-keystore-file-name) | Key file to be used for signing **APP_NAME**. | GLOBAL_KEYSTORE_FILE_NAME | | [*APP_NAME*_KEYSTORE_FILE_NAME](#global-keystore-file-name) | Key file to be used for signing **APP_NAME**. | GLOBAL_KEYSTORE_FILE_NAME |
| [*APP_NAME*_OLD_KEY](#global-keystore-file-name) | Whether key used was generated with cli > v4(new) <br/><br/>**APP_NAME**. <br/> <br/> | GLOBAL_OLK_KEY |
| [*APP_NAME*_ARCHS_TO_BUILD](#global-archs-to-build) | Arch to keep in the patched **APP_NAME**. | GLOBAL_ARCHS_TO_BUILD | | [*APP_NAME*_ARCHS_TO_BUILD](#global-archs-to-build) | Arch to keep in the patched **APP_NAME**. | GLOBAL_ARCHS_TO_BUILD |
| [*APP_NAME*_EXCLUDE_PATCH**](#custom-exclude-patching) | Patches to exclude while patching **APP_NAME**. | [] | | [*APP_NAME*_EXCLUDE_PATCH**](#custom-exclude-patching) | Patches to exclude while patching **APP_NAME**. | [] |
| [*APP_NAME*_INCLUDE_PATCH**](#custom-include-patching) | Patches to include while patching **APP_NAME**. | [] | | [*APP_NAME*_INCLUDE_PATCH**](#custom-include-patching) | Patches to include while patching **APP_NAME**. | [] |
@@ -288,6 +292,9 @@ You can use any of the following methods to build.
If you have want to provide resource locally in the apks folder. You can specify that by mentioning filename If you have want to provide resource locally in the apks folder. You can specify that by mentioning filename
prefixed with `local://`. prefixed with `local://`.
*Note* - The link provided must be DLs. Unless they are from GitHub. *Note* - The link provided must be DLs. Unless they are from GitHub.
*Note* - Some of the patch source like inotia00 still provides **-** seperated patches while revanced shifted to
Space formatted patches. Use `SPACE_FORMATTED_PATCHES` to define the type of patches.
8. <a id="global-keystore-file-name"></a>If you don't want to use default keystore. You can provide your own by 8. <a id="global-keystore-file-name"></a>If you don't want to use default keystore. You can provide your own by
placing it inside `apks` folder. And adding the name of `keystore-file` in `.env` file or in `ENVS` in `GitHub placing it inside `apks` folder. And adding the name of `keystore-file` in `.env` file or in `ENVS` in `GitHub
secrets` (Recommended) in the format secrets` (Recommended) in the format
@@ -300,6 +307,15 @@ You can use any of the following methods to build.
```dotenv ```dotenv
YOUTUBE_KEYSTORE_FILE_NAME=youtube.keystore YOUTUBE_KEYSTORE_FILE_NAME=youtube.keystore
``` ```
Note - If you are using your own keystore.And it was generated with cli > v4 Add
Example:
```dotenv
GLOBAL_OLD_KEY=False
```
if you are using different key for different apps. You need to specify at app level.
```dotenv
YOUTUBE_OLD_KEY=False
```
9. <a id="global-archs-to-build"></a>You can build only for a particular arch in order to get smaller apk files.This 9. <a id="global-archs-to-build"></a>You can build only for a particular arch in order to get smaller apk files.This
can be done with by adding comma separated `ARCHS_TO_BUILD` in `ENVS` in `GitHub secrets` (Recommended) in the can be done with by adding comma separated `ARCHS_TO_BUILD` in `ENVS` in `GitHub secrets` (Recommended) in the
format. format.
-2
View File
@@ -6,7 +6,6 @@ from loguru import logger
from src.app import APP from src.app import APP
from src.config import RevancedConfig from src.config import RevancedConfig
from src.downloader.download import Downloader
from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError
from src.parser import Parser from src.parser import Parser
from src.patches import Patches from src.patches import Patches
@@ -25,7 +24,6 @@ def main() -> None:
env = Env() env = Env()
env.read_env() env.read_env()
config = RevancedConfig(env) config = RevancedConfig(env)
Downloader.extra_downloads(config)
if not config.dry_run: if not config.dry_run:
check_java() check_java()
+5
View File
@@ -42,6 +42,11 @@ class APP(object):
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 = package_name self.package_name = package_name
self.old_key = config.env.bool(f"{app_name}_OLD_KEY".upper(), config.global_old_key)
self.space_formatted = config.env.bool(
f"{app_name}_SPACE_FORMATTED_PATCHES".upper(),
config.global_space_formatted,
)
def download_apk_for_patching(self: Self, config: RevancedConfig) -> None: def download_apk_for_patching(self: Self, config: RevancedConfig) -> None:
"""Download apk to be patched.""" """Download apk to be patched."""
+2
View File
@@ -34,3 +34,5 @@ class RevancedConfig(object):
self.apk_editor = "apkeditor-output.jar" self.apk_editor = "apkeditor-output.jar"
self.extra_download_files.append("https://github.com/REAndroid/APKEditor@apkeditor.jar") self.extra_download_files.append("https://github.com/REAndroid/APKEditor@apkeditor.jar")
self.apps = env.list("PATCH_APPS", default_build) self.apps = env.list("PATCH_APPS", default_build)
self.global_old_key = env.bool("GLOBAL_OLD_KEY", True)
self.global_space_formatted = env.bool("GLOBAL_SPACE_FORMATTED_PATCHES", True)
+21 -5
View File
@@ -110,6 +110,17 @@ class Parser(object):
patches_dict: dict[str, str], patches_dict: dict[str, str],
) -> None: ) -> None:
"""The function `include_exclude_patch` includes and excludes patches for a given app.""" """The function `include_exclude_patch` includes and excludes patches for a given app."""
if app.space_formatted:
for patch in patches:
normalized_patch = patch["name"].lower().replace(" ", "-")
self.include(patch["name"]) if normalized_patch not in app.exclude_request else self.exclude(
patch["name"],
)
for normalized_patch in app.include_request:
self.include(normalized_patch.lower().replace("-", " ")) if normalized_patch not in patches_dict[
"universal_patch"
] else ()
else:
for patch in patches: for patch in patches:
normalized_patch = patch["name"].lower().replace(" ", "-") normalized_patch = patch["name"].lower().replace(" ", "-")
self.include(normalized_patch) if normalized_patch not in app.exclude_request else self.exclude( self.include(normalized_patch) if normalized_patch not in app.exclude_request else self.exclude(
@@ -119,7 +130,7 @@ class Parser(object):
self.include(normalized_patch) if normalized_patch not in patches_dict["universal_patch"] else () self.include(normalized_patch) if normalized_patch not in patches_dict["universal_patch"] else ()
@staticmethod @staticmethod
def is_new_cli(cli_path: Path) -> bool: def is_new_cli(cli_path: Path) -> tuple[bool, str]:
"""Check if new cli is being used.""" """Check if new cli is being used."""
process = Popen(["java", "-jar", cli_path, "-V"], stdout=PIPE) process = Popen(["java", "-jar", cli_path, "-V"], stdout=PIPE)
output = process.stdout output = process.stdout
@@ -127,11 +138,11 @@ class Parser(object):
msg = "Failed to send request for patching." msg = "Failed to send request for patching."
raise PatchingFailedError(msg) raise PatchingFailedError(msg)
combined_result = "".join(line.decode() for line in output) combined_result = "".join(line.decode() for line in output)
if "v3" in combined_result: if "v3" in combined_result or "v4" in combined_result:
logger.debug("New cli") logger.debug("New cli")
return True return True, combined_result
logger.debug("Old cli") logger.debug("Old cli")
return False return False, combined_result
# noinspection IncorrectFormatting # noinspection IncorrectFormatting
def patch_app( def patch_app(
@@ -146,7 +157,8 @@ class Parser(object):
The `app` parameter is an instance of the `APP` class. It represents an application that needs The `app` parameter is an instance of the `APP` class. It represents an application that needs
to be patched. to be patched.
""" """
if self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"])): is_new, version = self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"]))
if is_new:
apk_arg = self.NEW_APK_ARG apk_arg = self.NEW_APK_ARG
exp = "--force" exp = "--force"
else: else:
@@ -172,6 +184,10 @@ class Parser(object):
logger.debug("Using experimental features") logger.debug("Using experimental features")
args.append(exp) args.append(exp)
args[1::2] = map(self.config.temp_folder.joinpath, args[1::2]) args[1::2] = map(self.config.temp_folder.joinpath, args[1::2])
if app.old_key and "v4" in version:
# https://github.com/ReVanced/revanced-cli/issues/272#issuecomment-1740587534
old_key_flags = ["--alias=alias", "--keystore-entry-password=ReVanced", "--keystore-password=ReVanced"]
args.extend(old_key_flags)
if self.config.ci_test: if self.config.ci_test:
self.exclude_all_patches() self.exclude_all_patches()
if self._PATCHES: if self._PATCHES: