mirror of
https://github.com/Radiquum/anixart-patcher.git
synced 2025-09-06 03:03:50 +05:00
feat: add compile and sign of apk
This commit is contained in:
parent
b6c058c40f
commit
4ec18d7dd4
3 changed files with 70 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,4 +5,5 @@ original
|
||||||
tools
|
tools
|
||||||
decompiled
|
decompiled
|
||||||
dist
|
dist
|
||||||
__pycache__
|
__pycache__
|
||||||
|
keystore.jks
|
23
main.py
23
main.py
|
@ -1,9 +1,11 @@
|
||||||
from scripts.download_tools import check_and_download_all_tools
|
from scripts.download_tools import check_and_download_all_tools
|
||||||
from scripts.select_apk import get_apks, select_apk
|
from scripts.select_apk import get_apks, select_apk
|
||||||
from scripts.select_patches import apply_patches, get_patches, select_patches
|
from scripts.select_patches import apply_patches, get_patches, select_patches
|
||||||
from scripts.utils import check_java_version, decompile_apk
|
from scripts.utils import check_java_version, compile_apk, decompile_apk, sign_apk
|
||||||
from config import log, console
|
from config import log, console
|
||||||
|
|
||||||
|
from time import time
|
||||||
|
import math
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_and_download_all_tools()
|
check_and_download_all_tools()
|
||||||
|
@ -15,15 +17,30 @@ if __name__ == "__main__":
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
apk = select_apk(apks)
|
apk = select_apk(apks)
|
||||||
|
|
||||||
|
start_time = time()
|
||||||
decompile_apk(apk)
|
decompile_apk(apk)
|
||||||
|
|
||||||
patches = get_patches()
|
patches = get_patches()
|
||||||
patches = select_patches(patches)
|
patches = select_patches(patches)
|
||||||
|
|
||||||
statuses = apply_patches(patches)
|
statuses = apply_patches(patches)
|
||||||
|
statuses_ok = []
|
||||||
|
statuses_err = []
|
||||||
|
|
||||||
for status in statuses:
|
for status in statuses:
|
||||||
if status["status"]:
|
if status["status"]:
|
||||||
console.print(f"{status['name']}: ✔", style="bold green")
|
console.print(f"{status['name']}: ✔", style="bold green")
|
||||||
|
statuses_ok.append(status["name"])
|
||||||
else:
|
else:
|
||||||
console.print(f"{status['name']}: ✘", style="bold red")
|
console.print(f"{status['name']}: ✘", style="bold red")
|
||||||
|
statuses_err.append(status["name"])
|
||||||
|
|
||||||
|
compile_apk(f"{apk.removesuffix(".apk")}-patched.apk")
|
||||||
|
sign_apk(f"{apk.removesuffix(".apk")}-patched.apk")
|
||||||
|
end_time = time()
|
||||||
|
|
||||||
|
log.info("Finished")
|
||||||
|
log.info(f"install this apk file: {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")
|
||||||
|
|
|
@ -41,3 +41,51 @@ def decompile_apk(apk: str):
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
log.fatal(f"error of running a command: %s", e.stderr, exc_info=True)
|
log.fatal(f"error of running a command: %s", e.stderr, exc_info=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def compile_apk(apk: str):
|
||||||
|
if not os.path.exists(config["folders"]["dist"]):
|
||||||
|
log.info(f"creating `dist` folder: {config['folders']['dist']}")
|
||||||
|
os.mkdir(config["folders"]["dist"])
|
||||||
|
else:
|
||||||
|
log.info(f"resetting `dist` folder: {config['folders']['dist']}")
|
||||||
|
shutil.rmtree(config["folders"]["dist"])
|
||||||
|
os.mkdir(config["folders"]["dist"])
|
||||||
|
|
||||||
|
log.info(f"compile apk: `{apk}`")
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
f"java -jar {config['folders']['tools']}/apktool.jar b -f -o {config['folders']['dist']}/{apk} {config['folders']['decompiled']}",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
text=True,
|
||||||
|
# stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
log.fatal(f"error of running a command: %s", e.stderr, exc_info=True)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def sign_apk(apk: str):
|
||||||
|
log.info(f"sign and align apk: `{apk}`")
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
f"zipalign -p 4 {config['folders']['dist']}/{apk} {config['folders']['dist']}/{apk.removesuffix(".apk")}-aligned.apk",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
text=True,
|
||||||
|
# stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
result = subprocess.run(
|
||||||
|
f"apksigner sign --ks ./keystore.jks --out {config['folders']['dist']}/{apk.removesuffix(".apk")}-aligned-signed.apk {config['folders']['dist']}/{apk.removesuffix(".apk")}-aligned.apk",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
text=True,
|
||||||
|
# stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
log.fatal(f"error of running a command: %s", e.stderr, exc_info=True)
|
||||||
|
exit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue