Ghost mode for stories and chats, several photos in one comment, .ltp plugins (rights, defender, rollback, downloads only with consent), custom chat bubbles with a text colour of your choice, the lihont-ltp SDK and the plugin docs, streak flames as widgets with a keeper, avatar shapes, Material 3 surfaces. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
180 lines
7.9 KiB
Python
180 lines
7.9 KiB
Python
"""Patch TikTok 47.1.3 settings composables to inject native mod settings row and MD3 icons."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
|
|
RENDERER_CLASS = "LX/1DvK;"
|
|
GROUP_CLASS = "LX/1DuR;"
|
|
DRAW_HOOK = "Llihont/two/settings/SettingsCell;->draw(ZLjava/lang/Object;)Z"
|
|
CELL_CLASS = "LX/0LDm;"
|
|
# The icon the settings cell shows before the Material 3 painter takes over. The 47.1.3 build used a fixed constant of
|
|
# LX/0LB8;; on another TikTok version (LIHONT_PORT_MAP set) that class is not known, so the cell keeps its default icon.
|
|
SETTINGS_ICON = "" if os.environ.get("LIHONT_PORT_MAP") else "LX/0LB8;->LLLLIIL:LX/0LGU;"
|
|
PAINTER_CLASS = "Llihont/two/settings/Md3BadgePainter;"
|
|
|
|
|
|
def rewrite_1dvk(text: str) -> str:
|
|
"""Inject lihont(...) composable into LX/1DvK that renders 'Настройки мода' cell.
|
|
|
|
The anchors are patterns that ignore register numbers, label names, `.line` numbers and the names of TikTok's
|
|
synthetic lambda classes, so they hold on other TikTok versions as well (see lihont/portmap.py).
|
|
"""
|
|
if "lihont(" in text:
|
|
raise ValueError("lihont method already present in LX/1DvK")
|
|
|
|
m_match = re.search(
|
|
r"(?ms)^\.method public static final LIZ\(LX/0CWi;ZZLX/0LYA;I\)V\n(.*?)\n\.end method",
|
|
text,
|
|
)
|
|
if not m_match:
|
|
raise ValueError("LX/1DvK;->LIZ method not found")
|
|
|
|
body = m_match.group(1)
|
|
noise = r"(?:[ \t]*\.line [0-9]+\n|[ \t]*\n)*"
|
|
|
|
# the recomposition callback: new Lambda(this, ...) is replaced by SettingsCell.again(...)
|
|
recomposition = re.compile(
|
|
r"[ \t]*new-instance v0, (L[\w/$]+;)\n" + noise +
|
|
r"[ \t]*const/16 v11, 0x[0-9a-f]+\n" + noise +
|
|
r"[ \t]*move-object v6, v0\n" + noise +
|
|
r"[ \t]*move-object v7, (v\d+)\n" + noise +
|
|
r"[ \t]*move v8, (v\d+)\n" + noise +
|
|
r"[ \t]*move v9, (v\d+)\n" + noise +
|
|
r"[ \t]*move v10, (v\d+)\n" + noise +
|
|
r"[ \t]*invoke-direct/range \{v6 \.\. v11\}, \1-><init>\(LX/0CWi;ZZII\)V"
|
|
)
|
|
found = recomposition.search(body)
|
|
if found is None:
|
|
raise ValueError("LX/1DvK;->LIZ recomposition callback pattern not found")
|
|
body = body[:found.start()] + (
|
|
" invoke-static {%s, %s, %s, %s}, Llihont/two/settings/SettingsCell;->again(Ljava/lang/Object;ZZI)Ljava/lang/Object;\n\n"
|
|
" move-result-object v0\n\n"
|
|
" check-cast v0, Lkotlin/jvm/functions/Function2;"
|
|
) % found.group(2, 3, 4, 5) + body[found.end():]
|
|
|
|
# the title and the icon of the cell
|
|
title_icon = re.compile(
|
|
r"[ \t]*iget-object v0, v5, LX/0CWi;->\w+:Ljava/lang/Integer;\n" + noise +
|
|
r"[ \t]*const/4 v12, 0x0\n" + noise +
|
|
r"[ \t]*if-eqz v0, :(cond_\w+)\n" + noise +
|
|
r"[ \t]*invoke-virtual \{v0\}, Ljava/lang/Integer;->intValue\(\)I\n" + noise +
|
|
r"[ \t]*move-result v0\n" + noise +
|
|
r"[ \t]*:(goto_\w+)\n"
|
|
r"[ \t]*invoke-static \{v0, v6\}, LX/0KwU;->LIZIZ\(ILX/0LYA;\)Ljava/lang/String;\n" + noise +
|
|
r"[ \t]*move-result-object v11\n" + noise +
|
|
r"[ \t]*const/4 v10, 0x0\n" + noise +
|
|
r"[ \t]*iget-object v0, v5, LX/0CWi;->\w+:LX/0LGU;\n" + noise +
|
|
r"[ \t]*if-nez v0, :(cond_\w+)\n" + noise +
|
|
r"[ \t]*sget-object v0, LX/0L1b;->LIZ:LX/0LGU;\n" + noise +
|
|
r"[ \t]*:\3\n"
|
|
r"[ \t]*invoke-static \{v0, v6\}, LX/0Lis;->LJFF\(LX/0LGU;LX/0LYA;\)LX/0MIo;"
|
|
)
|
|
found = title_icon.search(body)
|
|
if found is None:
|
|
raise ValueError("LX/1DvK;->LIZ title/icon pattern not found")
|
|
miss_label, goto_label = found.group(1), found.group(2)
|
|
icon = SETTINGS_ICON or "LX/0L1b;->LIZ:LX/0LGU;"
|
|
body = body[:found.start()] + (
|
|
" invoke-static {}, Llihont/two/settings/SettingsCell;->title()Ljava/lang/String;\n\n"
|
|
" move-result-object v11\n\n"
|
|
" const/4 v12, 0x0\n\n"
|
|
" const/4 v10, 0x0\n\n"
|
|
" sget-object v0, " + icon + "\n\n"
|
|
" invoke-static {v0, v6}, LX/0Lis;->LJFF(LX/0LGU;LX/0LYA;)LX/0MIo;"
|
|
) + body[found.end():]
|
|
|
|
# the branch that used to supply a missing icon number is gone together with the code that jumped to it
|
|
miss_block = re.compile(
|
|
r"(?m)^\s*:" + miss_label + r"\s*\n\s*const/4 v0, 0x0\s*\n(?:\s*\.line [0-9]+\s*\n)*\s*goto :" + goto_label + r"\s*\n?"
|
|
)
|
|
if not miss_block.search(body):
|
|
raise ValueError("LX/1DvK;->LIZ %s block not found" % miss_label)
|
|
body = miss_block.sub("", body)
|
|
|
|
click_pattern = re.compile(
|
|
r"(?ms)new-instance v9, (L[\w/$]+;)(?:(?!new-instance).)*?"
|
|
r"invoke-direct \{v9, v5, v1, v0\}, \1-><init>\(LX/0CWi;Landroid/content/Context;I\)V"
|
|
)
|
|
if click_pattern.search(body):
|
|
body = click_pattern.sub(
|
|
"invoke-static {v1}, Llihont/two/settings/SettingsCell;->onClick(Ljava/lang/Object;)Ljava/lang/Object;\n\n move-result-object v9",
|
|
body,
|
|
)
|
|
|
|
body = re.sub(
|
|
r" iget-object (v\d+), v5, LX/0CWi;->LL:Lkotlin/jvm/functions/Function1;",
|
|
r" const/4 \1, 0x0",
|
|
body,
|
|
count=1,
|
|
)
|
|
|
|
lihont_method = (
|
|
"\n.method public static final lihont(LX/0CWi;ZZLX/0LYA;I)V\n"
|
|
+ body
|
|
+ "\n.end method\n"
|
|
)
|
|
return text + lihont_method
|
|
|
|
|
|
def rewrite_1dur(text: str) -> str:
|
|
"""Inject SettingsCell.draw before ManagePostsVM in LX/1DuR;->LJIIIZ."""
|
|
if DRAW_HOOK in text:
|
|
raise ValueError("SettingsCell.draw already present in LX/1DuR")
|
|
|
|
# The call that draws the ManagePostsVM cell; the numbers after `.line` differ between TikTok versions.
|
|
anchor = re.compile(
|
|
r"([ \t]*const/4 v14, 0x4\n\n(?:[ \t]*\.line [0-9]+\n)*[ \t]*move-object v12, v6\n\n)"
|
|
r"((?:[ \t]*\.line [0-9]+\n)*[ \t]*invoke-static/range \{v9 \.\. v14\}, LX/1Dvf;->LIZIZ\("
|
|
r"ZZLcom/ss/android/ugc/aweme/setting/ui/rvmpcompose/group/top/cell/ManagePostsVM;LX/0LYA;II\)V)"
|
|
)
|
|
found = anchor.search(text)
|
|
if found is None:
|
|
raise ValueError("LX/1DuR ManagePostsVM anchor not found")
|
|
|
|
injection = (
|
|
" # LihonT 2.0 native settings cell injection: 47.1.3\n"
|
|
f" invoke-static {{v9, v6}}, {DRAW_HOOK}\n\n"
|
|
" move-result v9\n\n"
|
|
)
|
|
return text[:found.start()] + found.group(1) + injection + found.group(2) + text[found.end():]
|
|
|
|
|
|
def rewrite_0ldm(text: str) -> str:
|
|
"""Inject Material 3 icon transformation into LX/0LDm;->LIZ and upgrade card corner radius."""
|
|
if "SettingsCell;->transformIcon" in text:
|
|
raise ValueError("transformIcon hook already present in LX/0LDm")
|
|
|
|
# Upgrade settings card corner radius from 12dp to Material 3 standard 24dp (0x18)
|
|
clinit_corner = re.search(
|
|
r"const/16 v0, 0xc\s*\n(?:\s*\.line [0-9]+\s*\n)*\s*int-to-float v0, v0\s*\n(?:\s*\.line [0-9]+\s*\n)*\s*sput v0, LX/0LDm;->LIZLLL:F",
|
|
text,
|
|
)
|
|
if clinit_corner:
|
|
text = text.replace(
|
|
clinit_corner.group(0),
|
|
clinit_corner.group(0).replace("const/16 v0, 0xc", "const/16 v0, 0x18"),
|
|
1,
|
|
)
|
|
|
|
pattern = re.compile(
|
|
r"(\.method public static final LIZ\(LX/0M1d;[^\n]+\n.*?\.prologue\n(?:\s*\.line [0-9]+\n)?)(\s*move-object/from16 [vp]\d+, p20)",
|
|
re.DOTALL
|
|
)
|
|
m = pattern.search(text)
|
|
if not m:
|
|
raise ValueError("LX/0LDm;->LIZ prologue anchor not found")
|
|
|
|
injection = (
|
|
" # LihonT 2.0 Material 3 settings icon hook\n"
|
|
" move-object/from16 v0, p8\n"
|
|
" move-object/from16 v1, p1\n"
|
|
" move-object/from16 v2, p25\n"
|
|
" invoke-static {v0, v1, v2}, Llihont/two/settings/SettingsCell;->transformIcon(Ljava/lang/Object;Ljava/lang/CharSequence;Ljava/lang/Object;)Ljava/lang/Object;\n"
|
|
" move-result-object v0\n"
|
|
" check-cast v0, LX/0LRh;\n"
|
|
" move-object/from16 p8, v0\n\n"
|
|
)
|
|
text = pattern.sub(r"\1" + injection + r"\2", text, count=1)
|
|
return text
|