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
|
@ -4,24 +4,35 @@ def get_smali_lines(file: str) -> list[str]:
|
|||
lines = smali.readlines()
|
||||
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:
|
||||
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]:
|
||||
|
||||
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
|
||||
|
@ -29,30 +40,36 @@ def replace_smali_method_body(lines: list[str], start: int, end: int, new_lines:
|
|||
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
|
||||
|
||||
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
|
||||
# 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)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue