From 9e8dcd461110de1cb20bb44b17cf92ad929a4adc Mon Sep 17 00:00:00 2001 From: AlexisHamon <65979197+AlexisHamon@users.noreply.github.com> Date: Wed, 8 Sep 2021 23:03:33 +0200 Subject: [PATCH] getApktoolVersion patch https://github.com/NickstaDB/patch-apk/issues/27 args"apktool.bat" instead "apktool" for nt Same method as runApkTool() to avoid PAUSE --- patch-apk.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/patch-apk.py b/patch-apk.py index f666cd7..8c4a40d 100755 --- a/patch-apk.py +++ b/patch-apk.py @@ -152,8 +152,13 @@ def getObjectionVersion(): # Get apktool version #################### def getApktoolVersion(): - proc = subprocess.run(["apktool", "-version"], stdout=subprocess.PIPE) - return pkg_resources.parse_version(proc.stdout.decode("utf-8").strip().split("-")[0].strip()) + if os.name == "nt": + #apktool.bat has a dirty hack that execute "pause", so we need a dirty hack to kill the pause command... + proc = subprocess.Popen(["apktool.bat", "-version"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + return proc.communicate(b"\r\n")[0].decode("utf-8").strip().split("\r\n")[0] + else: + proc = subprocess.run(["apktool", "-version"], stdout=subprocess.PIPE) + return proc.stdout.decode("utf-8").strip().split("-")[0].strip() #################### # Wrapper to run apktool platform-independently, complete with a dirty hack to fix apktool's dirty hack. @@ -307,7 +312,7 @@ def combineSplitAPKs(pkgname, localapks, tmppath, disableStylesHack): if ret.returncode != 0: print("Error: Failed to run 'apktool b " + baseapkdir + "'.\nRun with --debug-output for more information.") sys.exit(1) - elif getApktoolVersion() > pkg_resources.parse_version("2.4.2"): + elif pkg_resources.parse_version(getApktoolVersion()) > pkg_resources.parse_version("2.4.2"): print("[+] Found apktool version > 2.4.2, rebuilding with 'apktool --use-aapt2'.") ret = runApkTool(["--use-aapt2", "b", baseapkdir]) if ret.returncode != 0: