From 8269d0d5b6343815a05465de3bd97b488b621ac5 Mon Sep 17 00:00:00 2001 From: Radiquum Date: Wed, 3 Sep 2025 10:41:55 +0500 Subject: [PATCH] feat: read apk name when --sign arg is provided from apktool.yml --- main.py | 48 ++++++++++++++++++++++++++---------------------- requirements.txt | 3 ++- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index 75b4003..d83d1a3 100644 --- a/main.py +++ b/main.py @@ -2,18 +2,19 @@ from scripts.download_tools import check_and_download_all_tools from scripts.select_apk import get_apks, select_apk from scripts.select_patches import apply_patches, get_patches, select_patches from scripts.utils import check_java_version, compile_apk, decompile_apk, sign_apk -from config import log, console +from config import config, log, console from time import time import math - import argparse -parser = argparse.ArgumentParser(prog='anixart patcher') -parser.add_argument("--no-decompile", action='store_true') -parser.add_argument("--no-compile", action='store_true') +import yaml -parser.add_argument("--patch", action='store_true') -parser.add_argument("--sign", action='store_true') + +parser = argparse.ArgumentParser(prog="anixart patcher") +parser.add_argument("--no-decompile", action="store_true") +parser.add_argument("--no-compile", action="store_true") +parser.add_argument("--patch", action="store_true") +parser.add_argument("--sign", action="store_true") def patch(): @@ -30,51 +31,54 @@ def patch(): else: console.print(f"{status['name']}: ✘", style="bold red") statuses_err.append(status["name"]) - return patches, statuses_ok, statuses_err if __name__ == "__main__": args = parser.parse_args() - + check_and_download_all_tools() check_java_version() - if not args.patch: + if not args.patch and not args.sign: apks = get_apks() if not apks: log.fatal(f"apks folder is empty") exit(1) apk = select_apk(apks) if not apk: - log.info('cancelled') + log.info("cancelled") exit(0) - else: + elif args.patch: patch() exit(0) - - if args.sign: - sign_apk(f"{apk.removesuffix('.apk')}-patched.apk") + elif args.sign: + apkFileName = None + with open( + f"{config["folders"]["decompiled"]}/apktool.yml", "r", encoding="utf-8" + ) as f: + data = yaml.load(f.read(), Loader=yaml.Loader) + apkFileName = data.get("apkFileName", None) + if not apkFileName: + log.fatal( + f"can't find apk file name in {config['folders']['decompiled']}/apktool.yml" + ) + exit(1) + sign_apk(f"{apkFileName.removesuffix('.apk')}-patched.apk") exit(0) start_time = time() - if not args.no_decompile: decompile_apk(apk) - patches, statuses_ok, statuses_err = patch() - if not args.no_compile: compile_apk(f"{apk.removesuffix(".apk")}-patched.apk") - end_time = time() - if not args.no_compile: sign_apk(f"{apk.removesuffix(".apk")}-patched.apk") - log.info("Finished") - log.info(f"install this apk file: {apk.removesuffix(".apk")}-patched-aligned-signed.apk") + log.info(f"install this apk file: `{config["folders"]["dist"]}/{apk.removesuffix(".apk")}-patched-aligned-signed.apk`") log.info(f"used and successful patches: {", ".join(statuses_ok)}") log.info(f"used and unsuccessful patches: {", ".join(statuses_err)}") log.info(f"time taken: {math.floor(end_time - start_time)}s") diff --git a/requirements.txt b/requirements.txt index 154e25e..97fc3bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ requests lxml rich -beaupy \ No newline at end of file +beaupy +pyyaml \ No newline at end of file