forked from anixart-mod/patcher
Добавление патча сжатия png, обновление документации
This commit is contained in:
@@ -7,22 +7,24 @@ import importlib
|
||||
import subprocess
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def init(apktool_jar_url: str, apktool_wrapper_url: str) -> dict:
|
||||
def init() -> dict:
|
||||
for directory in ["original", "modified", "patches", "tools", "decompiled"]:
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
with open("./patches/config.json", "r") as config_file:
|
||||
conf = json.load(config_file)
|
||||
|
||||
if not os.path.exists("./tools/apktool.jar"):
|
||||
try:
|
||||
print("Скачивание Apktool...")
|
||||
jar_response = requests.get(apktool_jar_url, stream=True)
|
||||
jar_response = requests.get(conf["tools"]["apktool_jar_url"], stream=True)
|
||||
jar_path = "tools/apktool.jar"
|
||||
with open(jar_path, "wb") as f:
|
||||
for chunk in jar_response.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
wrapper_response = requests.get(apktool_wrapper_url)
|
||||
wrapper_response = requests.get(conf["tools"]["apktool_wrapper_url"])
|
||||
wrapper_path = "tools/apktool"
|
||||
with open(wrapper_path, "w") as f:
|
||||
f.write(wrapper_response.text)
|
||||
@@ -47,9 +49,7 @@ def init(apktool_jar_url: str, apktool_wrapper_url: str) -> dict:
|
||||
print("Java не установлена. Установите Java 8 или более позднюю версию.")
|
||||
exit(1)
|
||||
|
||||
with open("./patches/config.json", "r") as config_file:
|
||||
return json.load(config_file)
|
||||
|
||||
return conf
|
||||
|
||||
def select_apk() -> str:
|
||||
apks = []
|
||||
@@ -106,6 +106,10 @@ class Patch:
|
||||
self.name = name
|
||||
self.package = pkg
|
||||
self.applied = False
|
||||
try:
|
||||
self.priority = pkg.priority
|
||||
except AttributeError:
|
||||
self.priority = 0
|
||||
|
||||
def apply(self, conf: dict) -> bool:
|
||||
try:
|
||||
@@ -117,10 +121,7 @@ class Patch:
|
||||
return False
|
||||
|
||||
|
||||
conf = init(
|
||||
apktool_jar_url="https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.12.0.jar",
|
||||
apktool_wrapper_url="https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool",
|
||||
)
|
||||
conf = init()
|
||||
apk = select_apk()
|
||||
patch = decompile_apk(apk)
|
||||
|
||||
@@ -131,6 +132,8 @@ for filename in os.listdir("patches/"):
|
||||
module = importlib.import_module(f"patches.{module_name}")
|
||||
patches.append(Patch(module_name, module))
|
||||
|
||||
patches.sort(key=lambda x: x.package.priority, reverse=True)
|
||||
|
||||
for patch in tqdm(patches, colour="green", desc="Применение патчей"):
|
||||
tqdm.write(f"Применение патча: {patch.name}")
|
||||
patch.apply(conf)
|
||||
|
||||
Reference in New Issue
Block a user