diff --git a/main.py b/main.py index a4ec073..9b147ef 100644 --- a/main.py +++ b/main.py @@ -30,14 +30,17 @@ class ToolsConfig(BaseModel): apktool_jar_url: str apktool_wrapper_url: str + class XmlNamespaces(BaseModel): android: str app: str + class BaseSection(BaseModel): tools: ToolsConfig xml_ns: XmlNamespaces + class Config(BaseModel): base: BaseSection patches: dict @@ -88,7 +91,9 @@ def init(): if not (TOOLS / "apktool.jar").exists(): download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar") - wrapper = httpx.get(conf.base.tools.apktool_wrapper_url, timeout=30).text + wrapper = httpx.get( + conf.base.tools.apktool_wrapper_url, timeout=30, follow_redirects=True + ).text (TOOLS / "apktool").write_text(wrapper, encoding="utf-8") (TOOLS / "apktool").chmod(0o755) @@ -138,7 +143,18 @@ def select_apk() -> Path: def decompile(apk: Path): console.print("[yellow]Декомпиляция apk...") - run(["java", "-jar", str(TOOLS / "apktool.jar"), "d", "-f", "-o", str(DECOMPILED), str(apk)]) + run( + [ + "java", + "-jar", + str(TOOLS / "apktool.jar"), + "d", + "-f", + "-o", + str(DECOMPILED), + str(apk), + ] + ) def compile(apk: Path, patches: List[Patch]): @@ -147,22 +163,43 @@ def compile(apk: Path, patches: List[Patch]): aligned = out_apk.with_stem(out_apk.stem + "-aligned") signed = out_apk.with_stem(out_apk.stem + "-mod") - run(["java", "-jar", str(TOOLS / "apktool.jar"), "b", str(DECOMPILED), "-o", str(out_apk)]) + run( + [ + "java", + "-jar", + str(TOOLS / "apktool.jar"), + "b", + str(DECOMPILED), + "-o", + str(out_apk), + ] + ) run(["zipalign", "-v", "4", str(out_apk), str(aligned)]) - run([ - "apksigner", "sign", - "--v1-signing-enabled", "false", - "--v2-signing-enabled", "true", - "--v3-signing-enabled", "true", - "--ks", "keystore.jks", - "--ks-pass", "file:keystore.pass", - "--out", str(signed), - str(aligned) - ]) + run( + [ + "apksigner", + "sign", + "--v1-signing-enabled", + "false", + "--v2-signing-enabled", + "true", + "--v3-signing-enabled", + "true", + "--ks", + "keystore.jks", + "--ks-pass", + "file:keystore.pass", + "--out", + str(signed), + str(aligned), + ] + ) with open(DECOMPILED / "apktool.yml", encoding="utf-8") as f: meta = yaml.safe_load(f) - version_str = " ".join(f"{k}:{v}" for k, v in meta.get("versionInfo", {}).items()) + version_str = " ".join( + f"{k}:{v}" for k, v in meta.get("versionInfo", {}).items() + ) with open(MODIFIED / "report.log", "w", encoding="utf-8") as f: f.write(f"anixart mod {version_str}\n") @@ -200,16 +237,16 @@ def build( with Progress() as progress: task = progress.add_task("Патчи", total=len(patch_objs)) for p in patch_objs: - ok = p.apply( - patch_settings.get(p.name, {}) | conf.get("base", {}) - ) + ok = p.apply(patch_settings.get(p.name, {}) | conf.get("base", {})) progress.console.print(f"{'✔' if ok else '✘'} {p.name}") progress.advance(task) successes = sum(p.applied for p in patch_objs) if successes == len(patch_objs): compile(apk, patch_objs) - elif successes > 0 and (force or Prompt.ask("Продолжить сборку?", choices=["y", "n"]) == "y"): + elif successes > 0 and ( + force or Prompt.ask("Продолжить сборку?", choices=["y", "n"]) == "y" + ): compile(apk, patch_objs) else: console.print("[red]Сборка отменена")