ZaStoGram/TMessagesProj/jni/zsg_naive/tests/check_hooks.py
loop-uh eb435ec451
Some checks failed
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 47s
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 53s
ZaStoGram source guards / guards (push) Failing after 17s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 48s
WSS: Cloudflare fronts send the zone as TLS server name, plain ws:// step, self-updating front list
Every front put kwsN.<zone> into the clear-text SNI, one pattern a network can
match to cut all of them at once. The zone is now the SNI and kwsN.<zone>
travels only in the encrypted Host header (101 on 40/40 front x DC2/DC4).

- A plain ws:// step (port 80) follows the TLS fronts, with its own health
  record (cdn-plain-kwsN); a pooled spare stays on its step.
- The front catalog is refreshed from the tg-ws-proxy list (GitHub, jsDelivr
  mirror) by WssFrontsUpdater at most daily into wss_fronts.txt; native
  validates it as a whole and a front without a baked address is dialled by name.
- naive-core pinned to 1f9bbfd (sni and plain fields); host tests cover TLS,
  plain and the catalog; guards updated for the new DC203 chain.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 12:41:26 -05:00

48 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""Guard: every fork hook of the Naive module outside jni/zsg_naive/ must still be present.
An upstream merge that silently drops one of these lines would leave the module compiled but unused (or not
compiling). Run from anywhere: python3 TMessagesProj/jni/zsg_naive/tests/check_hooks.py
"""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[4] # repository root (android/)
JNI = ROOT / "TMessagesProj/jni"
JAVA = ROOT / "TMessagesProj/src/main/java/org/telegram"
RES = ROOT / "TMessagesProj/src/main/res"
HOOKS = {
JNI / "CMakeLists.txt": ["include(zsg_naive/zsg_naive.cmake)", "zsg_naive_socket"],
JNI / "tgnet/ConnectionSocket.cpp": [
'#include "../zsg_naive/NaiveSocket.h"',
"const bool useNaive = proxyOptions.naive && !proxyAddress->empty();",
"tgnet::naive::RouteFor(*proxyAddress, proxyPort)",
"tgnet::naive::CreateFor(*proxyAddress, proxyPort,",
'std::strcmp(currentWssTransport->transportName(), "naive") == 0',
],
JNI / "tgnet/Connection.cpp": ["overrideMtProxyOptions.naive"],
JNI / "tgnet/wss/WssSocket.cpp": ["zsg_ws_new(&config", "zsg_ws_send(client", 'config.subprotocol = "binary"'],
JNI / "mtproxy/MtProxyOptions.h": ["bool naive = false;", "naive == other.naive", "normalized.naive = options.naive;"],
JNI / "TgNetWrapper.cpp": ["jclass_MtProxyOptions_naive", '"naive", "Z"', "RegisterWebProxyJni"],
JAVA / "tgnet/MtProxyOptions.java": ["public final boolean naive;", "public static MtProxyOptions naive()"],
JAVA / "tgnet/ConnectionsManager.java": ["MtProxyOptions.naive()", "MtProxyOptions.naive(), activationGeneration", "NaiveWebProxy.apply(hasSelectedProxy ? settings : null)", "NaiveWebProxy.apply(proxySettings)", "WssFrontsUpdater.start(configPath)"],
JAVA / "proxy/ProxySettings.java": ["NAIVE", "case NAIVE:", "Type.NAIVE"],
JAVA / "proxy/ProxyWssFallback.java": ["getType() != ProxySettings.Type.NAIVE"],
JAVA / "messenger/ProxyLinkHelper.java": ["TYPE_NAIVE", "ProxySettings.Type.NAIVE"],
# the last entry is not a Naive hook: the 13.2.1 upstream merge dropped that line and left the proxy screen blank (restored 2026-11-25)
JAVA / "ui/ProxySettingsActivity.java": ["TYPE_NAIVE", "R.string.UseProxyNaive", "scrollView.addView(linearLayout2, new ScrollView.LayoutParams("],
RES / "values/strings.xml": ['name="UseProxyNaive"', 'name="UseProxyNaiveInfo"'],
}
missing = []
for path, needles in HOOKS.items():
text = path.read_text(encoding="utf-8", errors="replace") if path.exists() else ""
for needle in needles:
if needle not in text:
missing.append(f"{path.relative_to(ROOT)}: missing `{needle}`")
if missing:
print("Naive module hooks LOST (see jni/zsg_naive/README.md):")
print("\n".join(" - " + m for m in missing))
sys.exit(1)
print(f"all Naive hooks present ({sum(len(v) for v in HOOKS.values())} checks in {len(HOOKS)} files)")