forked from anixart-mod/patcher
Merge pull request 'Добавление патчей' (#4) from Radiquum/patcher:main into main
Reviewed-on: https://git.wowlikon.tech/anixart-mod/patcher/pulls/4
This commit is contained in:
Vendored
+6
-5
@@ -1,6 +1,7 @@
|
||||
decompiled/*
|
||||
modified/*
|
||||
original/*
|
||||
tools/*
|
||||
decompiled
|
||||
modified
|
||||
original
|
||||
tools
|
||||
|
||||
__pycache__/
|
||||
__pycache__
|
||||
.venv
|
||||
@@ -0,0 +1,33 @@
|
||||
"""Disable ad banners"""
|
||||
|
||||
priority = 0
|
||||
|
||||
from smali_parser import (
|
||||
find_smali_method_end,
|
||||
find_smali_method_start,
|
||||
get_smali_lines,
|
||||
replace_smali_method_body,
|
||||
)
|
||||
|
||||
replace = """ .locals 0
|
||||
|
||||
const/4 p0, 0x1
|
||||
|
||||
return p0
|
||||
"""
|
||||
|
||||
|
||||
def apply(config) -> bool:
|
||||
path = "./decompiled/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
|
||||
@@ -0,0 +1,39 @@
|
||||
"""Remove beta banner"""
|
||||
|
||||
priority = 0
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
from lxml import etree
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
def apply(config) -> bool:
|
||||
attributes = [
|
||||
"paddingTop",
|
||||
"paddingBottom",
|
||||
"paddingStart",
|
||||
"paddingEnd",
|
||||
"layout_width",
|
||||
"layout_height",
|
||||
"layout_marginTop",
|
||||
"layout_marginBottom",
|
||||
"layout_marginStart",
|
||||
"layout_marginEnd",
|
||||
]
|
||||
|
||||
beta_banner_xml = "./decompiled/res/layout/item_beta.xml"
|
||||
if os.path.exists(beta_banner_xml):
|
||||
parser = etree.XMLParser(remove_blank_text=True)
|
||||
tree = etree.parse(beta_banner_xml, parser)
|
||||
root = tree.getroot()
|
||||
|
||||
for attr in attributes:
|
||||
# tqdm.write(f"set {attr} = 0.0dip")
|
||||
root.set(f"{{{config["xml_ns"]['android']}}}{attr}", "0.0dip")
|
||||
|
||||
tree.write(
|
||||
beta_banner_xml, pretty_print=True, xml_declaration=True, encoding="utf-8"
|
||||
)
|
||||
|
||||
return True
|
||||
+18
-15
@@ -33,22 +33,25 @@ def apply(config: dict) -> bool:
|
||||
except:
|
||||
pass
|
||||
|
||||
rename_dir(
|
||||
"./decompiled/smali/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
"./decompiled", "smali", config["new_package_name"].replace(".", "/")
|
||||
),
|
||||
)
|
||||
rename_dir(
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
"./decompiled",
|
||||
"smali_classes2",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
),
|
||||
)
|
||||
if os.path.exists("./decompiled/smali/com/swiftsoft/anixartd"):
|
||||
rename_dir(
|
||||
"./decompiled/smali/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
"./decompiled", "smali", config["new_package_name"].replace(".", "/")
|
||||
),
|
||||
)
|
||||
if os.path.exists("./decompiled/smali_classes2/com/swiftsoft/anixartd"):
|
||||
rename_dir(
|
||||
"./decompiled/smali_classes2/com/swiftsoft/anixartd",
|
||||
os.path.join(
|
||||
"./decompiled",
|
||||
"smali_classes2",
|
||||
config["new_package_name"].replace(".", "/"),
|
||||
),
|
||||
)
|
||||
|
||||
os.rmdir("./decompiled/smali_classes2/com/swiftsoft")
|
||||
# в этой папке остаётся файл StringUtils.smali, который может быть важен
|
||||
# os.rmdir("./decompiled/smali_classes2/com/swiftsoft")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user