Skip to content

Commit 10d91cc

Browse files
authored
🐛 Handle new v3 cli args (#339)
1 parent f7bc283 commit 10d91cc

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ venv
55
*/__pycache__*
66
*.pyc
77
/revanced-cache/
8+
/revanced-resource-cache/
89
changelog.md
910
.idea
1011
*.json

src/parser.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Revanced Parser."""
2+
from pathlib import Path
23
from subprocess import PIPE, Popen
34
from time import perf_counter
45
from typing import List, Self
@@ -17,6 +18,7 @@ class Parser(object):
1718

1819
CLI_JAR = "-jar"
1920
APK_ARG = "-a"
21+
NEW_APK_ARG = "patch"
2022
PATCHES_ARG = "-b"
2123
INTEGRATIONS_ARG = "-m"
2224
OUTPUT_ARG = "-o"
@@ -101,6 +103,21 @@ def exclude_all_patches(self: Self) -> None:
101103
if item == "-i":
102104
self._PATCHES[idx] = "-e"
103105

106+
@staticmethod
107+
def is_new_cli(cli_path: Path) -> bool:
108+
"""Check if new cli is being used."""
109+
process = Popen(["java", "-jar", cli_path, "-V"], stdout=PIPE)
110+
output = process.stdout
111+
if not output:
112+
msg = "Failed to send request for patching."
113+
raise PatchingFailedError(msg)
114+
combined_result = "".join(line.decode() for line in output)
115+
if "v3" in combined_result:
116+
logger.debug("New cli")
117+
return True
118+
logger.debug("Old cli")
119+
return False
120+
104121
# noinspection IncorrectFormatting
105122
def patch_app(
106123
self: Self,
@@ -114,10 +131,16 @@ def patch_app(
114131
The `app` parameter is an instance of the `APP` class. It represents an application that needs
115132
to be patched.
116133
"""
134+
if self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"])):
135+
apk_arg = self.NEW_APK_ARG
136+
exp = "--force"
137+
else:
138+
apk_arg = self.APK_ARG
139+
exp = "--experimental"
117140
args = [
118141
self.CLI_JAR,
119142
app.resource["cli"],
120-
self.APK_ARG,
143+
apk_arg,
121144
app.download_file_name,
122145
self.PATCHES_ARG,
123146
app.resource["patches"],
@@ -132,7 +155,7 @@ def patch_app(
132155
]
133156
if app.experiment:
134157
logger.debug("Using experimental features")
135-
args.append("--experimental")
158+
args.append(exp)
136159
args[1::2] = map(self.config.temp_folder.joinpath, args[1::2])
137160
if self.config.ci_test:
138161
self.exclude_all_patches()

0 commit comments

Comments
 (0)