diff --git a/patches/change_package_name.py b/patches/change_package_name.py index 53d05d5..7467bdc 100644 --- a/patches/change_package_name.py +++ b/patches/change_package_name.py @@ -1,10 +1,8 @@ """Change package name""" priority = -10 -from tqdm import tqdm import os -import shutil from typing import TypedDict class PatchConfig_ChangePackageName(TypedDict): diff --git a/patches/disable_ad.py b/patches/disable_ad.py new file mode 100644 index 0000000..0131c90 --- /dev/null +++ b/patches/disable_ad.py @@ -0,0 +1,39 @@ +"""Disable ad banners""" + +priority = 0 +from typing import TypedDict + +from scripts.smali_parser import ( + find_smali_method_end, + find_smali_method_start, + get_smali_lines, + replace_smali_method_body, +) + + +class PatchConfig_DisableAdBanner(TypedDict): + src: str + + +replace = """ .locals 0 + + const/4 p0, 0x1 + + return p0 +""" + + +def apply(config: PatchConfig_DisableAdBanner) -> bool: + path = f"{config['src']}/smali_classes2/com/swiftsoft/anixartd/Prefs.smali" + lines = get_smali_lines(path) + for index, line in enumerate(lines): + if line.find("IS_SPONSOR") >= 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 + ) + + with open(path, "w", encoding="utf-8") as file: + file.writelines(new_content) + return True diff --git a/scripts/smali_parser.py b/scripts/smali_parser.py new file mode 100644 index 0000000..f8d1c62 --- /dev/null +++ b/scripts/smali_parser.py @@ -0,0 +1,58 @@ +def get_smali_lines(file: str) -> list[str]: + lines = [] + with open(file, "r", encoding="utf-8") as smali: + lines = smali.readlines() + return lines + +def find_smali_method_start(lines: list[str], index: int) -> int: + while True: + index -= 1 + if lines[index].find(".method") >= 0: + return index + +def find_smali_method_end(lines: list[str], index: int) -> int: + while True: + index += 1 + if lines[index].find(".end method") >= 0: + return index + +def debug_print_smali_method(lines: list[str], start: int, end: int) -> None: + while start != (end + 1): + print(start, lines[start]) + start += 1 + +def replace_smali_method_body(lines: list[str], start: int, end: int, new_lines: list[str]) -> list[str]: + new_content = [] + index = 0 + skip = end - start - 1 + + while index != (start + 1): + new_content.append(lines[index]) + index += 1 + + for line in new_lines: + new_content.append(line) + + index += skip + while index < len(lines): + new_content.append(lines[index]) + index += 1 + + + return new_content + +# example i guess +# if __name__ == "__main__": +# lines = get_smali_lines("./decompiled/smali_classes2/com/radiquum/anixart/Prefs.smali") + +# for index, line in enumerate(lines): +# if line.find("IS_SPONSOR") >= 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, c) + +# with open("./help/Prefs_orig.smali", "w", encoding="utf-8") as file: +# file.writelines(lines) +# with open("./help/Prefs_modified.smali", "w", encoding="utf-8") as file: +# file.writelines(new_content) + \ No newline at end of file