mirror of
https://github.com/Radiquum/anixart-patcher.git
synced 2025-09-07 19:53:50 +05:00
parent
1c4df94d89
commit
6981ae7d84
4 changed files with 156 additions and 25 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# patch settings
|
# patch settings
|
||||||
# priority, default: 0
|
# priority, default: 0
|
||||||
priority = 0
|
priority = 100
|
||||||
|
|
||||||
# imports
|
# imports
|
||||||
## bundled
|
## bundled
|
||||||
|
@ -11,16 +11,12 @@ import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
## installed
|
|
||||||
from rich.progress import track
|
|
||||||
|
|
||||||
## custom
|
## custom
|
||||||
from config import config, log, console
|
from config import config, log
|
||||||
from scripts.smali_parser import get_smali_lines
|
from scripts.smali_parser import get_smali_lines, save_smali_lines
|
||||||
|
|
||||||
|
|
||||||
# Patch
|
# Patch
|
||||||
|
|
||||||
|
|
||||||
class PatchConfig_Compress(TypedDict):
|
class PatchConfig_Compress(TypedDict):
|
||||||
keep_dirs: list[str]
|
keep_dirs: list[str]
|
||||||
|
|
||||||
|
@ -29,12 +25,7 @@ def remove_files(patch_config: PatchConfig_Compress):
|
||||||
path = f"{config['folders']['decompiled']}/unknown"
|
path = f"{config['folders']['decompiled']}/unknown"
|
||||||
|
|
||||||
items = os.listdir(path)
|
items = os.listdir(path)
|
||||||
for item in track(
|
for item in items:
|
||||||
items,
|
|
||||||
console=console,
|
|
||||||
description="[COMPRESS]",
|
|
||||||
total=len(items),
|
|
||||||
):
|
|
||||||
item_path = f"{path}/{item}"
|
item_path = f"{path}/{item}"
|
||||||
if os.path.isfile(item_path):
|
if os.path.isfile(item_path):
|
||||||
os.remove(item_path)
|
os.remove(item_path)
|
||||||
|
@ -56,12 +47,11 @@ def remove_debug_lines():
|
||||||
file_content = get_smali_lines(file_path)
|
file_content = get_smali_lines(file_path)
|
||||||
new_content = []
|
new_content = []
|
||||||
for line in file_content:
|
for line in file_content:
|
||||||
if line.find(".line") >= 0:
|
if line.find(".line") >= 0 or line.find(".source") >= 0:
|
||||||
continue
|
continue
|
||||||
new_content.append(line)
|
new_content.append(line)
|
||||||
|
save_smali_lines(file_path, new_content)
|
||||||
|
|
||||||
with open(file_path, "w", encoding="utf-8") as f:
|
|
||||||
f.writelines(new_content)
|
|
||||||
log.debug(f"[COMPRESS] removed debug lines from: {file_path}")
|
log.debug(f"[COMPRESS] removed debug lines from: {file_path}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +105,6 @@ def apply(patch_config: PatchConfig_Compress) -> bool:
|
||||||
|
|
||||||
remove_files(patch_config)
|
remove_files(patch_config)
|
||||||
remove_debug_lines()
|
remove_debug_lines()
|
||||||
compress_pngs()
|
# compress_pngs()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
22
patches/force_static_request_urls.config.json
Normal file
22
patches/force_static_request_urls.config.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"base_url": "https://anix-api.wah.su/",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"file_path": "smali_classes2/com/swiftsoft/anixartd/network/api/ConfigApi.smali",
|
||||||
|
"value": "config/toggles"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_path": "smali_classes2/com/swiftsoft/anixartd/network/api/ProfileApi.smali",
|
||||||
|
"value": "profile/{id}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_path": "smali_classes2/com/swiftsoft/anixartd/network/api/ReleaseApi.smali",
|
||||||
|
"value": "release/{r_id}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file_path": "smali_classes2/com/swiftsoft/anixartd/network/api/EpisodeApi.smali",
|
||||||
|
"value": "episode/{releaseId}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"constants": []
|
||||||
|
}
|
102
patches/force_static_request_urls.py
Normal file
102
patches/force_static_request_urls.py
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
"""Change `value="something/endpoint"` to `value="https://example.com/something/endpoint" """
|
||||||
|
|
||||||
|
# patch settings
|
||||||
|
# priority, default: 0
|
||||||
|
priority = 0
|
||||||
|
|
||||||
|
# imports
|
||||||
|
## bundled
|
||||||
|
import os
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
|
## custom
|
||||||
|
from config import config, log
|
||||||
|
from scripts.smali_parser import (
|
||||||
|
get_smali_lines,
|
||||||
|
save_smali_lines,
|
||||||
|
find_and_replace_smali_line,
|
||||||
|
find_smali_method_start,
|
||||||
|
find_smali_method_end,
|
||||||
|
replace_smali_method_body,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Patch
|
||||||
|
class PatchConfig_ForceStaticRequestUrlsValue(TypedDict):
|
||||||
|
file_path: str
|
||||||
|
value: str
|
||||||
|
|
||||||
|
|
||||||
|
class PatchConfig_ForceStaticRequestUrlsConst(TypedDict):
|
||||||
|
file_path: str
|
||||||
|
_from: str
|
||||||
|
_to: str
|
||||||
|
|
||||||
|
|
||||||
|
class PatchConfig_ForceStaticRequestUrls(TypedDict):
|
||||||
|
base_url: str
|
||||||
|
values: PatchConfig_ForceStaticRequestUrlsValue
|
||||||
|
constants: PatchConfig_ForceStaticRequestUrlsConst
|
||||||
|
|
||||||
|
|
||||||
|
replace_should_use_mirror_urls = """ .locals 0
|
||||||
|
|
||||||
|
const/4 p0, 0x0
|
||||||
|
|
||||||
|
return p0
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def apply(patch_config: PatchConfig_ForceStaticRequestUrls) -> bool:
|
||||||
|
for value in patch_config["values"]:
|
||||||
|
if os.path.exists(f"{config['folders']['decompiled']}/{value['file_path']}"):
|
||||||
|
path = f"{config['folders']['decompiled']}/{value['file_path']}"
|
||||||
|
lines = get_smali_lines(path)
|
||||||
|
lines = find_and_replace_smali_line(
|
||||||
|
lines, value["value"], f"{patch_config['base_url']}{value['value']}"
|
||||||
|
)
|
||||||
|
save_smali_lines(path, lines)
|
||||||
|
log.debug(f"[FORCE_STATIC_REQUEST_URLS] file {path} has been modified")
|
||||||
|
|
||||||
|
for const in patch_config["constants"]:
|
||||||
|
if os.path.exists(f"{config['folders']['decompiled']}/{const['file_path']}"):
|
||||||
|
path = f"{config['folders']['decompiled']}/{const['file_path']}"
|
||||||
|
lines = get_smali_lines(path)
|
||||||
|
replace_value = ""
|
||||||
|
try:
|
||||||
|
replace_value = const["to"]
|
||||||
|
except:
|
||||||
|
replace_value = patch_config["base_url"]
|
||||||
|
lines = find_and_replace_smali_line(lines, const["from"], replace_value)
|
||||||
|
save_smali_lines(path, lines)
|
||||||
|
log.debug(f"[FORCE_STATIC_REQUEST_URLS] file {path} has been modified")
|
||||||
|
|
||||||
|
# IDK If it is actually needed, will leave it for now, but seems like it should not be needed, since patch is working
|
||||||
|
# path = f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd/Prefs.smali"
|
||||||
|
# if os.path.exists(path):
|
||||||
|
# lines = get_smali_lines(path)
|
||||||
|
# new_content = []
|
||||||
|
# for index, line in enumerate(lines):
|
||||||
|
# if line.find("SHOULD_USE_MIRROR_URLS") >= 0:
|
||||||
|
# method_start = find_smali_method_start(lines, index)
|
||||||
|
# method_end = find_smali_method_end(lines, index)
|
||||||
|
# new_content = replace_smali_method_body(
|
||||||
|
# lines, method_start, method_end, replace_should_use_mirror_urls
|
||||||
|
# )
|
||||||
|
# save_smali_lines(path, new_content)
|
||||||
|
# log.debug(f"[FORCE_STATIC_REQUEST_URLS] file {path} has been modified")
|
||||||
|
|
||||||
|
path = f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd/DaggerApp_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.smali"
|
||||||
|
pathInterceptor = f"{config['folders']['decompiled']}/smali_classes2/com/swiftsoft/anixartd/dagger/module/ApiModule$provideRetrofit$lambda$2$$inlined$-addInterceptor$1.smali"
|
||||||
|
if os.path.exists(path) and os.path.exists(pathInterceptor):
|
||||||
|
lines = get_smali_lines(path)
|
||||||
|
new_content = []
|
||||||
|
for index, line in enumerate(lines):
|
||||||
|
if line.find("addInterceptor") >= 0:
|
||||||
|
continue
|
||||||
|
new_content.append(line)
|
||||||
|
save_smali_lines(path, new_content)
|
||||||
|
log.debug(f"[FORCE_STATIC_REQUEST_URLS] file {path} has been modified")
|
||||||
|
|
||||||
|
|
||||||
|
return True
|
|
@ -4,24 +4,35 @@ def get_smali_lines(file: str) -> list[str]:
|
||||||
lines = smali.readlines()
|
lines = smali.readlines()
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
def save_smali_lines(file: str, lines: list[str]) -> None:
|
||||||
|
with open(file, "w", encoding="utf-8") as f:
|
||||||
|
f.writelines(lines)
|
||||||
|
|
||||||
|
|
||||||
def find_smali_method_start(lines: list[str], index: int) -> int:
|
def find_smali_method_start(lines: list[str], index: int) -> int:
|
||||||
while True:
|
while True:
|
||||||
index -= 1
|
index -= 1
|
||||||
if lines[index].find(".method") >= 0:
|
if lines[index].find(".method") >= 0:
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
||||||
def find_smali_method_end(lines: list[str], index: int) -> int:
|
def find_smali_method_end(lines: list[str], index: int) -> int:
|
||||||
while True:
|
while True:
|
||||||
index += 1
|
index += 1
|
||||||
if lines[index].find(".end method") >= 0:
|
if lines[index].find(".end method") >= 0:
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
|
||||||
def debug_print_smali_method(lines: list[str], start: int, end: int) -> None:
|
def debug_print_smali_method(lines: list[str], start: int, end: int) -> None:
|
||||||
while start != (end + 1):
|
while start != (end + 1):
|
||||||
print(start, lines[start])
|
print(start, lines[start])
|
||||||
start += 1
|
start += 1
|
||||||
|
|
||||||
def replace_smali_method_body(lines: list[str], start: int, end: int, new_lines: list[str]) -> list[str]:
|
|
||||||
|
def replace_smali_method_body(
|
||||||
|
lines: list[str], start: int, end: int, new_lines: list[str]
|
||||||
|
) -> list[str]:
|
||||||
new_content = []
|
new_content = []
|
||||||
index = 0
|
index = 0
|
||||||
skip = end - start - 1
|
skip = end - start - 1
|
||||||
|
@ -29,30 +40,36 @@ def replace_smali_method_body(lines: list[str], start: int, end: int, new_lines:
|
||||||
while index != (start + 1):
|
while index != (start + 1):
|
||||||
new_content.append(lines[index])
|
new_content.append(lines[index])
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
for line in new_lines:
|
for line in new_lines:
|
||||||
new_content.append(line)
|
new_content.append(line)
|
||||||
|
|
||||||
index += skip
|
index += skip
|
||||||
while index < len(lines):
|
while index < len(lines):
|
||||||
new_content.append(lines[index])
|
new_content.append(lines[index])
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
|
|
||||||
return new_content
|
return new_content
|
||||||
|
|
||||||
|
def find_and_replace_smali_line(
|
||||||
|
lines: list[str], search: str, replace: str
|
||||||
|
) -> list[str]:
|
||||||
|
for index, line in enumerate(lines):
|
||||||
|
if line.find(search) >= 0:
|
||||||
|
lines[index] = lines[index].replace(search, replace)
|
||||||
|
return lines
|
||||||
|
|
||||||
# example i guess
|
# example i guess
|
||||||
# if __name__ == "__main__":
|
# if __name__ == "__main__":
|
||||||
# lines = get_smali_lines("./decompiled/smali_classes2/com/radiquum/anixart/Prefs.smali")
|
# lines = get_smali_lines("./decompiled/smali_classes2/com/radiquum/anixart/Prefs.smali")
|
||||||
|
|
||||||
# for index, line in enumerate(lines):
|
# for index, line in enumerate(lines):
|
||||||
# if line.find("IS_SPONSOR") >= 0:
|
# if line.find("IS_SPONSOR") >= 0:
|
||||||
# method_start = find_smali_method_start(lines, index)
|
# method_start = find_smali_method_start(lines, index)
|
||||||
# method_end = find_smali_method_end(lines, index)
|
# method_end = find_smali_method_end(lines, index)
|
||||||
# new_content = replace_smali_method_body(lines, method_start, method_end, c)
|
# new_content = replace_smali_method_body(lines, method_start, method_end, c)
|
||||||
|
|
||||||
# with open("./help/Prefs_orig.smali", "w", encoding="utf-8") as file:
|
# with open("./help/Prefs_orig.smali", "w", encoding="utf-8") as file:
|
||||||
# file.writelines(lines)
|
# file.writelines(lines)
|
||||||
# with open("./help/Prefs_modified.smali", "w", encoding="utf-8") as file:
|
# with open("./help/Prefs_modified.smali", "w", encoding="utf-8") as file:
|
||||||
# file.writelines(new_content)
|
# file.writelines(new_content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue