Commit 3f6b326684532e954c177f38007da9ce1856bfa4

Authored by yibo
1 parent 40ff74d1

feat(wechathook): 语音全合成追踪 — 定位内联 cgi uploadvoice 路 + 捕获 wire 协议

真机 hook 追踪确认本机语音走 jg0.x.w 内联 cgi 分支(非 CDN 引擎 addSendTask,
那是 send_use_cdn_upload=1 的机器才走)。内联路可 z2.b 全合成,复用文字同队列。

新增追踪 hook:
- hookCdnTrace: h2.d(addSendTask)/l1.keep_onUpload*/jg0.x.u — 证实 CDN 路本机不触发。
- hookVoiceCgiCapture: hook modelbase.l.a() 过滤 uploadvoice,按类型定位字段(base≠
  tinker 名,NoSuchFieldError 教训),dump 请求 pb r45.cv6 全字段。

捕获的 wire 协议(cgi /cgi-bin/micromsg-bin/uploadvoice, cmdid 127, req cv6/resp dv6):
  [0]self [1]talker [2]netOffset [3]本块SILK长 [4]"newSendVoice_"+voiceId
  [6]时长ms [7]custom cu5(SILK字节) [8]endflag [11]msgsource [12]=4 [15]long
  分块=6000字节/片,末块 end=1 响应 dv6.getLong(11)>0=服务器msgId=投递。
  scene modelbase.g extends m1 → z2.b(scene) 同文字。modelbase.o 有公开构造器可绕
  过 modelbase.l 字段名不匹配。

下一步: sendVoiceViaCgi 实现分块 cgi + z2.b 全合成。详见 memory + WECHAT_SEND_API。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
xhs_lsposed_a16_fix/backups/WeChatHook_20260707_voice-cgi-trace.java 0 → 100644
  1 +package com.example.wechathook;
  2 +
  3 +import android.app.Activity;
  4 +import android.content.BroadcastReceiver;
  5 +import android.content.Context;
  6 +import android.content.Intent;
  7 +import android.content.IntentFilter;
  8 +import android.os.Bundle;
  9 +import android.os.Handler;
  10 +import android.os.Looper;
  11 +import android.view.View;
  12 +import java.lang.reflect.Proxy;
  13 +import de.robv.android.xposed.IXposedHookLoadPackage;
  14 +import de.robv.android.xposed.XC_MethodHook;
  15 +import de.robv.android.xposed.XposedBridge;
  16 +import de.robv.android.xposed.XposedHelpers;
  17 +import de.robv.android.xposed.callbacks.XC_LoadPackage;
  18 +
  19 +public class WeChatHook implements IXposedHookLoadPackage {
  20 +
  21 + private static final String ACTION_SEND = "com.hermes.wechat.SEND_MSG_INTERNAL";
  22 + private static final String ACTION_SEND_IMAGE = "com.hermes.wechat.SEND_IMAGE_INTERNAL";
  23 + private static final String ACTION_SEND_VOICE = "com.hermes.wechat.SEND_VOICE_INTERNAL";
  24 + private static final String ACTION_ARM_SWAP = "com.hermes.wechat.ARM_VOICE_SWAP";
  25 + private static final String ACTION_DUMP_API = "com.hermes.wechat.DUMP_WECHAT_API";
  26 +
  27 + // ── Voice hot-swap state (the route that actually delivers) ────────────────
  28 + // Fully-synthetic voice (SEND_VOICE_INTERNAL) can build the message shell but
  29 + // can never upload the SILK to WeChat's CDN (upload is locked inside jg0.x's
  30 + // Kotlin coroutine). So instead we let the user trigger a REAL recording (hold
  31 + // "按住说话") and intercept jg0.x.w — the CDN uploadAttach step — replacing the
  32 + // recorded SILK bytes (w21.t.a) with our TTS SILK. WeChat's own machinery then
  33 + // uploads + delivers our audio. Armed by ARM_VOICE_SWAP; consumed once.
  34 + private static volatile boolean sSwapArmed = false;
  35 + private static volatile byte[] sSwapSilk = null; // TTS SILK bytes to inject
  36 + private static volatile int sSwapDuration = 0; // ms, replaces the recorded duration
  37 + // Safety: an arm auto-expires at this wall-clock time (set to arm + audio duration
  38 + // + 10s slack). The swap fires only on release AFTER a full hold, so the window must
  39 + // outlast the hold; past it, a stale arm silently dies instead of hijacking a later
  40 + // unrelated recording.
  41 + private static volatile long sSwapExpiresAt = 0;
  42 + // Cached f9 setter map (column -> methodName), built once on first voice send
  43 + // (sF9SetterMap is declared alongside probeAllF9Setters below)
  44 + // Thread-locals for voice send: voiceId and SILK bytes to inject into f9 ctor
  45 + private static final ThreadLocal<String> sPendingVoiceId = new ThreadLocal<>();
  46 + private static final ThreadLocal<byte[]> sPendingLvBuffer = new ThreadLocal<>();
  47 + // Captures the f9 that called convertTo() (= the one written to DB); used to populate r0.i.
  48 + private static final ThreadLocal<Object> sDatabaseF9 = new ThreadLocal<>();
  49 + private static ClassLoader sWeChatCL; // pre-Tinker classloader (from handleLoadPackage)
  50 + private static volatile ClassLoader sTinkerCL; // Tinker-patched classloader (from App.onCreate)
  51 + private static volatile Context sAppContext;
  52 + private static volatile boolean sFsGReady = false;
  53 + // Set true while WE are calling newInstance so r0Hook can distinguish us from WeChat
  54 + private static volatile boolean sCalledByUs = false;
  55 + // Network dispatcher captured from a real WeChat r0 at H()-entry; needed by CDN upload
  56 + private static volatile Object sCapturedDispatcher = null;
  57 + private static volatile Object sPt0E0Instance = null; // pt0.e0 singleton, captured from r() hook
  58 + private static volatile Object sImgPlugin = null; // b80.u instance, captured from pj/Bi hook
  59 + private static volatile Object sRealImgParams = null; // last real o70.h, captured for replication
  60 + private static volatile Object sRealImgK = null; // last real o70.k (oj insert object)
  61 + private static final ThreadLocal<Long> sPendingMsgLocalId = new ThreadLocal<>(); // msgId from DB insert
  62 + // Logged-in user's wxid, auto-discovered from first real voice message send
  63 + private static volatile String sMyWxid = null;
  64 + // Pending send: stored when broadcast arrives before gm0.j1 is initialized
  65 + private static volatile String sPendingTalker = null;
  66 + private static volatile String sPendingText = null;
  67 + private static volatile String sPendingProc = null;
  68 +
  69 + @Override
  70 + public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
  71 + if (!"com.tencent.mm".equals(lpparam.packageName)) return;
  72 + // Use android.util.Log directly so it appears even before VectorLegacyBridge is ready
  73 + android.util.Log.i("WeChatHookEarly", "INIT proc=" + lpparam.processName
  74 + + " pid=" + android.os.Process.myPid());
  75 + XposedBridge.log("[WeChatHook] Injected into WeChat " + lpparam.processName
  76 + + " pid=" + android.os.Process.myPid());
  77 + ClassLoader cl = lpparam.classLoader;
  78 + sWeChatCL = cl;
  79 +
  80 + // Tablet login hooks — DISABLED. User switched to normal direct (primary)
  81 + // login. The bk.A/B tablet-spoof would make WeChat think it's a tablet
  82 + // mid-session and can re-trigger the beta "体验资格" gate on this test build,
  83 + // kicking the login. Keep them off so restarts don't disturb direct login.
  84 + // hookInTabletEnv(cl);
  85 + // hookProbe(cl);
  86 + // hookLoginHistoryUIInitView(cl);
  87 + // hookLoginUIInitView(cl);
  88 + // hookLoginSelectUICheck(cl);
  89 + // hookLoginButtonClick(cl);
  90 +
  91 + // WCDB diagnostic: which process writes? + media ContentValues dump
  92 + hookWCDB(cl, lpparam.processName);
  93 +
  94 + // Factory method discovery: dumps w11.s1 signatures + hooks all static methods
  95 + // so that when WeChat UI sends image/voice we capture the exact API call.
  96 + hookFactoryMethods(cl, lpparam.processName);
  97 +
  98 + // MediaPlayer hook: captures voice file paths when WeChat plays voice messages.
  99 + // This reveals the voice2/{dir1}/{dir2}/msg_{id}.amr naming formula.
  100 + hookMediaPlayer(lpparam.processName);
  101 +
  102 + // Hook gm0.j1.g() to detect when DI kernel is ready — runs in ALL processes.
  103 + // This enables the pending-send mechanism: if broadcast arrives before DI init,
  104 + // we store the args and retry once g() fires.
  105 + hookDIInit(cl, lpparam.processName);
  106 +
  107 + // Send hook in ALL WeChat processes — we need to find which one can actually send.
  108 + // The broadcast receiver registered in each process will all receive the intent;
  109 + // whichever process has gm0.j1 initialized will succeed.
  110 + hookSendMessage(cl, lpparam.processName);
  111 +
  112 + // Hook w11.r0.H(String) to trace CDN upload: log r0 String fields + file access.
  113 + hookR0H(cl, lpparam.processName);
  114 +
  115 + // Capture the live network dispatcher com.tencent.mm.modelbase.m2 (MicroMsg.RDispatcher)
  116 + // at construction. Synthetic voice sends need the REAL m2 to actually reach the
  117 + // network; without it we'd fall back to a fake $Proxy that never sends.
  118 + hookDispatcher(cl, lpparam.processName);
  119 +
  120 + // Instrument the voice-upload service w21.g1 (voiceinfo table): on a REAL voice
  121 + // send, dump the exact w21.w0 upload-task fields so we can replicate them for
  122 + // synthetic voice (the last missing step = CDN audio upload).
  123 + hookVoiceUpload(cl, lpparam.processName);
  124 +
  125 + // Image send: hook the non-suspend plugin methods b80.u.pj/Bi (o70.h) — the
  126 + // actual image-send entry the coroutine calls. Capture the b80.u instance +
  127 + // dump the full o70.h a REAL send builds, so we can replicate it directly.
  128 + hookImageSend(cl, lpparam.processName);
  129 + // Capture the SendImgProxyUI launch Intent (real gallery send goes through it),
  130 + // so we can replay the whole real send flow via `am start`.
  131 + hookSendImgProxyUI(cl, lpparam.processName);
  132 +
  133 + // Hook pt0.e0 — the voice-send coroutine class found in the stack trace.
  134 + // Real voice sends don't use r0.H(); we need to find where CDN upload actually fires.
  135 + hookPt0E0(cl, lpparam.processName);
  136 +
  137 + // Surgical voice-send entry probe (jg0.x + qi3.f0/g0 only). On this fresh
  138 + // reinstall the send runs in the base CL (no Tinker patch yet), so hook here.
  139 + hookVoiceProbe(cl, lpparam.processName);
  140 +
  141 + // Voice hot-swap: intercept jg0.x.w (CDN uploadAttach) to replace the recorded
  142 + // SILK with our TTS audio during a real (user- or A11y-triggered) recording.
  143 + // This is the ONE route that actually delivers synthetic voice.
  144 + hookVoiceSwap(cl, lpparam.processName);
  145 +
  146 + // Trace the CDN upload submission (dn.m task + assigned aeskey/fileId) on a real
  147 + // voice send — the layer full-synthesis was missing (addSendTask / CdnManager).
  148 + hookCdnTrace(cl, lpparam.processName);
  149 + // Capture the real uploadvoice cgi request (this device uses inline-cgi, not CDN).
  150 + hookVoiceCgiCapture(cl, lpparam.processName);
  151 + }
  152 +
  153 + // ── WCDB hook ──────────────────────────────────────────────────────────────
  154 + // Intercepts every INSERT into the message table.
  155 + // For msgtype 3 (image) and 34 (voice) logs the full ContentValues so we can
  156 + // reverse-engineer the exact schema WeChat uses when building those messages.
  157 + private void hookWCDB(ClassLoader cl, String procName) {
  158 + try {
  159 + XposedHelpers.findAndHookMethod(
  160 + "com.tencent.wcdb.database.SQLiteDatabase", cl,
  161 + "insertWithOnConflict",
  162 + String.class, String.class, android.content.ContentValues.class, int.class,
  163 + new XC_MethodHook() {
  164 + private boolean textLogged = false;
  165 + @Override
  166 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  167 + String table = (String) param.args[0];
  168 + if (table == null) return;
  169 + android.content.ContentValues cv =
  170 + (android.content.ContentValues) param.args[2];
  171 +
  172 + // Determine msgtype from ContentValues (key may be "type" or "msgtype")
  173 + Object rawType = null;
  174 + if (cv != null) {
  175 + rawType = cv.get("type");
  176 + if (rawType == null) rawType = cv.get("msgtype");
  177 + if (rawType == null) rawType = cv.get("msgType");
  178 + }
  179 + int msgtype = -1;
  180 + try { if (rawType != null) msgtype = Integer.parseInt(rawType.toString()); }
  181 + catch (NumberFormatException ignored) {}
  182 +
  183 + if (msgtype == 3 || msgtype == 34) {
  184 + // Image (3) or Voice (34): dump full ContentValues + stack
  185 + String cvStr = cv != null ? cv.toString() : "null";
  186 + String stack = android.util.Log.getStackTraceString(new Throwable());
  187 + if (stack.length() > 4000) stack = stack.substring(0, 4000) + "…";
  188 + XposedBridge.log("[WeChatHook] WCDB MEDIA INSERT table=" + table
  189 + + " msgtype=" + msgtype
  190 + + " proc=" + procName
  191 + + "\nContentValues=" + cvStr
  192 + + "\nStack=" + stack);
  193 + } else if (msgtype == 1) {
  194 + // Text: only log once (to confirm which process writes)
  195 + if (!textLogged) {
  196 + textLogged = true;
  197 + String stack = android.util.Log.getStackTraceString(new Throwable());
  198 + if (stack.length() > 3000) stack = stack.substring(0, 3000) + "…";
  199 + XposedBridge.log("[WeChatHook] WCDB TEXT INSERT table=" + table
  200 + + " proc=" + procName + "\n" + stack);
  201 + } else {
  202 + XposedBridge.log("[WeChatHook] WCDB TEXT table=" + table
  203 + + " proc=" + procName);
  204 + }
  205 + }
  206 + }
  207 + });
  208 + XposedBridge.log("[WeChatHook] WCDB hook OK in " + procName);
  209 + } catch (Throwable t) {
  210 + XposedBridge.log("[WeChatHook] WCDB hook failed in " + procName + ": " + t);
  211 + }
  212 + }
  213 +
  214 + // ── MediaPlayer hook: reveals voice file path format ─────────────────────
  215 + // When WeChat plays a voice message it calls MediaPlayer.setDataSource(path).
  216 + // We log any path under voice2/ to see the full path including subdirectory,
  217 + // which reveals the formula WeChat uses to map voice file IDs to directories.
  218 + private void hookMediaPlayer(String procName) {
  219 + try {
  220 + XposedHelpers.findAndHookMethod("android.media.MediaPlayer", null,
  221 + "setDataSource", String.class, new XC_MethodHook() {
  222 + @Override
  223 + protected void beforeHookedMethod(MethodHookParam p) throws Throwable {
  224 + String path = (String) p.args[0];
  225 + if (path != null && path.contains("voice2")) {
  226 + XposedBridge.log("[WeChatHook] MediaPlayer.setDataSource VOICE="
  227 + + path + " proc=" + procName);
  228 + }
  229 + }
  230 + });
  231 + XposedBridge.log("[WeChatHook] MediaPlayer hook OK in " + procName);
  232 + } catch (Throwable t) {
  233 + XposedBridge.log("[WeChatHook] MediaPlayer hook failed in " + procName + ": " + t);
  234 + }
  235 + }
  236 +
  237 + // ── f9.convertTo() hook: maps f9 fields to DB columns ─────────────────────
  238 + // Captures ContentValues produced by convertTo() for image (3) and voice (34).
  239 + // From these ContentValues we know which f9 setter corresponds to which DB column
  240 + // (imgPath, content, talker, etc.) so we can construct f9 programmatically.
  241 + private void hookF9ConvertTo(ClassLoader cl, String procName) {
  242 + try {
  243 + XposedHelpers.findAndHookMethod("com.tencent.mm.storage.f9", cl,
  244 + "convertTo", new XC_MethodHook() {
  245 + @Override
  246 + protected void afterHookedMethod(MethodHookParam p) throws Throwable {
  247 + if (p.hasThrowable()) return;
  248 + android.content.ContentValues cv =
  249 + (android.content.ContentValues) p.getResult();
  250 + if (cv == null) return;
  251 + Object rawType = cv.get("type");
  252 + if (rawType == null) rawType = cv.get("msgtype");
  253 + if (rawType == null) return;
  254 + int msgtype = -1;
  255 + try { msgtype = Integer.parseInt(rawType.toString()); } catch (Throwable e) {}
  256 + if (msgtype == 3 && !sCalledByUs) {
  257 + // Dump full call stack once for a real IMAGE send so we can find
  258 + // the top-level app entry point to replicate for API image send.
  259 + XposedBridge.log("[WeChatHook] convertTo IMAGE STACK (real send):\n"
  260 + + android.util.Log.getStackTraceString(new Exception()));
  261 + }
  262 + if (msgtype == 34) {
  263 + // Dump call stack once for real sends to find the CDN upload caller.
  264 + if (!sCalledByUs) {
  265 + XposedBridge.log("[WeChatHook] convertTo STACK (real send):\n"
  266 + + android.util.Log.getStackTraceString(new Exception()));
  267 + }
  268 + // Auto-discover logged-in user's wxid from real UI voice sends.
  269 + // We look for isSend=1 messages (user's own sends) and extract
  270 + // fromusername from the voicemsg XML, cache as sMyWxid.
  271 + if (sMyWxid == null && !sCalledByUs) {
  272 + Object isSend = cv.get("isSend");
  273 + Object contentVal = cv.get("content");
  274 + if (isSend instanceof Integer && ((Integer)isSend) == 1
  275 + && contentVal instanceof String) {
  276 + String c = (String) contentVal;
  277 + int fi = c.indexOf("fromusername=\"");
  278 + if (fi >= 0) {
  279 + int start = fi + "fromusername=\"".length();
  280 + int end = c.indexOf("\"", start);
  281 + if (end > start) {
  282 + String wxid = c.substring(start, end);
  283 + if (!wxid.isEmpty()) {
  284 + sMyWxid = wxid;
  285 + XposedBridge.log("[WeChatHook] auto-discovered sMyWxid=" + wxid);
  286 + }
  287 + }
  288 + }
  289 + }
  290 + }
  291 + }
  292 + if (msgtype == 3 || msgtype == 34) {
  293 + // Inject lvbuffer (SILK bytes) if we're sending voice via hook.
  294 + // sPendingLvBuffer is still set here — convertTo fires INSIDE
  295 + // the r0 constructor which runs before our finally-block clears it.
  296 + byte[] pendingLv = sPendingLvBuffer.get();
  297 + if (pendingLv != null && !(cv.get("lvbuffer") instanceof byte[])) {
  298 + cv.put("lvbuffer", pendingLv);
  299 + XposedBridge.log("[WeChatHook] convertTo: injected lvbuffer " + pendingLv.length + " bytes");
  300 + }
  301 + // Capture the DB-bound f9 (the one convertTo() runs on).
  302 + // This is the correct object for r0.i: it has content + msgId set.
  303 + if (pendingLv != null) {
  304 + sDatabaseF9.set(p.thisObject);
  305 + // Capture msgLocalId for pt0.e0.s() CDN trigger
  306 + try {
  307 + Object msgIdObj = cv.get("msgId");
  308 + if (msgIdObj != null) {
  309 + long mid = Long.parseLong(msgIdObj.toString());
  310 + sPendingMsgLocalId.set(mid);
  311 + XposedBridge.log("[WeChatHook] convertTo: captured msgLocalId=" + mid);
  312 + }
  313 + } catch (Throwable ignored) {}
  314 + // Do NOT force status=4 here.
  315 + // Forcing status=4 before H() causes H() to skip CDN upload
  316 + // (WeChat checks status and exits early if already "delivered").
  317 + // Let H() set status=4 naturally after successful CDN upload.
  318 + // Ensure flag and msgSvrId are present (missing from our sends).
  319 + if (cv.get("flag") == null) cv.put("flag", 0);
  320 + if (cv.get("msgSvrId") == null) cv.put("msgSvrId", 0L);
  321 + XposedBridge.log("[WeChatHook] convertTo: initial INSERT (status not forced, H() will set it)");
  322 + }
  323 + // Log full ContentValues including lvbuffer details
  324 + StringBuilder sb = new StringBuilder();
  325 + sb.append("[WeChatHook] f9.convertTo() msgtype=").append(msgtype)
  326 + .append(" proc=").append(procName).append("\nContentValues=").append(cv);
  327 + Object lvbuf = cv.get("lvbuffer");
  328 + if (lvbuf instanceof byte[]) {
  329 + byte[] b = (byte[]) lvbuf;
  330 + StringBuilder hex = new StringBuilder();
  331 + int show = Math.min(b.length, 32);
  332 + for (int i = 0; i < show; i++)
  333 + hex.append(String.format("%02x", b[i] & 0xff));
  334 + sb.append("\nlvbuffer len=").append(b.length).append(" hex=").append(hex);
  335 + } else {
  336 + sb.append("\nlvbuffer=null");
  337 + }
  338 + XposedBridge.log(sb.toString());
  339 + }
  340 + }
  341 + });
  342 + XposedBridge.log("[WeChatHook] f9.convertTo hook OK in " + procName);
  343 + } catch (Throwable t) {
  344 + XposedBridge.log("[WeChatHook] f9.convertTo hook failed in " + procName + ": " + t);
  345 + }
  346 + }
  347 +
  348 + // ── f9 constructor imgPath injector ───────────────────────────────────────
  349 + // Hooks ALL f9 constructors. When sPendingVoiceId is set on the calling thread,
  350 + // immediately calls the discovered imgPath setter on the newly created f9 object.
  351 + // This fires INSIDE the r0 constructor (before its internal f9.convertTo() call),
  352 + // so the DB insert from r0 constructor already has the correct voice file ID.
  353 + private void hookF9ImgPathInjector(ClassLoader cl, String procName) {
  354 + try {
  355 + Class<?> f9Class = XposedHelpers.findClass("com.tencent.mm.storage.f9", cl);
  356 + XC_MethodHook injHook = new XC_MethodHook() {
  357 + @Override
  358 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  359 + String pending = sPendingVoiceId.get();
  360 + if (pending == null) return;
  361 + java.util.Map<String, String> sm = sF9SetterMap;
  362 + if (sm == null) return;
  363 + // Inject imgPath
  364 + String setter = sm.get("imgPath");
  365 + if (setter != null) {
  366 + XposedHelpers.callMethod(param.thisObject, setter, pending);
  367 + XposedBridge.log("[WeChatHook] f9 ctor injected imgPath=" + pending + " via " + setter);
  368 + }
  369 + // Inject lvbuffer (SILK bytes) so WeChat treats the voice as locally available
  370 + byte[] lvbuf = sPendingLvBuffer.get();
  371 + String lvSetter = sm.get("lvbuffer:bytes");
  372 + if (lvbuf != null && lvSetter != null) {
  373 + XposedHelpers.callMethod(param.thisObject, lvSetter, (Object) lvbuf);
  374 + XposedBridge.log("[WeChatHook] f9 ctor injected lvbuffer len=" + lvbuf.length + " via " + lvSetter);
  375 + } else {
  376 + XposedBridge.log("[WeChatHook] f9 ctor lvbuffer skip: lvbuf=" + (lvbuf==null?"null":"ok") + " setter=" + lvSetter);
  377 + }
  378 + // sDatabaseF9 is captured in convertTo() — that's the correct DB-bound f9.
  379 + }
  380 + };
  381 + int hooked = 0;
  382 + for (java.lang.reflect.Constructor<?> ctor : f9Class.getDeclaredConstructors()) {
  383 + XposedBridge.hookMethod(ctor, injHook);
  384 + hooked++;
  385 + }
  386 + XposedBridge.log("[WeChatHook] f9 ctor injector OK in " + procName + " (" + hooked + " ctors)");
  387 + } catch (Throwable t) {
  388 + XposedBridge.log("[WeChatHook] f9 ctor injector failed in " + procName + ": " + t);
  389 + }
  390 + }
  391 +
  392 + // ── Image send via internal API ────────────────────────────────────────────
  393 + // Calls the gallery's own static image-send helper:
  394 + // j33.d0.k(long imgId, String path, String talker, boolean, int, boolean,
  395 + // GalleryItem$MediaItem)
  396 + // This is exactly what the album picker calls (traced via a real image send's
  397 + // convertTo stack → b80.u.oj → b80.s coroutine → built from o70.h; d0.k is the
  398 + // top-level builder). It builds o70.h (PreBuildParams) and launches the send
  399 + // coroutine internally (thumbnail gen + CDN upload + DB insert), fire-and-forget.
  400 + // The old w11.s1.b(IMAGE) path built an incomplete r1 → n1.a() NPE; abandoned.
  401 + private static void sendImageViaAPI(String talker, String imagePath) throws Throwable {
  402 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  403 + if (cl == null) throw new IllegalStateException("classloader null");
  404 + // Replicate the REAL image send captured by hookImageSend: build the exact
  405 + // o70.h (PreBuildParams) that b80.u.pj() receives on a genuine send, then call
  406 + // b80.u.pj(o70.h) directly (non-suspend), skipping the whole gallery/coroutine UI.
  407 + //
  408 + // Captured real o70.h (fields are single letters a–l):
  409 + // a=r6 preBuildFolder, e=imgPath, g=toUserName(talker), c=source(0), d=0,
  410 + // f=imgId(0 ok), h=compressType(0), k=Uri(null for pj), b=UUID(auto)
  411 + //
  412 + // r6 folder = lp0.b.h0(gm0.j1.b().j() + "_MsgImgUploadFSC") (= g80.o.c7()).
  413 + // plugin b80.u = i95.n0.c(o70.e.class) (fallback to hook-captured instance).
  414 + // b80.u image plugin = i95.n0.c(o70.e.class) (fallback to hook-captured instance).
  415 + Object imgPlugin = sImgPlugin;
  416 + if (imgPlugin == null) {
  417 + Class<?> n0 = XposedHelpers.findClass("i95.n0", cl);
  418 + Class<?> o70e = XposedHelpers.findClass("o70.e", cl);
  419 + imgPlugin = XposedHelpers.callStaticMethod(n0, "c", o70e);
  420 + }
  421 + if (imgPlugin == null) throw new IllegalStateException("b80.u image plugin null");
  422 +
  423 + // r6 pre-build folder = lp0.b.h0(gm0.j1.b().j() + "_MsgImgUploadFSC") (= g80.o.c7()).
  424 + Object m = XposedHelpers.callStaticMethod(XposedHelpers.findClass("gm0.j1", cl), "b");
  425 + Object prefix = XposedHelpers.callMethod(m, "j");
  426 + Class<?> lp0b = XposedHelpers.findClass("lp0.b", cl);
  427 + Object r6 = XposedHelpers.callStaticMethod(lp0b, "h0", prefix + "_MsgImgUploadFSC");
  428 +
  429 + // Build o70.k (the batch send object) — fields captured from a real oj(o70.k):
  430 + // a=r6, b=UUID(auto), c=talker, d=source, f=compressType, g=List<o70.i>
  431 + Class<?> o70k = XposedHelpers.findClass("o70.k", cl);
  432 + Object k = XposedHelpers.newInstance(o70k, r6);
  433 + XposedHelpers.setObjectField(k, "c", talker); // toUserName
  434 + // source (field d) — real send used 3; set via reflection (int field).
  435 + try { java.lang.reflect.Field df = o70k.getDeclaredField("d"); df.setAccessible(true); df.setInt(k, 3); } catch (Throwable ignored) {}
  436 + // o70.i(imgPath, Uri, Long imgId) — give it a file:// Uri so the CDN upload has
  437 + // a readable source (real sends pass a MediaStore content:// Uri).
  438 + Class<?> o70i = XposedHelpers.findClass("o70.i", cl);
  439 + android.net.Uri fileUri = android.net.Uri.fromFile(new java.io.File(imagePath));
  440 + Object item = XposedHelpers.newInstance(o70i,
  441 + new Class<?>[]{String.class, android.net.Uri.class, Long.class},
  442 + imagePath, fileUri, Long.valueOf(0L));
  443 + java.util.List<Object> list = new java.util.ArrayList<>();
  444 + list.add(item);
  445 + XposedHelpers.setObjectField(k, "g", list);
  446 + String clientId = (String) XposedHelpers.getObjectField(k, "b");
  447 +
  448 + // Replicate b80.s coroutine's per-item prebuild loop: build o70.h from k+item,
  449 + // then pj (stage compressed image + thumbnail into r6).
  450 + Class<?> o70h = XposedHelpers.findClass("o70.h", cl);
  451 + Object h = XposedHelpers.newInstance(o70h, r6);
  452 + XposedHelpers.callMethod(h, "b", clientId); // clientId (field b)
  453 + XposedHelpers.setObjectField(h, "e", imagePath); // imgPath
  454 + XposedHelpers.setObjectField(h, "g", talker); // toUserName
  455 + XposedHelpers.setObjectField(h, "k", fileUri); // Uri (source for staging/upload)
  456 + try { java.lang.reflect.Field hc = o70h.getDeclaredField("c"); hc.setAccessible(true); hc.setInt(h, 3); } catch (Throwable ignored) {} // source
  457 + // d(rotate)/h(compressType) default 0. f(imgId) 0.
  458 + XposedBridge.log("[WeChatHook] sendImageViaAPI: built o70.k+o70.h e=" + imagePath + " g=" + talker
  459 + + " plugin=" + imgPlugin.getClass().getName());
  460 +
  461 + sCalledByUs = true;
  462 + try {
  463 + if (!(Boolean) XposedHelpers.callMethod(imgPlugin, "Bi", h, "thumb.jpg")) {
  464 + XposedHelpers.callMethod(imgPlugin, "pj", h); // prebuild (stage)
  465 + try { XposedHelpers.callMethod(imgPlugin, "nj", h, 10000); } catch (Throwable ignored) {}
  466 + }
  467 + java.util.ArrayList<?> res = (java.util.ArrayList<?>)
  468 + XposedHelpers.callMethod(imgPlugin, "oj", k); // insert + build descriptors
  469 + XposedBridge.log("[WeChatHook] sendImageViaAPI: oj() DONE to=" + talker
  470 + + " res=" + (res == null ? "null" : "size=" + res.size()));
  471 +
  472 + // ── Last mile: submit each o70.l descriptor to the CDN upload service ──
  473 + // oj() only inserts the msg (f9) + ImgInfo (b0) and RETURNS List<o70.l>
  474 + // upload descriptors — it does NOT start the CDN upload. The real flow
  475 + // (pe5.f.a) loops the list and, per item, builds r70.g + k70.i0 crossParams
  476 + // and calls the d1 img-send service's oj(r70.g, o70.l), which launches the
  477 + // CDN upload coroutine (e80.c). Without this, the full image never uploads
  478 + // (thumbnail renders but the send spins forever). jadx field names f30xxxN
  479 + // map to the real single-letter dex field N (verified: o70.k "d"=source).
  480 + // v70.w.oj builds a ViewModel via ViewModelProvider.get → must run on the
  481 + // main thread; the broadcast receiver already dispatches us there.
  482 + if (res != null && !res.isEmpty()) {
  483 + Class<?> n0 = XposedHelpers.findClass("i95.n0", cl);
  484 + Object cdnSvc = XposedHelpers.callStaticMethod(
  485 + n0, "c", XposedHelpers.findClass("xs.d1", cl)); // → v70.w (MsgImgFeatureService)
  486 + String selfWxid = null;
  487 + try { selfWxid = (String) XposedHelpers.callStaticMethod(
  488 + XposedHelpers.findClass("c01.z1", cl), "r"); } catch (Throwable ignored) {}
  489 + if (selfWxid == null) selfWxid = ""; // API accepts "" (pe5.f.a does the same)
  490 + Class<?> i0cls = XposedHelpers.findClass("k70.i0", cl);
  491 + Class<?> r70g = XposedHelpers.findClass("r70.g", cl);
  492 + int compressType = 0;
  493 + try { java.lang.reflect.Field cf = o70k.getDeclaredField("f"); cf.setAccessible(true); compressType = cf.getInt(k); } catch (Throwable ignored) {}
  494 + int submitted = 0;
  495 + for (Object l : res) {
  496 + // crossParams: only source (field a) matters for a plain photo;
  497 + // mirror quote(t)/long(u) from the descriptor (usually null/0).
  498 + Object crossParams = XposedHelpers.newInstance(i0cls);
  499 + try { java.lang.reflect.Field af = i0cls.getDeclaredField("a"); af.setAccessible(true); af.setInt(crossParams, 3); } catch (Throwable ignored) {}
  500 + try { XposedHelpers.setObjectField(crossParams, "t", XposedHelpers.getObjectField(l, "s")); } catch (Throwable ignored) {}
  501 + try {
  502 + java.lang.reflect.Field lr = l.getClass().getDeclaredField("r"); lr.setAccessible(true);
  503 + java.lang.reflect.Field iu = i0cls.getDeclaredField("u"); iu.setAccessible(true);
  504 + iu.setLong(crossParams, lr.getLong(l));
  505 + } catch (Throwable ignored) {}
  506 + String builtPath = (String) XposedHelpers.getObjectField(l, "e"); // pre-built compressed path
  507 + Object gVar = XposedHelpers.newInstance(r70g,
  508 + new Class<?>[]{String.class, int.class, String.class, String.class, i0cls},
  509 + builtPath, compressType, selfWxid, talker, crossParams);
  510 + XposedHelpers.callMethod(cdnSvc, "oj", gVar, l); // → e80.c CDN upload coroutine
  511 + submitted++;
  512 + }
  513 + XposedBridge.log("[WeChatHook] sendImageViaAPI: CDN submit DONE items=" + submitted
  514 + + " self=" + selfWxid + " compress=" + compressType);
  515 + }
  516 + } finally { sCalledByUs = false; }
  517 + }
  518 +
  519 + // ── Probe all f9 setter→column mappings (String + int, one-shot) ──────────
  520 + // Calls each String setter and each void(int) method with a unique marker,
  521 + // then calls convertTo() to see which ContentValues key reflects the marker.
  522 + // Returns a Map<columnName, setterMethodName>.
  523 + private static volatile java.util.Map<String, String> sF9SetterMap = null;
  524 +
  525 + private static java.util.Map<String, String> probeAllF9Setters(Class<?> f9Class) {
  526 + java.util.Map<String, String> result = new java.util.HashMap<>();
  527 +
  528 + // String setters (known from class dump)
  529 + for (String sn : new String[]{"Z0", "C1", "D1", "a1", "d1", "h1", "i1"}) {
  530 + try {
  531 + Object probe = XposedHelpers.newInstance(f9Class);
  532 + XposedHelpers.callMethod(probe, sn, "PROBE_" + sn);
  533 + android.content.ContentValues cv = (android.content.ContentValues)
  534 + XposedHelpers.callMethod(probe, "convertTo");
  535 + for (String key : cv.keySet()) {
  536 + Object val = cv.get(key);
  537 + if (("PROBE_" + sn).equals(val != null ? val.toString() : "")) {
  538 + result.put(key, sn);
  539 + XposedBridge.log("[WeChatHook] f9 str setter " + sn + " -> " + key);
  540 + }
  541 + }
  542 + } catch (Throwable t) {
  543 + XposedBridge.log("[WeChatHook] f9 probe str " + sn + ": " + t);
  544 + }
  545 + }
  546 +
  547 + // Int setters: scan all void(int) methods
  548 + try {
  549 + for (java.lang.reflect.Method m : f9Class.getDeclaredMethods()) {
  550 + if (m.getReturnType() != void.class) continue;
  551 + java.lang.Class<?>[] pt = m.getParameterTypes();
  552 + if (pt.length != 1 || pt[0] != int.class) continue;
  553 + m.setAccessible(true);
  554 + try {
  555 + Object probe = XposedHelpers.newInstance(f9Class);
  556 + m.invoke(probe, 88888);
  557 + android.content.ContentValues cv = (android.content.ContentValues)
  558 + XposedHelpers.callMethod(probe, "convertTo");
  559 + for (String key : cv.keySet()) {
  560 + Object val = cv.get(key);
  561 + if (val instanceof Integer && (Integer) val == 88888) {
  562 + result.put(key, m.getName());
  563 + XposedBridge.log("[WeChatHook] f9 int setter " + m.getName() + " -> " + key);
  564 + }
  565 + }
  566 + } catch (Throwable ignored) {}
  567 + }
  568 + } catch (Throwable t) {
  569 + XposedBridge.log("[WeChatHook] f9 int probe scan failed: " + t);
  570 + }
  571 +
  572 + // byte[] setters: scan all void(byte[]) methods — discovers lvbuffer setter
  573 + try {
  574 + for (java.lang.reflect.Method m : f9Class.getDeclaredMethods()) {
  575 + if (m.getReturnType() != void.class) continue;
  576 + java.lang.Class<?>[] pt = m.getParameterTypes();
  577 + if (pt.length != 1 || pt[0] != byte[].class) continue;
  578 + m.setAccessible(true);
  579 + // Marker: a 4-byte sentinel we can recognize in cv
  580 + byte[] marker = new byte[]{(byte)0xDE, (byte)0xAD, (byte)0xBE, (byte)0xEF};
  581 + try {
  582 + Object probe = XposedHelpers.newInstance(f9Class);
  583 + m.invoke(probe, (Object) marker);
  584 + android.content.ContentValues cv = (android.content.ContentValues)
  585 + XposedHelpers.callMethod(probe, "convertTo");
  586 + for (String key : cv.keySet()) {
  587 + Object val = cv.get(key);
  588 + if (val instanceof byte[]) {
  589 + byte[] got = (byte[]) val;
  590 + if (got.length == 4 && got[0] == (byte)0xDE && got[1] == (byte)0xAD) {
  591 + result.put(key + ":bytes", m.getName());
  592 + XposedBridge.log("[WeChatHook] f9 bytes setter " + m.getName() + " -> " + key);
  593 + }
  594 + }
  595 + }
  596 + } catch (Throwable ignored) {}
  597 + }
  598 + } catch (Throwable t) {
  599 + XposedBridge.log("[WeChatHook] f9 bytes probe scan failed: " + t);
  600 + }
  601 +
  602 + XposedBridge.log("[WeChatHook] f9 setter map: " + result);
  603 + return result;
  604 + }
  605 +
  606 + // ── Hook w11.r0.H(String) — CDN upload entry-point trace ─────────────────
  607 + // Logs every r0.H() call: dumps all String+File fields on r0 so we can identify
  608 + // which field contains the audio file path that H() uploads to CDN.
  609 + // Hook ALL methods on pt0.e0 (voice-send coroutine class found in stack trace).
  610 + // Goal: find which method triggers CDN upload AFTER f9.convertTo() returns.
  611 + // pt0.e0.k returns f9 objects and fires in multiple threads — CDN upload entry point.
  612 + private void hookPt0E0(ClassLoader cl, String procName) {
  613 + try {
  614 + Class<?> cls = XposedHelpers.findClass("pt0.e0", cl);
  615 + java.lang.reflect.Method[] methods = cls.getDeclaredMethods();
  616 + StringBuilder sig = new StringBuilder("[WeChatHook] pt0.e0 methods(" + methods.length + "):");
  617 + for (java.lang.reflect.Method m : methods) sig.append(" ").append(m.getName()).append("(").append(m.getParameterTypes().length).append(")");
  618 + XposedBridge.log(sig.toString());
  619 + for (java.lang.reflect.Method m : methods) {
  620 + final String mName = m.getName();
  621 + m.setAccessible(true);
  622 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  623 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  624 + // Capture singleton from ANY method (not just r()), so it's
  625 + // available even when no real voice send has happened this session.
  626 + if (sPt0E0Instance == null && p.thisObject != null) {
  627 + sPt0E0Instance = p.thisObject;
  628 + XposedBridge.log("[WeChatHook] pt0.e0 singleton captured via " + mName + ": " + p.thisObject);
  629 + }
  630 + if ("k".equals(mName)) {
  631 + // k(2): confirmed signature k(String talker, Long msgLocalId)
  632 + // CDN worker calls this to dequeue next upload task.
  633 + // Only log first call per send to avoid spam.
  634 + Object a0 = p.args != null && p.args.length > 0 ? p.args[0] : null;
  635 + Object a1 = p.args != null && p.args.length > 1 ? p.args[1] : null;
  636 + XposedBridge.log("[WeChatHook] pt0.e0.k ENTER talker=" + a0
  637 + + " msgLocalId=" + (a1 instanceof Long ? ((Long)a1).longValue() : a1));
  638 + } else if ("r".equals(mName)) {
  639 + // Save pt0.e0 singleton for later use in sendVoiceViaAPI.
  640 + if (sPt0E0Instance == null && p.thisObject != null) {
  641 + sPt0E0Instance = p.thisObject;
  642 + XposedBridge.log("[WeChatHook] pt0.e0 singleton captured: " + p.thisObject);
  643 + }
  644 + XposedBridge.log("[WeChatHook] pt0.e0.r ENTER, dumping thisObject fields:");
  645 + if (p.thisObject != null) {
  646 + Class<?> c = p.thisObject.getClass();
  647 + while (c != null && !c.equals(Object.class)) {
  648 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  649 + f.setAccessible(true);
  650 + try {
  651 + Object v = f.get(p.thisObject);
  652 + XposedBridge.log("[WeChatHook] " + c.getSimpleName()
  653 + + "." + f.getName() + "=" + (v == null ? "null"
  654 + : (v instanceof String || v instanceof Number || v instanceof Boolean)
  655 + ? v.toString() : v.getClass().getName() + "@" + System.identityHashCode(v)));
  656 + } catch (Throwable ignored) {}
  657 + }
  658 + c = c.getSuperclass();
  659 + }
  660 + }
  661 + } else if ("s".equals(mName)) {
  662 + // s(3): CDN upload trigger. Log args + full f9 hierarchy for diff analysis.
  663 + StringBuilder sb = new StringBuilder("[WeChatHook] pt0.e0.s ENTER args:");
  664 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  665 + Object a = p.args[i];
  666 + if (a == null) { sb.append(" [").append(i).append("]=null"); }
  667 + else if (a instanceof String) { sb.append(" [").append(i).append("]=String(\"").append(a).append("\")"); }
  668 + else if (a instanceof Number) { sb.append(" [").append(i).append("]=").append(a); }
  669 + else { sb.append(" [").append(i).append("]=").append(a.getClass().getName()).append("@").append(System.identityHashCode(a)); }
  670 + }
  671 + XposedBridge.log(sb.toString());
  672 + // Dump ALL fields of f9 (args[2]) across full parent hierarchy
  673 + if (p.args != null && p.args.length > 2 && p.args[2] != null) {
  674 + Object f9 = p.args[2];
  675 + StringBuilder fb = new StringBuilder("[WeChatHook] pt0.e0.s f9 DUMP:");
  676 + Class<?> c = f9.getClass();
  677 + while (c != null && !c.equals(Object.class)) {
  678 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  679 + f.setAccessible(true);
  680 + try {
  681 + Object v = f.get(f9);
  682 + String vs;
  683 + if (v == null) vs = "null";
  684 + else if (v instanceof byte[]) vs = "byte[" + ((byte[])v).length + "]";
  685 + else if (v instanceof String || v instanceof Number || v instanceof Boolean) vs = v.toString();
  686 + else vs = v.getClass().getSimpleName() + "@" + System.identityHashCode(v);
  687 + fb.append("\n ").append(c.getSimpleName()).append(".").append(f.getName()).append("=").append(vs);
  688 + } catch (Throwable ignored) {}
  689 + }
  690 + c = c.getSuperclass();
  691 + }
  692 + XposedBridge.log(fb.toString());
  693 + }
  694 + } else if (p.args != null && p.args.length == 2
  695 + && ("a".equals(mName) || "b".equals(mName) || "l".equals(mName)
  696 + || "n".equals(mName) || "q".equals(mName))) {
  697 + // Log 2-arg entry methods — one of these is likely the
  698 + // "enqueue voice for send" entry point called by WeChat UI
  699 + StringBuilder sb2 = new StringBuilder(
  700 + "[WeChatHook] pt0.e0." + mName + "(2) ENTER");
  701 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  702 + Object a = p.args[i];
  703 + if (a == null) sb2.append(" arg").append(i).append("=null");
  704 + else if (a instanceof String) sb2.append(" arg").append(i).append("=\"").append(a).append("\"");
  705 + else if (a instanceof Number) sb2.append(" arg").append(i).append("=").append(a);
  706 + else sb2.append(" arg").append(i).append("=").append(a.getClass().getName()).append("@").append(System.identityHashCode(a));
  707 + }
  708 + XposedBridge.log(sb2.toString());
  709 + } else {
  710 + XposedBridge.log("[WeChatHook] pt0.e0." + mName + " ENTER");
  711 + }
  712 + }
  713 + @Override protected void afterHookedMethod(MethodHookParam p) {
  714 + if (p.hasThrowable()) {
  715 + XposedBridge.log("[WeChatHook] pt0.e0." + mName + " THREW " + p.getThrowable());
  716 + } else if ("k".equals(mName)) {
  717 + Object ret = p.getResult();
  718 + if (ret != null) {
  719 + // Dump ALL declared fields on f9 (first call only, to learn field names)
  720 + StringBuilder fb = new StringBuilder("[WeChatHook] pt0.e0.k OK f9=").append(ret.getClass().getSimpleName());
  721 + java.lang.reflect.Field[] fields = ret.getClass().getDeclaredFields();
  722 + for (java.lang.reflect.Field f : fields) {
  723 + f.setAccessible(true);
  724 + try {
  725 + Object v = f.get(ret);
  726 + fb.append(" ").append(f.getName()).append("=").append(
  727 + v == null ? "null" : (v instanceof String || v instanceof Number || v instanceof Boolean)
  728 + ? v.toString() : v.getClass().getSimpleName() + "@" + System.identityHashCode(v));
  729 + } catch (Throwable ignored) {}
  730 + }
  731 + XposedBridge.log(fb.toString());
  732 + } else {
  733 + XposedBridge.log("[WeChatHook] pt0.e0.k OK ret=null");
  734 + }
  735 + } else {
  736 + XposedBridge.log("[WeChatHook] pt0.e0." + mName + " OK ret=" + p.getResult());
  737 + }
  738 + }
  739 + });
  740 + }
  741 + XposedBridge.log("[WeChatHook] hookPt0E0: hooked " + methods.length + " methods in " + procName);
  742 + } catch (Throwable t) {
  743 + XposedBridge.log("[WeChatHook] hookPt0E0 failed in " + procName + ": " + t);
  744 + }
  745 + }
  746 +
  747 + // ── Surgical voice-send entry probe ──────────────────────────────────────
  748 + // SAFE version: hooks ONLY the voice-send-specific classes (jg0.x coordinator
  749 + // + qi3.f0/g0 voice-message objects), NOT generic coroutine classes, so it
  750 + // won't add anti-tamper risk to the live Pad session. Goal: find the entry
  751 + // method that receives (talker, silk file/bytes, durationMs) in plain form,
  752 + // which we can then call synthetically to get a real, delivered voice send.
  753 + private static String fmtArg(Object a) {
  754 + if (a == null) return "null";
  755 + if (a instanceof byte[]) return "byte[" + ((byte[]) a).length + "]";
  756 + if (a instanceof String) return "\"" + a + "\"";
  757 + if (a instanceof Number || a instanceof Boolean) return a.toString();
  758 + return a.getClass().getName() + "@" + System.identityHashCode(a);
  759 + }
  760 +
  761 + // Recursively dump an object's non-static fields, bounded by depth, to find
  762 + // where scalar values (talker string / silk path / duration) are captured.
  763 + private static void dumpDeep(Object o, String prefix, int depth, StringBuilder sb) {
  764 + if (o == null || depth < 0) return;
  765 + for (Class<?> c = o.getClass(); c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  766 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  767 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  768 + f.setAccessible(true);
  769 + Object v;
  770 + try { v = f.get(o); } catch (Throwable t) { continue; }
  771 + sb.append("\n").append(prefix).append(f.getName()).append("=").append(fmtArg(v));
  772 + // Recurse into non-scalar, non-array WeChat/kotlin objects.
  773 + if (v != null && depth > 0
  774 + && !(v instanceof String) && !(v instanceof Number)
  775 + && !(v instanceof Boolean) && !(v instanceof byte[])
  776 + && !v.getClass().isArray()
  777 + && !v.getClass().getName().startsWith("java.")
  778 + && !v.getClass().getName().startsWith("android.")) {
  779 + dumpDeep(v, prefix + " ", depth - 1, sb);
  780 + }
  781 + }
  782 + }
  783 + }
  784 +
  785 + private void hookVoiceProbe(ClassLoader cl, String procName) {
  786 + // jg0.x — voice send coordinator; hook ALL methods to find the entry.
  787 + try {
  788 + Class<?> xClass = XposedHelpers.findClass("jg0.x", cl);
  789 + int n = 0;
  790 + for (java.lang.reflect.Method m : xClass.getDeclaredMethods()) {
  791 + final String mn = m.getName();
  792 + m.setAccessible(true);
  793 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  794 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  795 + // ── Voice hot-swap (the route that actually delivers) ──────────
  796 + // jg0.x.w(jg0.x, qi3.d0, w21.w0, int type, int durMs, w21.t silk, Cont)
  797 + // is the CDN uploadAttach step. On the REAL (non-resume) call, arg5
  798 + // (w21.t) holds the recorded SILK in its single byte[] field. When
  799 + // armed, replace it with our TTS SILK so WeChat uploads our audio.
  800 + // (This lives in the probe hook because this fork won't stack a 2nd
  801 + // hook on an already-hooked method — see hookVoiceSwap note.)
  802 + if ("w".equals(mn) && sSwapArmed && sSwapSilk != null
  803 + && System.currentTimeMillis() < sSwapExpiresAt
  804 + && p.args != null && p.args.length == 7 && p.args[5] != null) {
  805 + try {
  806 + Object tHolder = p.args[5];
  807 + java.lang.reflect.Field byteF = null;
  808 + for (java.lang.reflect.Field f : tHolder.getClass().getDeclaredFields())
  809 + if (f.getType() == byte[].class) { byteF = f; break; }
  810 + if (byteF != null) {
  811 + byteF.setAccessible(true);
  812 + byte[] orig = (byte[]) byteF.get(tHolder);
  813 + byteF.set(tHolder, sSwapSilk);
  814 + if (orig != null) for (java.lang.reflect.Field f : tHolder.getClass().getDeclaredFields()) {
  815 + if (f.getType() != int.class) continue;
  816 + f.setAccessible(true);
  817 + if (f.getInt(tHolder) == orig.length) f.setInt(tHolder, sSwapSilk.length);
  818 + }
  819 + if (sSwapDuration > 0) p.args[4] = sSwapDuration;
  820 + XposedBridge.log("[WeChatHook] VOICE SWAP DONE: "
  821 + + (orig == null ? "?" : orig.length) + "B -> " + sSwapSilk.length
  822 + + "B dur -> " + p.args[4]);
  823 + sSwapArmed = false; sSwapSilk = null; // one-shot
  824 + }
  825 + } catch (Throwable t) {
  826 + XposedBridge.log("[WeChatHook] VOICE SWAP failed: " + t);
  827 + }
  828 + }
  829 + StringBuilder sb = new StringBuilder("[WeChatHook] jg0.x." + mn + "(");
  830 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  831 + if (i > 0) sb.append(", ");
  832 + sb.append(fmtArg(p.args[i]));
  833 + }
  834 + sb.append(")");
  835 + // Deep-dump the send-carrying methods: D's lambda (arg0) and
  836 + // w's descriptor args — to locate talker/silk/duration fields.
  837 + if ("D".equals(mn) && p.args != null && p.args.length > 0) {
  838 + sb.append("\n [D arg0 pu.m0 deep]:");
  839 + dumpDeep(p.args[0], " ", 3, sb);
  840 + } else if ("w".equals(mn) && p.args != null) {
  841 + for (int i = 0; i < p.args.length; i++) {
  842 + if (p.args[i] != null && !(p.args[i] instanceof Number)) {
  843 + sb.append("\n [w arg").append(i).append(" deep]:");
  844 + dumpDeep(p.args[i], " ", 2, sb);
  845 + }
  846 + }
  847 + }
  848 + XposedBridge.log(sb.toString());
  849 + }
  850 + });
  851 + n++;
  852 + }
  853 + XposedBridge.log("[WeChatHook] hookVoiceProbe: jg0.x " + n + " methods in " + procName);
  854 + } catch (Throwable t) {
  855 + XposedBridge.log("[WeChatHook] hookVoiceProbe jg0.x failed: " + t);
  856 + }
  857 + // qi3.f0 / qi3.g0 — voice-message domain objects; dump ctor args + fields.
  858 + for (String cn : new String[]{"qi3.f0", "qi3.g0"}) {
  859 + try {
  860 + Class<?> c = XposedHelpers.findClass(cn, cl);
  861 + for (java.lang.reflect.Constructor<?> ctor : c.getDeclaredConstructors()) {
  862 + ctor.setAccessible(true);
  863 + final String fcn = cn;
  864 + XposedBridge.hookMethod(ctor, new XC_MethodHook() {
  865 + @Override protected void afterHookedMethod(MethodHookParam p) {
  866 + StringBuilder sb = new StringBuilder("[WeChatHook] " + fcn + ".<init>(");
  867 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  868 + if (i > 0) sb.append(", ");
  869 + sb.append(fmtArg(p.args[i]));
  870 + }
  871 + sb.append(") fields:");
  872 + for (Class<?> cc = p.thisObject.getClass();
  873 + cc != null && !cc.equals(Object.class); cc = cc.getSuperclass()) {
  874 + for (java.lang.reflect.Field f : cc.getDeclaredFields()) {
  875 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  876 + f.setAccessible(true);
  877 + try {
  878 + sb.append("\n ").append(f.getName()).append("=").append(fmtArg(f.get(p.thisObject)));
  879 + } catch (Throwable ignored) {}
  880 + }
  881 + }
  882 + XposedBridge.log(sb.toString());
  883 + }
  884 + });
  885 + }
  886 + XposedBridge.log("[WeChatHook] hookVoiceProbe: " + cn + " ctor hooked in " + procName);
  887 + } catch (Throwable t) {
  888 + XposedBridge.log("[WeChatHook] hookVoiceProbe " + cn + " failed: " + t);
  889 + }
  890 + }
  891 + }
  892 +
  893 + // ── Find the voice-send entry point ──────────────────────────────────────
  894 + // pu.o0 is the outer coroutine, launched by the real entry point (async, so
  895 + // it doesn't appear in the jg0.x.D stack). Hooking pu.o0's CONSTRUCTOR gives
  896 + // a synchronous stack trace revealing the method that starts a voice send.
  897 + // Also dumps qi3.f0/g0 constructors (the voice-message domain objects that
  898 + // carry talker/silk/duration).
  899 + private void hookVoiceEntry(ClassLoader cl, String procName) {
  900 + // pu.o0 constructor — stack trace = the real send entry point.
  901 + for (String cn : new String[]{"pu.o0", "pu.m0"}) {
  902 + try {
  903 + Class<?> c = XposedHelpers.findClass(cn, cl);
  904 + for (java.lang.reflect.Constructor<?> ctor : c.getDeclaredConstructors()) {
  905 + ctor.setAccessible(true);
  906 + final String fcn = cn;
  907 + final int np = ctor.getParameterTypes().length;
  908 + XposedBridge.hookMethod(ctor, new XC_MethodHook() {
  909 + private volatile boolean logged = false;
  910 + @Override protected void afterHookedMethod(MethodHookParam p) {
  911 + if (logged) return;
  912 + logged = true;
  913 + StringBuilder sb = new StringBuilder(
  914 + "[WeChatHook] " + fcn + ".<init>(" + np + ") args:");
  915 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  916 + Object a = p.args[i];
  917 + sb.append("\n arg[").append(i).append("]=")
  918 + .append(a == null ? "null" : a.getClass().getName());
  919 + }
  920 + sb.append("\n").append(android.util.Log.getStackTraceString(new Exception()));
  921 + XposedBridge.log(sb.toString());
  922 + }
  923 + });
  924 + }
  925 + XposedBridge.log("[WeChatHook] hookVoiceEntry: " + cn + " ctor hooked in " + procName);
  926 + } catch (Throwable t) {
  927 + XposedBridge.log("[WeChatHook] hookVoiceEntry " + cn + " failed: " + t);
  928 + }
  929 + }
  930 + // qi3.f0 / qi3.g0 constructors — dump their args (talker/silk/duration).
  931 + for (String cn : new String[]{"qi3.f0", "qi3.g0"}) {
  932 + try {
  933 + Class<?> c = XposedHelpers.findClass(cn, cl);
  934 + StringBuilder info = new StringBuilder("[WeChatHook] " + cn
  935 + + " super=" + c.getSuperclass().getName() + " fields:");
  936 + for (java.lang.reflect.Field f : c.getDeclaredFields())
  937 + info.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  938 + XposedBridge.log(info.toString());
  939 + for (java.lang.reflect.Constructor<?> ctor : c.getDeclaredConstructors()) {
  940 + ctor.setAccessible(true);
  941 + final String fcn = cn;
  942 + XposedBridge.hookMethod(ctor, new XC_MethodHook() {
  943 + private volatile boolean logged = false;
  944 + @Override protected void afterHookedMethod(MethodHookParam p) {
  945 + if (logged) return;
  946 + logged = true;
  947 + StringBuilder sb = new StringBuilder(
  948 + "[WeChatHook] " + fcn + ".<init> args:");
  949 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  950 + Object a = p.args[i];
  951 + String vs;
  952 + if (a == null) vs = "null";
  953 + else if (a instanceof byte[]) vs = "byte[" + ((byte[])a).length + "]";
  954 + else if (a instanceof String || a instanceof Number || a instanceof Boolean)
  955 + vs = a.getClass().getSimpleName() + "(" + a + ")";
  956 + else vs = a.getClass().getName();
  957 + sb.append("\n arg[").append(i).append("]=").append(vs);
  958 + }
  959 + // Dump the constructed object's fields too
  960 + for (Class<?> cc = p.thisObject.getClass();
  961 + cc != null && !cc.equals(Object.class); cc = cc.getSuperclass()) {
  962 + for (java.lang.reflect.Field f : cc.getDeclaredFields()) {
  963 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  964 + f.setAccessible(true);
  965 + try {
  966 + Object v = f.get(p.thisObject);
  967 + String vs;
  968 + if (v == null) vs = "null";
  969 + else if (v instanceof byte[]) vs = "byte[" + ((byte[])v).length + "]";
  970 + else if (v instanceof String || v instanceof Number || v instanceof Boolean) vs = v.toString();
  971 + else vs = v.getClass().getSimpleName();
  972 + sb.append("\n this.").append(f.getName()).append("=").append(vs);
  973 + } catch (Throwable ignored) {}
  974 + }
  975 + }
  976 + XposedBridge.log(sb.toString());
  977 + }
  978 + });
  979 + }
  980 + XposedBridge.log("[WeChatHook] hookVoiceEntry: " + cn + " ctor hooked in " + procName);
  981 + } catch (Throwable t) {
  982 + XposedBridge.log("[WeChatHook] hookVoiceEntry " + cn + " failed: " + t);
  983 + }
  984 + }
  985 + }
  986 +
  987 + // ── Hook jg0.j / jg0.x / g9 ─────────────────────────────────────────────
  988 + // Reveals the internal structure needed to call pt0.e0.r() synthetically.
  989 + // jg0.j captures the g9 (voice message / f9 subclass) as a field.
  990 + // jg0.x.D sets up jg0.j and starts the coroutine.
  991 + // g9 extends f9 (or is f9) with M9/N9 DB-insert methods.
  992 + private void hookJg0(ClassLoader cl, String procName) {
  993 + // ── jg0.j (the inner coroutine whose invokeSuspend calls pt0.e0.r) ────
  994 + try {
  995 + Class<?> jClass = XposedHelpers.findClass("jg0.j", cl);
  996 + StringBuilder jInfo = new StringBuilder("[WeChatHook] jg0.j class=" + jClass.getName()
  997 + + " super=" + jClass.getSuperclass().getName() + " ownFields:");
  998 + for (java.lang.reflect.Field f : jClass.getDeclaredFields())
  999 + jInfo.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  1000 + jInfo.append(" | superFields:");
  1001 + for (java.lang.reflect.Field f : jClass.getSuperclass().getDeclaredFields())
  1002 + jInfo.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  1003 + XposedBridge.log(jInfo.toString());
  1004 +
  1005 + // Hook invokeSuspend — fires every time a jg0.j coroutine step runs.
  1006 + // We only care about the FIRST call (state=0, label=0) to see captured fields.
  1007 + try {
  1008 + XposedHelpers.findAndHookMethod(jClass, "invokeSuspend", Object.class,
  1009 + new XC_MethodHook() {
  1010 + private volatile boolean sLogged = false;
  1011 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1012 + if (sLogged) return;
  1013 + sLogged = true;
  1014 + StringBuilder sb = new StringBuilder(
  1015 + "[WeChatHook] jg0.j.invokeSuspend FIRST fields:");
  1016 + for (Class<?> c = p.thisObject.getClass();
  1017 + c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1018 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1019 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1020 + f.setAccessible(true);
  1021 + try {
  1022 + Object v = f.get(p.thisObject);
  1023 + sb.append("\n ").append(c.getSimpleName())
  1024 + .append(".").append(f.getName()).append("=")
  1025 + .append(v == null ? "null"
  1026 + : v.getClass().getName() + "@" + System.identityHashCode(v));
  1027 + } catch (Throwable ignored) {}
  1028 + }
  1029 + }
  1030 + XposedBridge.log(sb.toString());
  1031 + }
  1032 + });
  1033 + } catch (Throwable t) {
  1034 + XposedBridge.log("[WeChatHook] hookJg0 jg0.j.invokeSuspend hook failed: " + t);
  1035 + }
  1036 + XposedBridge.log("[WeChatHook] hookJg0: jg0.j hooked in " + procName);
  1037 + } catch (Throwable t) {
  1038 + XposedBridge.log("[WeChatHook] hookJg0 jg0.j failed: " + t);
  1039 + }
  1040 +
  1041 + // ── jg0.x (coordinator that creates jg0.j and calls D to enqueue send) ──
  1042 + try {
  1043 + Class<?> xClass = XposedHelpers.findClass("jg0.x", cl);
  1044 + StringBuilder xInfo = new StringBuilder("[WeChatHook] jg0.x methods:");
  1045 + for (java.lang.reflect.Method m : xClass.getDeclaredMethods())
  1046 + xInfo.append(" ").append(m.getName()).append("(").append(m.getParameterTypes().length).append(")");
  1047 + xInfo.append(" | ownFields:");
  1048 + for (java.lang.reflect.Field f : xClass.getDeclaredFields())
  1049 + xInfo.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  1050 + XposedBridge.log(xInfo.toString());
  1051 +
  1052 + // Hook D() — the method called from pu.o0.invokeSuspend(84) that enqueues the send
  1053 + for (java.lang.reflect.Method m : xClass.getDeclaredMethods()) {
  1054 + if (!"D".equals(m.getName())) continue;
  1055 + m.setAccessible(true);
  1056 + final String sig = m.toGenericString();
  1057 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1058 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1059 + StringBuilder sb = new StringBuilder(
  1060 + "[WeChatHook] jg0.x.D ENTER sig=" + sig);
  1061 + // args
  1062 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  1063 + Object a = p.args[i];
  1064 + sb.append("\n arg[").append(i).append("]=")
  1065 + .append(a == null ? "null" : a.getClass().getName()
  1066 + + "@" + System.identityHashCode(a));
  1067 + // If it looks like a voice-msg / f9 subclass, dump its fields
  1068 + if (a != null) {
  1069 + for (Class<?> c2 = a.getClass();
  1070 + c2 != null && !c2.equals(Object.class); c2 = c2.getSuperclass()) {
  1071 + for (java.lang.reflect.Field f2 : c2.getDeclaredFields()) {
  1072 + if (java.lang.reflect.Modifier.isStatic(f2.getModifiers())) continue;
  1073 + f2.setAccessible(true);
  1074 + try {
  1075 + Object v2 = f2.get(a);
  1076 + String vs;
  1077 + if (v2 == null) vs = "null";
  1078 + else if (v2 instanceof byte[]) vs = "byte[" + ((byte[])v2).length + "]";
  1079 + else if (v2 instanceof String || v2 instanceof Number
  1080 + || v2 instanceof Boolean) vs = v2.toString();
  1081 + else vs = v2.getClass().getSimpleName();
  1082 + sb.append("\n ").append(c2.getSimpleName())
  1083 + .append(".").append(f2.getName()).append("=").append(vs);
  1084 + } catch (Throwable ignored2) {}
  1085 + }
  1086 + }
  1087 + }
  1088 + }
  1089 + // thisObject fields
  1090 + for (Class<?> c = p.thisObject.getClass();
  1091 + c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1092 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1093 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1094 + f.setAccessible(true);
  1095 + try {
  1096 + Object v = f.get(p.thisObject);
  1097 + sb.append("\n this.").append(c.getSimpleName())
  1098 + .append(".").append(f.getName()).append("=")
  1099 + .append(v == null ? "null" : v.getClass().getName());
  1100 + } catch (Throwable ignored) {}
  1101 + }
  1102 + }
  1103 + XposedBridge.log(sb.toString());
  1104 + }
  1105 + });
  1106 + }
  1107 + XposedBridge.log("[WeChatHook] hookJg0: jg0.x hooked in " + procName);
  1108 + } catch (Throwable t) {
  1109 + XposedBridge.log("[WeChatHook] hookJg0 jg0.x failed: " + t);
  1110 + }
  1111 +
  1112 + // ── g9 (likely a subclass of f9; M9/N9 are the DB-insert methods) ─────
  1113 + try {
  1114 + Class<?> g9Class = XposedHelpers.findClass("com.tencent.mm.storage.g9", cl);
  1115 + StringBuilder g9Info = new StringBuilder("[WeChatHook] g9 super="
  1116 + + g9Class.getSuperclass().getName() + " methods:");
  1117 + for (java.lang.reflect.Method m : g9Class.getDeclaredMethods())
  1118 + g9Info.append(" ").append(m.getName()).append("(").append(m.getParameterTypes().length).append(")");
  1119 + g9Info.append(" | ownFields:");
  1120 + for (java.lang.reflect.Field f : g9Class.getDeclaredFields())
  1121 + g9Info.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  1122 + XposedBridge.log(g9Info.toString());
  1123 +
  1124 + for (java.lang.reflect.Method m : g9Class.getDeclaredMethods()) {
  1125 + if (!"M9".equals(m.getName()) && !"N9".equals(m.getName())) continue;
  1126 + m.setAccessible(true);
  1127 + final String mName2 = m.getName();
  1128 + final String mSig2 = m.toGenericString();
  1129 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1130 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1131 + StringBuilder sb = new StringBuilder(
  1132 + "[WeChatHook] g9." + mName2 + " ENTER sig=" + mSig2
  1133 + + " thisClass=" + p.thisObject.getClass().getName());
  1134 + if (p.args != null) for (int i = 0; i < p.args.length; i++)
  1135 + sb.append(" arg[").append(i).append("]=")
  1136 + .append(p.args[i] == null ? "null" : p.args[i].getClass().getName());
  1137 + XposedBridge.log(sb.toString());
  1138 + }
  1139 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1140 + if (p.hasThrowable())
  1141 + XposedBridge.log("[WeChatHook] g9." + mName2 + " THREW: " + p.getThrowable());
  1142 + else
  1143 + XposedBridge.log("[WeChatHook] g9." + mName2 + " OK ret=" + p.getResult());
  1144 + }
  1145 + });
  1146 + }
  1147 + XposedBridge.log("[WeChatHook] hookJg0: g9 hooked in " + procName);
  1148 + } catch (Throwable t) {
  1149 + XposedBridge.log("[WeChatHook] hookJg0 g9 failed: " + t);
  1150 + }
  1151 +
  1152 + // ── pu.o0 (outer coroutine that calls jg0.x.D) ───────────────────────
  1153 + // Hook invokeSuspend to see what it captures (especially the g9/voice data).
  1154 + try {
  1155 + Class<?> puClass = XposedHelpers.findClass("pu.o0", cl);
  1156 + StringBuilder puInfo = new StringBuilder("[WeChatHook] pu.o0 super="
  1157 + + puClass.getSuperclass().getName() + " | ownFields:");
  1158 + for (java.lang.reflect.Field f : puClass.getDeclaredFields())
  1159 + puInfo.append(" ").append(f.getName()).append("(").append(f.getType().getSimpleName()).append(")");
  1160 + XposedBridge.log(puInfo.toString());
  1161 +
  1162 + XposedHelpers.findAndHookMethod(puClass, "invokeSuspend", Object.class,
  1163 + new XC_MethodHook() {
  1164 + private volatile boolean sLogged2 = false;
  1165 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1166 + if (sLogged2) return;
  1167 + sLogged2 = true;
  1168 + StringBuilder sb = new StringBuilder(
  1169 + "[WeChatHook] pu.o0.invokeSuspend FIRST fields:");
  1170 + for (Class<?> c = p.thisObject.getClass();
  1171 + c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1172 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1173 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1174 + f.setAccessible(true);
  1175 + try {
  1176 + Object v = f.get(p.thisObject);
  1177 + sb.append("\n ").append(c.getSimpleName())
  1178 + .append(".").append(f.getName()).append("=")
  1179 + .append(v == null ? "null"
  1180 + : v.getClass().getName() + "@" + System.identityHashCode(v));
  1181 + } catch (Throwable ignored) {}
  1182 + }
  1183 + }
  1184 + XposedBridge.log(sb.toString());
  1185 + }
  1186 + });
  1187 + XposedBridge.log("[WeChatHook] hookJg0: pu.o0 hooked in " + procName);
  1188 + } catch (Throwable t) {
  1189 + XposedBridge.log("[WeChatHook] hookJg0 pu.o0 failed: " + t);
  1190 + }
  1191 + }
  1192 +
  1193 + private void hookR0H(ClassLoader cl, String procName) {
  1194 + try {
  1195 + Class<?> r0Class = XposedHelpers.findClass("w11.r0", cl);
  1196 + int hooked = 0;
  1197 + // Hook ALL methods named H on r0 — real voice sends may use H() or H(int), not just H(String).
  1198 + for (java.lang.reflect.Method m : r0Class.getDeclaredMethods()) {
  1199 + if (!m.getName().equals("H")) continue;
  1200 + final String sig = m.toGenericString();
  1201 + final boolean isHString = m.getParameterTypes().length == 1
  1202 + && m.getParameterTypes()[0] == String.class;
  1203 + m.setAccessible(true);
  1204 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1205 + @Override
  1206 + protected void beforeHookedMethod(MethodHookParam p) throws Throwable {
  1207 + String by = sCalledByUs ? "US" : "WeChat";
  1208 + XposedBridge.log("[WeChatHook] r0." + sig + " ENTER by=" + by + " proc=" + procName);
  1209 + // Capture real dispatcher from any real WeChat r0 H() call.
  1210 + if (!sCalledByUs) {
  1211 + try {
  1212 + Object disp = XposedHelpers.getObjectField(p.thisObject, "dispatcher");
  1213 + if (disp != null && !(disp instanceof java.lang.reflect.Proxy)) {
  1214 + sCapturedDispatcher = disp;
  1215 + XposedBridge.log("[WeChatHook] hookR0H: REAL dispatcher=" + disp.getClass().getName() + " from " + sig);
  1216 + }
  1217 + } catch (Throwable ignored) {}
  1218 + // Also dump r0 fields on first real send to capture full state.
  1219 + dumpR0Fields(p.thisObject, "r0.H-WeChat by=" + by + " proc=" + procName);
  1220 + } else if (isHString) {
  1221 + dumpR0Fields(p.thisObject, "r0.H-ENTER by=US proc=" + procName);
  1222 + }
  1223 + }
  1224 + @Override
  1225 + protected void afterHookedMethod(MethodHookParam p) throws Throwable {
  1226 + String by = sCalledByUs ? "US" : "WeChat";
  1227 + XposedBridge.log("[WeChatHook] r0.H() DONE by=" + by + " proc=" + procName
  1228 + + (p.hasThrowable() ? " THREW=" + p.getThrowable() : " OK"));
  1229 + }
  1230 + });
  1231 + hooked++;
  1232 + }
  1233 + XposedBridge.log("[WeChatHook] hookR0H: hooked " + hooked + " H() overloads in " + procName);
  1234 + } catch (Throwable t) {
  1235 + XposedBridge.log("[WeChatHook] hookR0H failed in " + procName + ": " + t);
  1236 + }
  1237 + }
  1238 +
  1239 + // ── Capture live network dispatcher (com.tencent.mm.modelbase.m2) ────────────
  1240 + // m2 = MicroMsg.RDispatcher, the com.tencent.mm.network.s the send scene needs.
  1241 + // We grab the instance at construction (network init, before any synthetic send)
  1242 + // into sCapturedDispatcher, so sendVoiceViaAPI can hand r0 the REAL dispatcher.
  1243 + private void hookDispatcher(ClassLoader cl, String procName) {
  1244 + try {
  1245 + Class<?> m2 = XposedHelpers.findClass("com.tencent.mm.modelbase.m2", cl);
  1246 + XC_MethodHook grab = new XC_MethodHook() {
  1247 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1248 + if (sCapturedDispatcher == null && p.thisObject != null
  1249 + && !(p.thisObject instanceof java.lang.reflect.Proxy)) {
  1250 + sCapturedDispatcher = p.thisObject;
  1251 + XposedBridge.log("[WeChatHook] hookDispatcher: captured REAL m2="
  1252 + + p.thisObject + " in " + procName);
  1253 + }
  1254 + }
  1255 + };
  1256 + int n = 0;
  1257 + // Ctor: catches m2 constructed AFTER we install (network re-init).
  1258 + for (java.lang.reflect.Constructor<?> c : m2.getDeclaredConstructors()) {
  1259 + c.setAccessible(true);
  1260 + XposedBridge.hookMethod(c, new XC_MethodHook() {
  1261 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1262 + sCapturedDispatcher = p.thisObject;
  1263 + XposedBridge.log("[WeChatHook] hookDispatcher: captured REAL m2 (ctor)="
  1264 + + p.thisObject + " in " + procName);
  1265 + }
  1266 + });
  1267 + n++;
  1268 + }
  1269 + // Instance methods: catches an ALREADY-existing m2 (constructed before our
  1270 + // hook / persistent connection) on its next network call. After capture the
  1271 + // callback is a single null check — negligible overhead.
  1272 + int mh = 0;
  1273 + for (java.lang.reflect.Method m : m2.getDeclaredMethods()) {
  1274 + if (java.lang.reflect.Modifier.isStatic(m.getModifiers())) continue;
  1275 + if (java.lang.reflect.Modifier.isAbstract(m.getModifiers())) continue;
  1276 + try { m.setAccessible(true); XposedBridge.hookMethod(m, grab); mh++; }
  1277 + catch (Throwable ignored) {}
  1278 + }
  1279 + XposedBridge.log("[WeChatHook] hookDispatcher: hooked " + n + " ctor(s) + "
  1280 + + mh + " method(s) on m2 in " + procName);
  1281 + } catch (Throwable t) {
  1282 + XposedBridge.log("[WeChatHook] hookDispatcher failed in " + procName + ": " + t);
  1283 + }
  1284 + }
  1285 +
  1286 + // ── Instrument voice-upload service w21.g1 (voiceinfo table) ─────────────────
  1287 + // On a REAL voice send, WeChat builds a w21.w0 upload-task and calls g1.L0(w0)
  1288 + // (insert) / g1.P0(file, w0) (upload). Dump every w0 field on those calls so we
  1289 + // learn the exact template (FileName/ClientId/MsgLocalId/VoiceLength/MsgTalker/
  1290 + // Status correlation) needed to synthesize the upload for hook-sent voice.
  1291 + // ── Voice hot-swap: replace recorded SILK with our TTS at the CDN-upload step ─
  1292 + // jg0.x.w(jg0.x self, qi3.d0, w21.w0, int type, int durationMs, w21.t silk, Cont)
  1293 + // is WeChat's uploadAttach step (confirmed by real-recording capture + tinker
  1294 + // decompile). w21.t has exactly one byte[] field (f443506a) = the SILK audio
  1295 + // about to be sent to CDN. When armed, we overwrite that byte[] with our TTS
  1296 + // SILK and the duration int (arg4). WeChat then uploads + delivers OUR audio,
  1297 + // reusing the entire real send pipeline we cannot rebuild.
  1298 + // Hook runs in the process where recording happens (main). Verified swap target,
  1299 + // but does its own field dump on every fire so a first real test confirms layout.
  1300 + private void hookVoiceSwap(ClassLoader cl, String procName) {
  1301 + try {
  1302 + Class<?> xClass = XposedHelpers.findClass("jg0.x", cl);
  1303 + int hooked = 0;
  1304 + for (java.lang.reflect.Method m : xClass.getDeclaredMethods()) {
  1305 + if (!"w".equals(m.getName())) continue; // hook EVERY 'w' overload
  1306 + m.setAccessible(true);
  1307 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1308 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1309 + // Absolute-first, arg-safe entry log so we KNOW the hook runs.
  1310 + int n = (p.args == null) ? 0 : p.args.length;
  1311 + XposedBridge.log("[WeChatHook] SWAPHOOK ENTER w nargs=" + n + " armed=" + sSwapArmed);
  1312 + try {
  1313 + // Real uploadAttach call: (jg0.x, qi3.d0, w21.w0, int, int, w21.t, Cont).
  1314 + // Coroutine resumptions re-call w with nulls — skip those.
  1315 + if (n != 7 || p.args[5] == null) return;
  1316 + Object tHolder = p.args[5]; // w21.t (SILK holder)
  1317 + java.lang.reflect.Field byteF = null;
  1318 + for (java.lang.reflect.Field f : tHolder.getClass().getDeclaredFields()) {
  1319 + if (f.getType() == byte[].class) { byteF = f; break; }
  1320 + }
  1321 + if (byteF == null) return;
  1322 + byteF.setAccessible(true);
  1323 + byte[] orig = (byte[]) byteF.get(tHolder);
  1324 + XposedBridge.log("[WeChatHook] SWAPHOOK real w: silk="
  1325 + + (orig == null ? "null" : orig.length + "B") + " durArg=" + p.args[4]
  1326 + + " holder=" + tHolder.getClass().getName());
  1327 + if (!sSwapArmed || sSwapSilk == null) return;
  1328 +
  1329 + byteF.set(tHolder, sSwapSilk);
  1330 + if (orig != null) {
  1331 + for (java.lang.reflect.Field f : tHolder.getClass().getDeclaredFields()) {
  1332 + if (f.getType() != int.class) continue;
  1333 + f.setAccessible(true);
  1334 + if (f.getInt(tHolder) == orig.length) f.setInt(tHolder, sSwapSilk.length);
  1335 + }
  1336 + }
  1337 + if (sSwapDuration > 0) p.args[4] = sSwapDuration;
  1338 + XposedBridge.log("[WeChatHook] VOICE SWAP DONE: "
  1339 + + (orig == null ? "?" : orig.length) + "B -> " + sSwapSilk.length
  1340 + + "B, dur -> " + p.args[4]);
  1341 + sSwapArmed = false; // one-shot
  1342 + sSwapSilk = null;
  1343 + } catch (Throwable t) {
  1344 + XposedBridge.log("[WeChatHook] VOICE SWAP failed: " + t
  1345 + + "\n" + android.util.Log.getStackTraceString(t));
  1346 + }
  1347 + }
  1348 + });
  1349 + hooked++;
  1350 + }
  1351 + XposedBridge.log("[WeChatHook] hookVoiceSwap: hooked jg0.x.w x" + hooked + " in " + procName);
  1352 + } catch (Throwable t) {
  1353 + XposedBridge.log("[WeChatHook] hookVoiceSwap failed in " + procName + ": " + t);
  1354 + }
  1355 + }
  1356 +
  1357 + // ── Full field dump across the whole class hierarchy (for RE capture) ────────
  1358 + private static void dumpFieldsDeep(Object o, String tag) {
  1359 + if (o == null) { XposedBridge.log("[WeChatHook] " + tag + " = null"); return; }
  1360 + try {
  1361 + StringBuilder sb = new StringBuilder("[WeChatHook] " + tag + " (" + o.getClass().getName() + "):");
  1362 + for (Class<?> c = o.getClass(); c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1363 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1364 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1365 + f.setAccessible(true);
  1366 + Object v; try { v = f.get(o); } catch (Throwable t) { continue; }
  1367 + String vs = v == null ? "null"
  1368 + : (v instanceof byte[] ? "byte[" + ((byte[]) v).length + "]"
  1369 + : (v instanceof String || v instanceof Number || v instanceof Boolean ? v.toString()
  1370 + : v.getClass().getName() + "@" + System.identityHashCode(v)));
  1371 + if (vs.length() > 200) vs = vs.substring(0, 200) + "…";
  1372 + sb.append("\n ").append(f.getName()).append(" (").append(f.getType().getSimpleName()).append(") = ").append(vs);
  1373 + }
  1374 + }
  1375 + XposedBridge.log(sb.toString());
  1376 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] dumpFieldsDeep err: " + t); }
  1377 + }
  1378 +
  1379 + // ── Trace the CDN upload submission for voice (the missing full-synthesis layer) ─
  1380 + // Real voice send: jg0.x.u builds a dn.m task (field_fileType=15, field_fullpath=
  1381 + // voice2 amr, field_mediaId="VideoData"+id, aesKey/fileId empty) and drives the CDN
  1382 + // engine (h2.d=addSendTask → l1.u → native CdnManager.startC2CUpload). The native
  1383 + // side ASSIGNS aeskey+fileId, returned in dn.h to l1.keep_onUploadSuccessed, then
  1384 + // jg0.x.u writes them back to the voiceinfo protobuf + newsendmsg. We OBSERVE only
  1385 + // (no modification) so a real recording still delivers, and we capture the exact
  1386 + // dn.m template + assigned aeskey/fileId to replicate CDN upload for synthetic voice.
  1387 + private void hookCdnTrace(ClassLoader cl, String procName) {
  1388 + // 1) h2.d(dn.m) = addSendTask — dump the full task struct on submit.
  1389 + try {
  1390 + Class<?> h2 = XposedHelpers.findClass("com.tencent.mm.modelcdntran.h2", cl);
  1391 + Class<?> dnm = XposedHelpers.findClass("dn.m", cl);
  1392 + XposedBridge.hookMethod(h2.getDeclaredMethod("d", dnm), new XC_MethodHook() {
  1393 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1394 + XposedBridge.log("[WeChatHook] CDNTRACE h2.d(addSendTask) ENTER");
  1395 + if (p.args != null && p.args.length > 0) dumpFieldsDeep(p.args[0], "CDNTRACE addSendTask dn.m");
  1396 + }
  1397 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1398 + XposedBridge.log("[WeChatHook] CDNTRACE h2.d ret=" + p.getResult());
  1399 + }
  1400 + });
  1401 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked h2.d(addSendTask) in " + procName);
  1402 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace h2.d failed in " + procName + ": " + t); }
  1403 +
  1404 + // 2) l1.keep_onUpload* — the native CDN callback carrying assigned aeskey/fileId (dn.h).
  1405 + try {
  1406 + Class<?> l1 = XposedHelpers.findClass("com.tencent.mm.modelcdntran.l1", cl);
  1407 + int n = 0;
  1408 + for (java.lang.reflect.Method m : l1.getDeclaredMethods()) {
  1409 + if (!m.getName().startsWith("keep_onUpload")) continue;
  1410 + m.setAccessible(true);
  1411 + final String mn = m.getName();
  1412 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1413 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1414 + XposedBridge.log("[WeChatHook] CDNTRACE l1." + mn + " nargs=" + (p.args == null ? 0 : p.args.length));
  1415 + if (p.args != null) for (Object a : p.args) {
  1416 + if (a != null && a.getClass().getName().equals("dn.h")) dumpFieldsDeep(a, "CDNTRACE " + mn + " dn.h");
  1417 + }
  1418 + }
  1419 + });
  1420 + n++;
  1421 + }
  1422 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked l1.keep_onUpload* x" + n + " in " + procName);
  1423 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace l1 failed in " + procName + ": " + t); }
  1424 +
  1425 + // 3) jg0.x.u — the orchestrator (builds dn.m, writes aeskey back). Log entry to
  1426 + // confirm it fires + timing vs the CDN calls.
  1427 + try {
  1428 + Class<?> x = XposedHelpers.findClass("jg0.x", cl);
  1429 + int n = 0;
  1430 + for (java.lang.reflect.Method m : x.getDeclaredMethods()) {
  1431 + if (!"u".equals(m.getName())) continue;
  1432 + m.setAccessible(true);
  1433 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1434 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1435 + XposedBridge.log("[WeChatHook] CDNTRACE jg0.x.u ENTER nargs=" + (p.args == null ? 0 : p.args.length));
  1436 + if (p.args != null && p.args.length > 1 && p.args[1] != null)
  1437 + dumpFieldsDeep(p.args[1], "CDNTRACE jg0.x.u w21.w0");
  1438 + }
  1439 + });
  1440 + n++;
  1441 + }
  1442 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked jg0.x.u x" + n + " in " + procName);
  1443 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace jg0.x.u failed in " + procName + ": " + t); }
  1444 + }
  1445 +
  1446 + // ── Capture the real uploadvoice cgi request (this device's actual voice path) ──
  1447 + // This device uses the INLINE-cgi branch of jg0.x.w (not CDN): it builds a
  1448 + // com.tencent.mm.modelbase.l reqresp with url /cgi-bin/micromsg-bin/uploadvoice,
  1449 + // request pb r45.cv6 carrying the SILK inline in field 7. The scene
  1450 + // (modelbase.i.f70699d, a NetScene = m1 subclass) can be submitted via z2.b — the
  1451 + // SAME queue our text send uses. Hook modelbase.l.a() (the reqresp builder, fires
  1452 + // mid-jg0.x.w) filtered to the uploadvoice url, and dump every cv6 field index so
  1453 + // we can replicate the exact wire request for fully-synthetic voice.
  1454 + private void hookVoiceCgiCapture(ClassLoader cl, String procName) {
  1455 + try {
  1456 + Class<?> lCls = XposedHelpers.findClass("com.tencent.mm.modelbase.l", cl);
  1457 + final Class<?> pbCls = XposedHelpers.findClass("com.tencent.mm.protobuf.f", cl);
  1458 + XposedBridge.hookMethod(lCls.getDeclaredMethod("a"), new XC_MethodHook() {
  1459 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1460 + try {
  1461 + // Field names differ base-vs-tinker, so locate by TYPE: the url String
  1462 + // (contains cgi-bin) + the request/response protobufs (protobuf.f).
  1463 + Object self = p.thisObject;
  1464 + String url = null;
  1465 + java.util.List<Object> pbs = new java.util.ArrayList<>();
  1466 + for (Class<?> c = self.getClass(); c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1467 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1468 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1469 + f.setAccessible(true);
  1470 + Object v; try { v = f.get(self); } catch (Throwable t) { continue; }
  1471 + if (v instanceof String && ((String) v).contains("cgi-bin")) url = (String) v;
  1472 + else if (v != null && pbCls.isInstance(v)) pbs.add(v);
  1473 + }
  1474 + }
  1475 + if (url == null || !url.contains("uploadvoice")) return; // gate: voice cgi only
  1476 + StringBuilder sb = new StringBuilder("[WeChatHook] VOICECGI url=" + url + " pbCount=" + pbs.size());
  1477 + int idx = 0;
  1478 + for (Object req : pbs) {
  1479 + sb.append("\n -- pb#").append(idx++).append(" ").append(req.getClass().getName()).append(" --");
  1480 + for (int i = 0; i <= 25; i++) {
  1481 + Object val = null; String kind = "";
  1482 + try { Object c = XposedHelpers.callMethod(req, "getCustom", i);
  1483 + if (c != null) { val = "custom:" + c.getClass().getName(); kind = "C"; } } catch (Throwable t) {}
  1484 + if (val == null) { try { Object s = XposedHelpers.callMethod(req, "getString", i); if (s != null) { val = s; kind = "S"; } } catch (Throwable t) {} }
  1485 + if (val == null) { try { Object iv = XposedHelpers.callMethod(req, "getInteger", i); if (iv != null && ((Integer) iv) != 0) { val = iv; kind = "I"; } } catch (Throwable t) {} }
  1486 + if (val == null) { try { Object lv = XposedHelpers.callMethod(req, "getLong", i); if (lv != null && ((Long) lv) != 0L) { val = lv; kind = "L"; } } catch (Throwable t) {} }
  1487 + if (val != null) {
  1488 + String vs = String.valueOf(val);
  1489 + if (vs.length() > 140) vs = vs.substring(0, 140) + "…";
  1490 + sb.append("\n [").append(i).append("](").append(kind).append(")=").append(vs);
  1491 + }
  1492 + }
  1493 + }
  1494 + XposedBridge.log(sb.toString());
  1495 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] VOICECGI err: " + t); }
  1496 + }
  1497 + });
  1498 + XposedBridge.log("[WeChatHook] hookVoiceCgiCapture: hooked modelbase.l.a() in " + procName);
  1499 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookVoiceCgiCapture failed in " + procName + ": " + t); }
  1500 + }
  1501 +
  1502 + private void hookVoiceUpload(ClassLoader cl, String procName) {
  1503 + try {
  1504 + Class<?> g1 = XposedHelpers.findClass("w21.g1", cl);
  1505 + int mh = 0;
  1506 + for (java.lang.reflect.Method m : g1.getDeclaredMethods()) {
  1507 + final String mName = m.getName();
  1508 + // L0(w0)=insert, P0(file,w0)=upload, D0/J0/y0/z0=lookups. Dump w0 on all.
  1509 + if (!("L0".equals(mName) || "P0".equals(mName))) continue;
  1510 + m.setAccessible(true);
  1511 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1512 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1513 + try {
  1514 + // find the w0 arg (w21.w0) among args
  1515 + Object w0 = null;
  1516 + if (p.args != null) for (Object a : p.args)
  1517 + if (a != null && a.getClass().getName().equals("w21.w0")) { w0 = a; break; }
  1518 + StringBuilder sb = new StringBuilder("[WeChatHook] g1." + mName
  1519 + + " by=" + (sCalledByUs ? "US" : "REAL") + " args=[");
  1520 + if (p.args != null) for (int i = 0; i < p.args.length; i++) {
  1521 + Object a = p.args[i];
  1522 + sb.append(i > 0 ? ", " : "").append(a == null ? "null"
  1523 + : (a instanceof String ? "\"" + a + "\"" : a.getClass().getSimpleName()));
  1524 + }
  1525 + sb.append("]");
  1526 + if (w0 != null) {
  1527 + sb.append("\n w21.w0 DUMP:");
  1528 + for (java.lang.reflect.Field f : w0.getClass().getDeclaredFields()) {
  1529 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1530 + f.setAccessible(true);
  1531 + Object v = f.get(w0);
  1532 + String vs = v == null ? "null"
  1533 + : (v instanceof byte[] ? "byte[" + ((byte[]) v).length + "]"
  1534 + : (v instanceof String || v instanceof Number || v instanceof Boolean ? v.toString()
  1535 + : v.getClass().getSimpleName()));
  1536 + sb.append("\n ").append(f.getName()).append("=").append(vs);
  1537 + }
  1538 + }
  1539 + XposedBridge.log(sb.toString());
  1540 + } catch (Throwable ignored) {}
  1541 + }
  1542 + });
  1543 + mh++;
  1544 + }
  1545 + XposedBridge.log("[WeChatHook] hookVoiceUpload: hooked " + mh + " g1 method(s) in " + procName);
  1546 + } catch (Throwable t) {
  1547 + XposedBridge.log("[WeChatHook] hookVoiceUpload failed in " + procName + ": " + t);
  1548 + }
  1549 + }
  1550 +
  1551 + // ── Image send: hook b80.u.pj/Bi (the real non-suspend send entry) ───────────
  1552 + // b80.u (implements o70.e, = n0.c(o70.e.class)) is the image plugin. The send
  1553 + // coroutine b80.s calls b80.u.Bi(o70.h,String) then b80.u.pj(o70.h). We hook both
  1554 + // to (1) capture the live b80.u instance and (2) on a REAL image send, dump the
  1555 + // full o70.h (PreBuildParams) field-by-field — that's the exact recipe to replicate.
  1556 + private static void dumpO70h(Object h, String tag) {
  1557 + try {
  1558 + StringBuilder sb = new StringBuilder("[WeChatHook] " + tag + " o70.h DUMP:");
  1559 + for (java.lang.reflect.Field f : h.getClass().getDeclaredFields()) {
  1560 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1561 + f.setAccessible(true);
  1562 + Object v = f.get(h);
  1563 + String vs = v == null ? "null"
  1564 + : (v instanceof byte[] ? "byte[" + ((byte[]) v).length + "]"
  1565 + : (v instanceof String || v instanceof Number || v instanceof Boolean || v instanceof android.net.Uri
  1566 + ? v.toString() : v.getClass().getName() + "@" + System.identityHashCode(v)));
  1567 + sb.append("\n ").append(f.getName()).append(" (").append(f.getType().getSimpleName())
  1568 + .append(") = ").append(vs);
  1569 + }
  1570 + XposedBridge.log(sb.toString());
  1571 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] dumpO70h err: " + t); }
  1572 + }
  1573 +
  1574 + // Hook SendImgProxyUI.onCreate → dump the launch Intent extras. Real gallery image
  1575 + // sends run through this proxy Activity ($$a.run → b80.s coroutine → send). Capturing
  1576 + // its Intent lets us replay the WHOLE real flow via `am start` with the same extras.
  1577 + private void hookSendImgProxyUI(ClassLoader cl, String procName) {
  1578 + try {
  1579 + XposedHelpers.findAndHookMethod(
  1580 + "com.tencent.mm.ui.chatting.SendImgProxyUI", cl, "onCreate",
  1581 + android.os.Bundle.class, new XC_MethodHook() {
  1582 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1583 + try {
  1584 + android.content.Intent it = (android.content.Intent)
  1585 + XposedHelpers.callMethod(p.thisObject, "getIntent");
  1586 + if (it == null) { XposedBridge.log("[WeChatHook] SendImgProxyUI: intent null"); return; }
  1587 + android.os.Bundle ex = it.getExtras();
  1588 + StringBuilder sb = new StringBuilder("[WeChatHook] SendImgProxyUI INTENT:");
  1589 + sb.append("\n action=").append(it.getAction());
  1590 + sb.append("\n data=").append(it.getDataString());
  1591 + if (ex != null) for (String key : ex.keySet()) {
  1592 + Object v = ex.get(key);
  1593 + String vs = v == null ? "null"
  1594 + : (v instanceof java.util.ArrayList ? "ArrayList" + v
  1595 + : (v.getClass().isArray() ? v.getClass().getSimpleName() + java.util.Arrays.deepToString(new Object[]{v})
  1596 + : v.toString()));
  1597 + if (vs.length() > 300) vs = vs.substring(0, 300) + "…";
  1598 + sb.append("\n [").append(key).append("] (")
  1599 + .append(v == null ? "?" : v.getClass().getName()).append(") = ").append(vs);
  1600 + }
  1601 + XposedBridge.log(sb.toString());
  1602 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] SendImgProxyUI dump err: " + t); }
  1603 + }
  1604 + });
  1605 + XposedBridge.log("[WeChatHook] hookSendImgProxyUI OK in " + procName);
  1606 + } catch (Throwable t) {
  1607 + XposedBridge.log("[WeChatHook] hookSendImgProxyUI failed in " + procName + ": " + t);
  1608 + }
  1609 + }
  1610 +
  1611 + private void hookImageSend(ClassLoader cl, String procName) {
  1612 + try {
  1613 + Class<?> u = XposedHelpers.findClass("b80.u", cl);
  1614 + int n = 0;
  1615 + for (java.lang.reflect.Method m : u.getDeclaredMethods()) {
  1616 + final String mn = m.getName();
  1617 + if (!("pj".equals(mn) || "Bi".equals(mn) || "oj".equals(mn))) continue;
  1618 + Class<?>[] pts = m.getParameterTypes();
  1619 + if (pts.length < 1) continue;
  1620 + final boolean isOj = "oj".equals(mn); // oj(o70.k) = the insert/send step
  1621 + if (!isOj && !pts[0].getName().equals("o70.h")) continue;
  1622 + m.setAccessible(true);
  1623 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1624 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1625 + if (sImgPlugin == null && p.thisObject != null) {
  1626 + sImgPlugin = p.thisObject;
  1627 + XposedBridge.log("[WeChatHook] hookImageSend: captured b80.u=" + p.thisObject);
  1628 + }
  1629 + if (!sCalledByUs && p.args != null && p.args.length > 0 && p.args[0] != null) {
  1630 + if (isOj) {
  1631 + // o70.k — the insert object. Dump its full field tree.
  1632 + Object k = p.args[0];
  1633 + sRealImgK = k;
  1634 + XposedBridge.log("[WeChatHook] b80.u.oj REAL o70.k class=" + k.getClass().getName());
  1635 + dumpO70h(k, "b80.u.oj REAL o70.k");
  1636 + } else {
  1637 + sRealImgParams = p.args[0];
  1638 + dumpO70h(p.args[0], "b80.u." + mn + " REAL");
  1639 + }
  1640 + }
  1641 + }
  1642 + });
  1643 + n++;
  1644 + }
  1645 + XposedBridge.log("[WeChatHook] hookImageSend: hooked " + n + " b80.u method(s) in " + procName);
  1646 + } catch (Throwable t) {
  1647 + XposedBridge.log("[WeChatHook] hookImageSend failed in " + procName + ": " + t);
  1648 + }
  1649 + }
  1650 +
  1651 + // ── Voice send via internal API ────────────────────────────────────────────
  1652 + // Protocol (confirmed by hooking f9.convertTo() on real user send):
  1653 + // • content XML: <msg><voicemsg voicelength="{ms}" fromusername="{wxid}" isPlayed="false"></voicemsg></msg>
  1654 + // • imgPath : 26-char hex voice file ID (f9 field, determines file location)
  1655 + // • voice2 dir : voice2/md5(voiceId)[0:2]/md5(voiceId)[2:4]/msg_{voiceId}.amr (confirmed formula)
  1656 + //
  1657 + // Two modes (mutually exclusive extras):
  1658 + // (a) voice_id — caller pre-placed the SILK file in voice2 already (no file I/O here)
  1659 + // (b) src_path — WeChat-readable path (e.g. /data/data/com.tencent.mm/cache/…);
  1660 + // hook generates voice_id, copies src_path → voice2/{dir}/msg_{id}.amr internally
  1661 + // (WeChat process has full access to its own data dir, unlike root which is SELinux-blocked)
  1662 + //
  1663 + // Typical flow for TTS voice:
  1664 + // root: cp tts.amr /data/data/com.tencent.mm/cache/hook_voice_src.amr && chown u0_a330 ...
  1665 + // broadcast: --es to filehelper --es src_path /data/data/com.tencent.mm/cache/hook_voice_src.amr --ei duration 3000
  1666 + private static void sendVoiceViaAPI(String talker, String voiceId, String srcPath,
  1667 + int durationMs, String fromWxId) throws Throwable {
  1668 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  1669 + if (cl == null) throw new IllegalStateException("classloader null");
  1670 +
  1671 + // ── File placement ───────────────────────────────────────────────────
  1672 + if (voiceId == null || voiceId.isEmpty()) {
  1673 + // Mode (b): generate voice_id and copy SILK from srcPath
  1674 + if (srcPath == null || srcPath.isEmpty())
  1675 + throw new IllegalArgumentException("need either voice_id or src_path");
  1676 + byte[] idBytes = new byte[13];
  1677 + new java.util.Random().nextBytes(idBytes);
  1678 + StringBuilder sb = new StringBuilder(26);
  1679 + for (byte b : idBytes) sb.append(String.format("%02x", b & 0xff));
  1680 + voiceId = sb.toString();
  1681 +
  1682 + java.security.MessageDigest md5 = java.security.MessageDigest.getInstance("MD5");
  1683 + byte[] mdBytes = md5.digest(voiceId.getBytes("UTF-8"));
  1684 + String dir1 = String.format("%02x", mdBytes[0] & 0xff);
  1685 + String dir2 = String.format("%02x", mdBytes[1] & 0xff);
  1686 +
  1687 + String mmDir = "/data/data/com.tencent.mm/MicroMsg/653cdc2320abb089e149a3f7a7683fcf";
  1688 + String destDir = mmDir + "/voice2/" + dir1 + "/" + dir2;
  1689 + String destPath = destDir + "/msg_" + voiceId + ".amr";
  1690 + new java.io.File(destDir).mkdirs();
  1691 + try (java.io.FileInputStream in = new java.io.FileInputStream(srcPath);
  1692 + java.io.FileOutputStream out = new java.io.FileOutputStream(destPath)) {
  1693 + byte[] buf = new byte[8192]; int n;
  1694 + while ((n = in.read(buf)) != -1) out.write(buf, 0, n);
  1695 + }
  1696 + new java.io.File(destPath).setReadable(true, false);
  1697 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: " + srcPath + " -> " + destPath);
  1698 + } else if (voiceId.length() != 26) {
  1699 + throw new IllegalArgumentException("voice_id must be 26 hex chars, got: " + voiceId);
  1700 + }
  1701 +
  1702 + // ── Build voice XML ──────────────────────────────────────────────────
  1703 + // fromusername is the sender's wxid. sMyWxid is auto-discovered from the first
  1704 + // real UI voice send; fall back to the known wxid for this device.
  1705 + String safeFrom = (fromWxId != null && !fromWxId.isEmpty())
  1706 + ? fromWxId
  1707 + : (sMyWxid != null ? sMyWxid : "wxid_51ap3m6p9xs722");
  1708 + String voiceXml = "<msg><voicemsg voicelength=\"" + durationMs
  1709 + + "\" fromusername=\"" + safeFrom + "\" isPlayed=\"false\"></voicemsg></msg>";
  1710 +
  1711 + // ── Probe f9 setter map BEFORE setting sPendingVoiceId ───────────────
  1712 + Class<?> f9Class = XposedHelpers.findClass("com.tencent.mm.storage.f9", cl);
  1713 + if (sF9SetterMap == null) sF9SetterMap = probeAllF9Setters(f9Class);
  1714 + if (!sF9SetterMap.containsKey("imgPath"))
  1715 + throw new IllegalStateException("imgPath setter not found in map: " + sF9SetterMap);
  1716 +
  1717 + // ── Synthetic lvbuffer (waveform visualization, NOT the SILK audio) ────
  1718 + // Real WeChat always stores exactly 74 bytes regardless of duration:
  1719 + // 4-byte header (0x7b 0x00 0x00 0x00) + 70 zero bytes. The size is fixed.
  1720 + byte[] syntheticLv = new byte[74];
  1721 + syntheticLv[0] = 0x7b;
  1722 + // bytes 1..73 default to 0x00
  1723 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: synthetic lvbuffer 74 bytes for " + durationMs + "ms");
  1724 +
  1725 + // ── Create r0: try Object-param ctor first (real WeChat voice path) ─────
  1726 + // WeChat has two 5-param r0 ctors:
  1727 + // (String, String, int, int, long) — timestamp variant
  1728 + // (String, String, int, int, Object) — audio-path variant (used by real voice sends)
  1729 + // The Object ctor stores the audio file reference that H() reads for CDN upload.
  1730 + // If it works, r0 sets imgPath internally and H() can find the SILK for upload.
  1731 + // Fall back to long ctor if the Object ctor throws.
  1732 + Class<?> r0Class = XposedHelpers.findClass("w11.r0", cl);
  1733 + sPendingVoiceId.set(voiceId);
  1734 + sPendingLvBuffer.set(syntheticLv);
  1735 + sCalledByUs = true;
  1736 + Object r0;
  1737 + try {
  1738 + try {
  1739 + // Pass the voice2 path (where we placed the SILK) as the Object arg.
  1740 + // Real WeChat passes the temp recording file; we pass our already-placed file.
  1741 + String voiceFilePath = srcPath != null ? srcPath
  1742 + : "/data/data/com.tencent.mm/MicroMsg/653cdc2320abb089e149a3f7a7683fcf/voice2/"
  1743 + + String.format("%02x", java.security.MessageDigest.getInstance("MD5")
  1744 + .digest(voiceId.getBytes("UTF-8"))[0] & 0xff)
  1745 + + "/" + String.format("%02x", java.security.MessageDigest.getInstance("MD5")
  1746 + .digest(voiceId.getBytes("UTF-8"))[1] & 0xff)
  1747 + + "/msg_" + voiceId + ".amr";
  1748 + r0 = XposedHelpers.newInstance(r0Class,
  1749 + new Class<?>[]{String.class, String.class, int.class, int.class, Object.class},
  1750 + talker, voiceXml, 34, 0, voiceFilePath);
  1751 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: used Object-ctor with path=" + voiceFilePath);
  1752 + } catch (Throwable e1) {
  1753 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: Object-ctor failed (" + e1 + "), falling back to long-ctor");
  1754 + long ts = System.currentTimeMillis();
  1755 + r0 = XposedHelpers.newInstance(r0Class,
  1756 + new Class<?>[]{String.class, String.class, int.class, int.class, long.class},
  1757 + talker, voiceXml, 34, 0, ts);
  1758 + }
  1759 + } finally {
  1760 + sCalledByUs = false;
  1761 + sPendingVoiceId.remove();
  1762 + sPendingLvBuffer.remove();
  1763 + }
  1764 + // Dump r0 fields so we can see which field holds the audio path.
  1765 + dumpR0Fields(r0, "r0-after-ctor by=US");
  1766 +
  1767 + // ── Leave r0.p == null: take the AUTHENTIC new-send path ──────────────────
  1768 + // The r0 Object-ctor already inserted a proper f9 (content=voiceXml, imgPath
  1769 + // injected by hookF9ImgPathInjector, status=1) via cj().N9(). With p==null,
  1770 + // NetSceneSendMsg.doScene() reloads that f9 fresh from the DB (cj().c6()) —
  1771 + // content/msgsource intact — and assembles + dispatches it, exactly like a
  1772 + // real new send.
  1773 + //
  1774 + // Previously we forced r0.p = sDatabaseF9. That sends doScene down the *resend*
  1775 + // branch (which expects status=5 and logs "should not be resend"), handing the
  1776 + // MsgSource assembler a stale in-memory f9 whose content reads null →
  1777 + // e14.k.fromXml(null) NPE. That was the root-cause blocker; fixed by NOT setting p.
  1778 + sDatabaseF9.remove();
  1779 +
  1780 + // ── Set dispatcher on r0 (required for CDN upload via H()) ─────────────
  1781 + // r0.dispatcher (type com.tencent.mm.network.s) is null in our synthetic r0.
  1782 + // H() NPEs on `dispatcher.J(z0, o0, int)` if null.
  1783 + // We capture dispatcher from the first real WeChat r0 that enters H() (hookR0H).
  1784 + if (sCapturedDispatcher != null && !(sCapturedDispatcher instanceof java.lang.reflect.Proxy)) {
  1785 + // Real dispatcher captured from a genuine WeChat send — use it directly.
  1786 + try {
  1787 + XposedHelpers.setObjectField(r0, "dispatcher", sCapturedDispatcher);
  1788 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: set r0.dispatcher REAL class="
  1789 + + sCapturedDispatcher.getClass().getName());
  1790 + } catch (Throwable ed) {
  1791 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: r0.dispatcher set failed: " + ed);
  1792 + }
  1793 + } else {
  1794 + // No real dispatcher yet — fall through to proxy creation below.
  1795 + // (Cached proxy is reused if already created; fresh one made otherwise.)
  1796 + // Dispatcher not yet captured — search WeChat singletons for it.
  1797 + // gm0.j1.i() returns the message manager which likely holds a dispatcher reference.
  1798 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: dispatcher null, searching singletons...");
  1799 + outer:
  1800 + for (String[] candidate : new String[][]{
  1801 + {"gm0.j1", "i"}, // message manager singleton
  1802 + {"tg3.t1", "a"}, // service locator
  1803 + }) {
  1804 + try {
  1805 + Class<?> mgr = XposedHelpers.findClass(candidate[0], cl);
  1806 + Object inst = XposedHelpers.callStaticMethod(mgr, candidate[1]);
  1807 + if (inst == null) continue;
  1808 + // Walk inst's fields recursively (depth 2) looking for dispatcher
  1809 + for (java.lang.reflect.Field f1 : inst.getClass().getDeclaredFields()) {
  1810 + if (java.lang.reflect.Modifier.isStatic(f1.getModifiers())) continue;
  1811 + f1.setAccessible(true);
  1812 + Object v1 = f1.get(inst);
  1813 + if (v1 == null) continue;
  1814 + // Level 1: try r0.dispatcher field name on v1 directly
  1815 + try {
  1816 + Object d = XposedHelpers.getObjectField(v1, "dispatcher");
  1817 + if (d != null) {
  1818 + sCapturedDispatcher = d;
  1819 + XposedBridge.log("[WeChatHook] dispatcher found: "
  1820 + + candidate[0] + "." + candidate[1] + "()." + f1.getName()
  1821 + + ".dispatcher=" + d.getClass().getName());
  1822 + XposedHelpers.setObjectField(r0, "dispatcher", d);
  1823 + break outer;
  1824 + }
  1825 + } catch (Throwable ignored1) {}
  1826 + // Level 2: walk v1's fields
  1827 + for (java.lang.reflect.Field f2 : v1.getClass().getDeclaredFields()) {
  1828 + if (java.lang.reflect.Modifier.isStatic(f2.getModifiers())) continue;
  1829 + f2.setAccessible(true);
  1830 + Object v2 = f2.get(v1);
  1831 + if (v2 == null) continue;
  1832 + try {
  1833 + Object d = XposedHelpers.getObjectField(v2, "dispatcher");
  1834 + if (d != null) {
  1835 + sCapturedDispatcher = d;
  1836 + XposedBridge.log("[WeChatHook] dispatcher found (L2): "
  1837 + + candidate[0] + "." + candidate[1] + "()."
  1838 + + f1.getName() + "." + f2.getName()
  1839 + + ".dispatcher=" + d.getClass().getName());
  1840 + XposedHelpers.setObjectField(r0, "dispatcher", d);
  1841 + break outer;
  1842 + }
  1843 + } catch (Throwable ignored2) {}
  1844 + }
  1845 + }
  1846 + } catch (Throwable t2) {
  1847 + XposedBridge.log("[WeChatHook] dispatcher search " + candidate[0] + ": " + t2);
  1848 + }
  1849 + }
  1850 + if (sCapturedDispatcher instanceof java.lang.reflect.Proxy) {
  1851 + // Already have a proxy from a previous voice send — reuse it on this r0.
  1852 + try {
  1853 + XposedHelpers.setObjectField(r0, "dispatcher", sCapturedDispatcher);
  1854 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: reusing proxy dispatcher on r0");
  1855 + } catch (Throwable ed2) {
  1856 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: proxy reuse failed: " + ed2);
  1857 + }
  1858 + } else if (sCapturedDispatcher == null) {
  1859 + // Still not found — create a minimal proxy for s that logs calls.
  1860 + // This lets H() proceed past the NPE; CDN upload may work via callback.
  1861 + try {
  1862 + Class<?> sInterface = XposedHelpers.findClass("com.tencent.mm.network.s", cl);
  1863 + java.lang.reflect.Method[] sMethods = sInterface.getDeclaredMethods();
  1864 + StringBuilder sb = new StringBuilder("[WeChatHook] s interface methods:\n");
  1865 + for (java.lang.reflect.Method m : sMethods) sb.append(" ").append(m.toGenericString()).append("\n");
  1866 + XposedBridge.log(sb.toString());
  1867 + Object dispProxy = java.lang.reflect.Proxy.newProxyInstance(cl,
  1868 + new Class<?>[]{sInterface},
  1869 + (proxy, method, args) -> {
  1870 + XposedBridge.log("[WeChatHook] dispatcher.proxy: " + method.getName()
  1871 + + " ret=" + method.getReturnType().getSimpleName());
  1872 + if ("J".equals(method.getName()) && args != null && args.length >= 2) {
  1873 + // ── Attempt 1: forward J() via l0 method on m05.j ──────────────
  1874 + // method.declaringClass = s (s has own J, NOT inherited from l0).
  1875 + // m05.j implements l0 (not s). Solution: get J() from l0 interface
  1876 + // and invoke THAT on m05.j — valid since m05.j implements l0.
  1877 + try {
  1878 + Object q2arg = args[1];
  1879 + Object mj = XposedHelpers.getObjectField(q2arg, "e");
  1880 + if (mj != null) {
  1881 + Class<?> l0Iface = XposedHelpers.findClass("com.tencent.mm.network.l0", cl);
  1882 + // Dump l0 methods for diagnosis
  1883 + StringBuilder l0log = new StringBuilder("[WeChatHook] l0 methods:");
  1884 + java.lang.reflect.Method foundL0J = null;
  1885 + for (java.lang.reflect.Method l0m : l0Iface.getDeclaredMethods()) {
  1886 + l0log.append(" ").append(l0m.getName()).append("(").append(l0m.getParameterTypes().length).append(")");
  1887 + if (l0m.getName().equals(method.getName())
  1888 + && l0m.getParameterTypes().length == method.getParameterTypes().length) {
  1889 + foundL0J = l0m;
  1890 + }
  1891 + }
  1892 + XposedBridge.log(l0log.toString());
  1893 + if (foundL0J != null) {
  1894 + foundL0J.setAccessible(true);
  1895 + XposedBridge.log("[WeChatHook] J→m05.j via l0.J()");
  1896 + try {
  1897 + Object result = foundL0J.invoke(mj, args);
  1898 + XposedBridge.log("[WeChatHook] J→m05.j l0 OK result=" + result);
  1899 + return result;
  1900 + } catch (java.lang.reflect.InvocationTargetException ite) {
  1901 + XposedBridge.log("[WeChatHook] J→m05.j l0 threw: " + ite.getCause());
  1902 + }
  1903 + } else {
  1904 + XposedBridge.log("[WeChatHook] J not found in l0 by name+paramcount");
  1905 + }
  1906 + }
  1907 + } catch (Throwable jt0) {
  1908 + XposedBridge.log("[WeChatHook] J→m05.j err: " + jt0);
  1909 + }
  1910 + // ── Attempt 2: find s implementor in J() args (skip l0-only classes) ──
  1911 + try {
  1912 + Class<?> sIface = XposedHelpers.findClass("com.tencent.mm.network.s", cl);
  1913 + for (Object searchRoot : new Object[]{args[0], args[1]}) {
  1914 + if (searchRoot == null) continue;
  1915 + for (Class<?> cls2 = searchRoot.getClass(); cls2 != null && !cls2.equals(Object.class); cls2 = cls2.getSuperclass()) {
  1916 + for (java.lang.reflect.Field sf1 : cls2.getDeclaredFields()) {
  1917 + if (java.lang.reflect.Modifier.isStatic(sf1.getModifiers())) continue;
  1918 + sf1.setAccessible(true);
  1919 + Object sv1 = sf1.get(searchRoot);
  1920 + if (sv1 == null || sv1 == proxy) continue;
  1921 + if (sIface.isInstance(sv1)) {
  1922 + sCapturedDispatcher = sv1;
  1923 + XposedBridge.log("[WeChatHook] J: REAL s L1 " + sv1.getClass().getName());
  1924 + try { return method.invoke(sv1, args); } catch (java.lang.reflect.InvocationTargetException ite) { throw ite.getCause(); }
  1925 + }
  1926 + // L2 sub-fields
  1927 + try {
  1928 + for (Class<?> cls3 = sv1.getClass(); cls3 != null && !cls3.equals(Object.class); cls3 = cls3.getSuperclass()) {
  1929 + for (java.lang.reflect.Field sf2 : cls3.getDeclaredFields()) {
  1930 + if (java.lang.reflect.Modifier.isStatic(sf2.getModifiers())) continue;
  1931 + sf2.setAccessible(true);
  1932 + Object sv2 = sf2.get(sv1);
  1933 + if (sv2 == null || sv2 == proxy) continue;
  1934 + if (sIface.isInstance(sv2)) {
  1935 + sCapturedDispatcher = sv2;
  1936 + XposedBridge.log("[WeChatHook] J: REAL s L2 " + sf1.getName() + "." + sf2.getName() + " " + sv2.getClass().getName());
  1937 + try { return method.invoke(sv2, args); } catch (java.lang.reflect.InvocationTargetException ite) { throw ite.getCause(); }
  1938 + }
  1939 + }
  1940 + }
  1941 + } catch (Throwable ignored4) {}
  1942 + }
  1943 + }
  1944 + }
  1945 + XposedBridge.log("[WeChatHook] J: no s implementor in args");
  1946 + } catch (Throwable jse) {
  1947 + XposedBridge.log("[WeChatHook] J: search err: " + jse);
  1948 + }
  1949 + // ── Deep-dump v2 (CDN request) sub-fields ───────────────────
  1950 + try {
  1951 + Object v2arg = args[0];
  1952 + StringBuilder cdnDump = new StringBuilder("[WeChatHook] J v2-deep:\n");
  1953 + // Walk class hierarchy (getDeclaredFields only finds own fields)
  1954 + for (Class<?> cls2 = v2arg.getClass(); cls2 != null && !cls2.equals(Object.class); cls2 = cls2.getSuperclass()) {
  1955 + for (java.lang.reflect.Field sf1 : cls2.getDeclaredFields()) {
  1956 + if (java.lang.reflect.Modifier.isStatic(sf1.getModifiers())) continue;
  1957 + sf1.setAccessible(true);
  1958 + Object sv1 = sf1.get(v2arg);
  1959 + cdnDump.append(" ").append(sf1.getName()).append("=")
  1960 + .append(sv1 == null ? "null" : sv1.getClass().getSimpleName()).append("\n");
  1961 + if (sv1 == null) continue;
  1962 + for (java.lang.reflect.Field sf2 : sv1.getClass().getDeclaredFields()) {
  1963 + if (java.lang.reflect.Modifier.isStatic(sf2.getModifiers())) continue;
  1964 + sf2.setAccessible(true);
  1965 + Object sv2 = sf2.get(sv1);
  1966 + String sv2s;
  1967 + if (sv2 == null) { sv2s = "null"; }
  1968 + else if (sv2 instanceof byte[]) {
  1969 + byte[] ba = (byte[]) sv2;
  1970 + StringBuilder hex = new StringBuilder();
  1971 + for (int xi = 0; xi < Math.min(ba.length, 20); xi++) hex.append(String.format("%02x", ba[xi] & 0xff));
  1972 + sv2s = "byte[" + ba.length + "]=" + hex;
  1973 + } else {
  1974 + sv2s = sv2.toString();
  1975 + if (sv2s.length() > 100) sv2s = sv2s.substring(0, 100);
  1976 + }
  1977 + cdnDump.append(" ").append(sf1.getName()).append(".").append(sf2.getName()).append("=").append(sv2s).append("\n");
  1978 + }
  1979 + }
  1980 + }
  1981 + XposedBridge.log(cdnDump.toString());
  1982 + } catch (Throwable jde) {
  1983 + XposedBridge.log("[WeChatHook] J v2-dump err: " + jde);
  1984 + }
  1985 + }
  1986 + if (method.getReturnType() == int.class || method.getReturnType() == Integer.class)
  1987 + return 0;
  1988 + if (method.getReturnType() == boolean.class || method.getReturnType() == Boolean.class)
  1989 + return false;
  1990 + return null;
  1991 + });
  1992 + sCapturedDispatcher = dispProxy;
  1993 + XposedHelpers.setObjectField(r0, "dispatcher", dispProxy);
  1994 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: dispatcher proxy set on r0");
  1995 + } catch (Throwable ep) {
  1996 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: dispatcher proxy failed: " + ep);
  1997 + }
  1998 + }
  1999 + }
  2000 +
  2001 + // ── u0 callback stub (same pattern as sendViaR0) ─────────────────────
  2002 + // r0.d (type com.tencent.mm.modelbase.u0) is null unless we set it;
  2003 + // H() calls u0.onSceneEnd which NPEs otherwise.
  2004 + // hStarted gates the u0 stub: ignore premature onSceneEnd (fires synchronously
  2005 + // when we set r0.d, BEFORE H() is called) and only act on H()'s async CDN callback.
  2006 + // Root cause: setting r0.d triggers an immediate "local save done" callback.
  2007 + // If we call K(0) there, WeChat marks the message as "completed" → H() skips CDN.
  2008 + final java.util.concurrent.atomic.AtomicBoolean hStarted =
  2009 + new java.util.concurrent.atomic.AtomicBoolean(false);
  2010 + try {
  2011 + Class<?> u0 = XposedHelpers.findClass("com.tencent.mm.modelbase.u0", cl);
  2012 + Object stub = Proxy.newProxyInstance(cl, new Class<?>[]{u0},
  2013 + (proxy, method, args) -> {
  2014 + StringBuilder params = new StringBuilder();
  2015 + if (args != null) {
  2016 + for (int i = 0; i < args.length; i++) {
  2017 + if (i > 0) params.append(", ");
  2018 + params.append(args[i]);
  2019 + }
  2020 + }
  2021 + XposedBridge.log("[WeChatHook] voice-cb: " + method.getName()
  2022 + + "(" + params + ") hStarted=" + hStarted.get());
  2023 + // onSceneEnd(int code, int errCode, String msg, m1 scene)
  2024 + // Real m2 dispatch: r0.onGYNetEnd handles the network result itself
  2025 + // (status/msgSvrId update, SendMsgSuccessEvent, K/I). This u0 only needs
  2026 + // to be non-null so that internal onSceneEnd call doesn't NPE — do NOT
  2027 + // call K/I here or success/fail events double-fire.
  2028 + if ("onSceneEnd".equals(method.getName()) && args != null && args.length >= 2) {
  2029 + XposedBridge.log("[WeChatHook] voice onSceneEnd code=" + args[0] + " err=" + args[1]);
  2030 + }
  2031 + return null;
  2032 + });
  2033 + XposedHelpers.setObjectField(r0, "d", stub);
  2034 + // Premature onSceneEnd fires synchronously during setObjectField above and is suppressed.
  2035 + } catch (Throwable t) {
  2036 + XposedBridge.log("[WeChatHook] u0 stub failed (non-fatal): " + t);
  2037 + }
  2038 +
  2039 + // ── Dispatch via WeChat's REAL NetSceneQueue ─────────────────────────────
  2040 + // Exactly the path the (now-working) internal text send uses. n1.a() does:
  2041 + // ((gm0.n) com.tencent.mm.modelbase.z2.f88087b).f290500a.f290528b.h(scene, 0)
  2042 + // The queue supplies the real network dispatcher and runs doScene properly:
  2043 + // p==null → it reloads our just-inserted voice f9 from the DB, assembles the
  2044 + // MsgSource, uploads the SILK to CDN, and transports to the server.
  2045 + //
  2046 + // This replaces the old manual r0.H()+fake-$Proxy dispatcher, which never
  2047 + // reached the network — real transport is the queue's job (routed via IPC to
  2048 + // the :push connection), NOT a hand-set main-process m2 (which is never even
  2049 + // exercised, so it can't be captured).
  2050 + hStarted.set(true);
  2051 + sCalledByUs = true;
  2052 + try {
  2053 + // z2.b(m1) = WeChat's own "run cgi" helper (IGetNetSceneQueue): enqueues the
  2054 + // scene into the real NetSceneQueue, which supplies the live dispatcher and
  2055 + // runs doScene. Using the static helper avoids hardcoding the queue's field
  2056 + // chain, whose obfuscated names differ between base.apk and the Tinker patch
  2057 + // (the running code). r0 extends m1, so this resolves b(m1) by assignability.
  2058 + Class<?> z2c = XposedHelpers.findClass("com.tencent.mm.modelbase.z2", cl);
  2059 + XposedHelpers.callStaticMethod(z2c, "b", r0);
  2060 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: enqueued via z2.b(NetSceneQueue) to=" + talker
  2061 + + " voiceId=" + voiceId + " durationMs=" + durationMs);
  2062 + } catch (Throwable t) {
  2063 + XposedBridge.log("[WeChatHook] sendVoiceViaAPI: enqueue threw: " + t
  2064 + + "\n" + android.util.Log.getStackTraceString(t));
  2065 + } finally {
  2066 + sCalledByUs = false;
  2067 + }
  2068 +
  2069 + // ── Trigger REAL delivery via ResendVoiceMsgEvent{f9} ──────────────────
  2070 + // Decompiling WeChat 8.0.74 revealed the real voice send path:
  2071 + // cg0.d(talker,file) → jg0.x(cg0.d) → sendCgi(m)+uploadAttach(w).
  2072 + // ResendVoiceMsgEvent (com.tencent.mm.autogen.events) carries a single f9
  2073 + // (field g = am.wr, wr.a = f9). Publishing it makes WeChat's voice-resend
  2074 + // handler run the FULL sendCgi + CDN upload for our already-inserted f9 —
  2075 + // i.e. the same machinery a real send uses. This replaces the dead
  2076 + // r0.H()/msgSvrId-poll path (delivery never happened → msgSvrId stayed 0).
  2077 + final Long msgLocalId = sPendingMsgLocalId.get();
  2078 + sPendingMsgLocalId.remove();
  2079 + sDatabaseF9.remove();
  2080 + final Object fPt0e0 = sPt0E0Instance;
  2081 + final String fTalker = talker;
  2082 + final ClassLoader fCl = cl;
  2083 + // ResendVoiceMsgEvent path CONFIRMED DEAD (2026-07-06): even after marking the
  2084 + // properly-inserted voice msg failed (status=5) and firing the event, WeChat's
  2085 + // resend handler does NOT respond — the message just shows red ! (failed), no
  2086 + // CDN upload. So this force-fails sends for nothing. Disabled. The remaining
  2087 + // real path is to build a voiceinfo/w0 upload task and drive w21.g1.P0() (or
  2088 + // reconstruct jg0.x). Kept for reference.
  2089 + if (false && msgLocalId != null) {
  2090 + new Thread(() -> {
  2091 + try {
  2092 + Thread.sleep(1500); // let the z2.b send settle first
  2093 + // Re-fetch the DB-bound f9 via pt0.e0.k(talker, msgLocalId).
  2094 + Object f9 = null;
  2095 + if (fPt0e0 != null) {
  2096 + try {
  2097 + java.lang.reflect.Method kM = null;
  2098 + for (java.lang.reflect.Method m : fPt0e0.getClass().getDeclaredMethods())
  2099 + if ("k".equals(m.getName()) && m.getParameterTypes().length == 2) { kM = m; break; }
  2100 + if (kM != null) { kM.setAccessible(true); f9 = kM.invoke(fPt0e0, fTalker, msgLocalId); }
  2101 + } catch (Throwable t) {
  2102 + XposedBridge.log("[WeChatHook] resend: k() failed: " + t);
  2103 + }
  2104 + }
  2105 + if (f9 == null) {
  2106 + XposedBridge.log("[WeChatHook] resend: f9 null for msgLocalId=" + msgLocalId + ", abort");
  2107 + return;
  2108 + }
  2109 + // Mark the message failed (status=5) + persist, so the resend handler
  2110 + // treats it as a resendable failed voice. f9.r1(int)=status setter;
  2111 + // pt0.e0.s(talker,msgId,f9) persists via cj().lb().
  2112 + try {
  2113 + XposedHelpers.callMethod(f9, "r1", 5);
  2114 + long mid = ((Number) XposedHelpers.callMethod(f9, "getMsgId")).longValue();
  2115 + if (fPt0e0 != null) {
  2116 + java.lang.reflect.Method sM = null;
  2117 + for (java.lang.reflect.Method m : fPt0e0.getClass().getDeclaredMethods())
  2118 + if ("s".equals(m.getName()) && m.getParameterTypes().length == 3) { sM = m; break; }
  2119 + if (sM != null) { sM.setAccessible(true); sM.invoke(fPt0e0, fTalker, mid, f9); }
  2120 + }
  2121 + XposedBridge.log("[WeChatHook] resend: marked f9 status=5 + persisted msgId=" + mid);
  2122 + } catch (Throwable t) {
  2123 + XposedBridge.log("[WeChatHook] resend: status=5 failed: " + t);
  2124 + }
  2125 + // Build ResendVoiceMsgEvent, set its f9 (field g -> wr.a), publish.
  2126 + Class<?> evCls = XposedHelpers.findClass(
  2127 + "com.tencent.mm.autogen.events.ResendVoiceMsgEvent", fCl);
  2128 + Object ev = evCls.newInstance();
  2129 + Object wr = XposedHelpers.getObjectField(ev, "g"); // am.wr
  2130 + XposedHelpers.setObjectField(wr, "a", f9);
  2131 + XposedHelpers.callMethod(ev, "b", Looper.getMainLooper());
  2132 + XposedBridge.log("[WeChatHook] resend: ResendVoiceMsgEvent published msgLocalId="
  2133 + + msgLocalId + " talker=" + fTalker + " f9=" + f9.getClass().getName());
  2134 + } catch (Throwable t) {
  2135 + XposedBridge.log("[WeChatHook] resend: failed: " + t);
  2136 + }
  2137 + }, "WCHook-resend-" + msgLocalId).start();
  2138 + } else {
  2139 + XposedBridge.log("[WeChatHook] resend: msgLocalId null, skip");
  2140 + }
  2141 + }
  2142 +
  2143 + // ── Factory method discovery ───────────────────────────────────────────────
  2144 + // Hooks ALL static methods on w11.s1 and logs their signatures + call args.
  2145 + // When WeChat UI sends image/voice, we'll see which s1 method is called and
  2146 + // what parameters it receives, revealing the builder API for each msgtype.
  2147 + private void hookFactoryMethods(ClassLoader cl, String procName) {
  2148 + try {
  2149 + Class<?> s1 = XposedHelpers.findClass("w11.s1", cl);
  2150 + java.lang.reflect.Method[] methods = s1.getDeclaredMethods();
  2151 +
  2152 + // Dump all method signatures immediately
  2153 + StringBuilder sb = new StringBuilder();
  2154 + sb.append("[WeChatHook] w11.s1 ALL METHODS (").append(methods.length).append("):\n");
  2155 + for (java.lang.reflect.Method m : methods) {
  2156 + sb.append(" ").append(m.toGenericString()).append("\n");
  2157 + }
  2158 + XposedBridge.log(sb.toString());
  2159 +
  2160 + // Hook each static method to intercept calls from WeChat UI
  2161 + for (java.lang.reflect.Method m : methods) {
  2162 + if (!java.lang.reflect.Modifier.isStatic(m.getModifiers())) continue;
  2163 + final String mName = m.getName();
  2164 + final String mSig = m.toGenericString();
  2165 + m.setAccessible(true);
  2166 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  2167 + @Override
  2168 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2169 + StringBuilder log = new StringBuilder();
  2170 + log.append("[WeChatHook] s1.").append(mName).append("(");
  2171 + if (param.args != null) {
  2172 + for (int i = 0; i < param.args.length; i++) {
  2173 + if (i > 0) log.append(", ");
  2174 + Object a = param.args[i];
  2175 + log.append(a == null ? "null" : a.getClass().getSimpleName() + "=" + a);
  2176 + }
  2177 + }
  2178 + log.append(") -> ");
  2179 + Object ret = param.getResult();
  2180 + if (ret == null) {
  2181 + log.append("null");
  2182 + } else {
  2183 + log.append(ret.getClass().getName());
  2184 + dumpBuilderMethods(ret, "s1." + mName);
  2185 + // Capture dispatcher from the r0 inside r1 (set by factory, null in direct ctor)
  2186 + try {
  2187 + StringBuilder r1Fields = new StringBuilder("[WeChatHook] r1 fields:\n");
  2188 + for (Class<?> rc = ret.getClass(); rc != null && !rc.equals(Object.class); rc = rc.getSuperclass()) {
  2189 + for (java.lang.reflect.Field rf : rc.getDeclaredFields()) {
  2190 + if (java.lang.reflect.Modifier.isStatic(rf.getModifiers())) continue;
  2191 + rf.setAccessible(true);
  2192 + Object rv = rf.get(ret);
  2193 + String typeName = rv != null ? rv.getClass().getName() : rf.getType().getName();
  2194 + r1Fields.append(" ").append(rf.getName()).append(" (").append(typeName).append(")");
  2195 + if (sCapturedDispatcher == null && rv != null) {
  2196 + // Try to get dispatcher from any field, whether it's r0 or a container
  2197 + try {
  2198 + Object disp = XposedHelpers.getObjectField(rv, "dispatcher");
  2199 + if (disp != null) {
  2200 + sCapturedDispatcher = disp;
  2201 + r1Fields.append(" [dispatcher captured!]");
  2202 + }
  2203 + } catch (Throwable ignored2) {}
  2204 + }
  2205 + r1Fields.append("\n");
  2206 + }
  2207 + }
  2208 + XposedBridge.log(r1Fields.toString());
  2209 + } catch (Throwable r1e) {
  2210 + XposedBridge.log("[WeChatHook] r1 field dump error: " + r1e);
  2211 + }
  2212 + }
  2213 + if (param.hasThrowable())
  2214 + log.append(" THREW: ").append(param.getThrowable());
  2215 + XposedBridge.log(log.toString());
  2216 + }
  2217 + });
  2218 + }
  2219 + XposedBridge.log("[WeChatHook] hookFactoryMethods: hooked " + methods.length
  2220 + + " methods on w11.s1 in " + procName);
  2221 + } catch (Throwable t) {
  2222 + XposedBridge.log("[WeChatHook] hookFactoryMethods failed in " + procName + ": " + t);
  2223 + }
  2224 + }
  2225 +
  2226 + // Dump ALL instance methods on a builder object returned by the factory.
  2227 + // Each unique builder class is only dumped once to avoid logcat spam.
  2228 + private static final java.util.Set<String> sDumpedClasses =
  2229 + java.util.Collections.synchronizedSet(new java.util.HashSet<>());
  2230 +
  2231 + private static void dumpBuilderMethods(Object builder, String fromFactory) {
  2232 + if (builder == null) return;
  2233 + String clsName = builder.getClass().getName();
  2234 + if (!sDumpedClasses.add(clsName)) return; // already dumped
  2235 + try {
  2236 + java.lang.reflect.Method[] ms = builder.getClass().getDeclaredMethods();
  2237 + StringBuilder sb = new StringBuilder();
  2238 + sb.append("[WeChatHook] BUILDER from ").append(fromFactory)
  2239 + .append(" class=").append(clsName)
  2240 + .append(" methods(").append(ms.length).append("):\n");
  2241 + for (java.lang.reflect.Method m : ms) {
  2242 + sb.append(" ").append(m.toGenericString()).append("\n");
  2243 + }
  2244 + XposedBridge.log(sb.toString());
  2245 + } catch (Throwable t) {
  2246 + XposedBridge.log("[WeChatHook] dumpBuilderMethods " + clsName + ": " + t);
  2247 + }
  2248 + }
  2249 +
  2250 + // Dump all instance fields of w11.r0 to logcat.
  2251 + // Used to discover which field holds the SILK audio data for CDN upload.
  2252 + // Logs each field name, type, and a brief value summary.
  2253 + private static void dumpR0Fields(Object r0, String tag) {
  2254 + if (r0 == null) return;
  2255 + try {
  2256 + Class<?> cls = r0.getClass();
  2257 + StringBuilder sb = new StringBuilder();
  2258 + sb.append("[WeChatHook] ").append(tag).append(" class=").append(cls.getName()).append("\n");
  2259 + // Walk the class hierarchy to capture inherited fields
  2260 + for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  2261 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  2262 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  2263 + f.setAccessible(true);
  2264 + try {
  2265 + Object val = f.get(r0);
  2266 + if (val == null) {
  2267 + sb.append(" ").append(f.getName()).append(" (").append(f.getType().getSimpleName()).append(") = null\n");
  2268 + } else if (val instanceof byte[]) {
  2269 + byte[] ba = (byte[]) val;
  2270 + StringBuilder hex = new StringBuilder();
  2271 + int show = Math.min(ba.length, 16);
  2272 + for (int i = 0; i < show; i++) hex.append(String.format("%02x", ba[i] & 0xff));
  2273 + sb.append(" ").append(f.getName()).append(" (byte[]) len=").append(ba.length).append(" hex=").append(hex).append("\n");
  2274 + } else if (val instanceof String) {
  2275 + String s = (String) val;
  2276 + sb.append(" ").append(f.getName()).append(" (String) = \"").append(s.length() > 80 ? s.substring(0, 80) + "…" : s).append("\"\n");
  2277 + } else {
  2278 + String vs = val.toString();
  2279 + sb.append(" ").append(f.getName()).append(" (").append(val.getClass().getSimpleName()).append(") = ").append(vs.length() > 80 ? vs.substring(0, 80) + "…" : vs).append("\n");
  2280 + }
  2281 + } catch (Throwable e2) {
  2282 + sb.append(" ").append(f.getName()).append(" ERROR: ").append(e2).append("\n");
  2283 + }
  2284 + }
  2285 + }
  2286 + XposedBridge.log(sb.toString());
  2287 + } catch (Throwable t) {
  2288 + XposedBridge.log("[WeChatHook] dumpR0Fields failed: " + t);
  2289 + }
  2290 + }
  2291 +
  2292 + // ── On-demand API dump broadcast ──────────────────────────────────────────
  2293 + // am broadcast -a com.hermes.wechat.DUMP_WECHAT_API
  2294 + // Optional extra: --es class "w11.s1" (defaults to w11.s1 if omitted)
  2295 + private static void handleDumpApi(Intent intent) {
  2296 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  2297 + if (cl == null) { XposedBridge.log("[WeChatHook] DUMP_API: classloader null"); return; }
  2298 +
  2299 + String className = intent.getStringExtra("class");
  2300 + if (className == null || className.isEmpty()) className = "w11.s1";
  2301 +
  2302 + try {
  2303 + Class<?> cls = XposedHelpers.findClass(className, cl);
  2304 + java.lang.reflect.Method[] ms = cls.getDeclaredMethods();
  2305 + java.lang.reflect.Constructor[] cs = cls.getDeclaredConstructors();
  2306 + java.lang.reflect.Field[] fs = cls.getDeclaredFields();
  2307 +
  2308 + StringBuilder sb = new StringBuilder();
  2309 + sb.append("[WeChatHook] DUMP_API class=").append(cls.getName()).append("\n");
  2310 +
  2311 + // For enum classes, print each constant with its ordinal and any int fields
  2312 + if (cls.isEnum()) {
  2313 + sb.append(" ENUM CONSTANTS:\n");
  2314 + try {
  2315 + Object[] constants = (Object[]) cls.getMethod("values").invoke(null);
  2316 + java.lang.reflect.Method nameM = Enum.class.getMethod("name");
  2317 + java.lang.reflect.Method ordinalM = Enum.class.getMethod("ordinal");
  2318 + for (Object c : constants) {
  2319 + String cName = (String) nameM.invoke(c);
  2320 + int cOrd = (int) ordinalM.invoke(c);
  2321 + sb.append(" ").append(cName).append(" ordinal=").append(cOrd);
  2322 + // Also print any int/String fields on the enum instance
  2323 + for (java.lang.reflect.Field f2 : fs) {
  2324 + if (java.lang.reflect.Modifier.isStatic(f2.getModifiers())) continue;
  2325 + f2.setAccessible(true);
  2326 + try {
  2327 + Object fv = f2.get(c);
  2328 + sb.append(" ").append(f2.getName()).append("=").append(fv);
  2329 + } catch (Throwable ignored) {}
  2330 + }
  2331 + sb.append("\n");
  2332 + }
  2333 + } catch (Throwable e2) {
  2334 + sb.append(" (enum values() failed: ").append(e2).append(")\n");
  2335 + }
  2336 + }
  2337 +
  2338 + sb.append(" FIELDS (").append(fs.length).append("):\n");
  2339 + for (java.lang.reflect.Field f : fs) {
  2340 + sb.append(" ").append(f.toGenericString());
  2341 + // Read static field values (helpful for non-enum static constants)
  2342 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers()) && !cls.isEnum()) {
  2343 + f.setAccessible(true);
  2344 + try { sb.append(" = ").append(f.get(null)); } catch (Throwable ignored) {}
  2345 + }
  2346 + sb.append("\n");
  2347 + }
  2348 + sb.append(" CONSTRUCTORS (").append(cs.length).append("):\n");
  2349 + for (java.lang.reflect.Constructor<?> c : cs) sb.append(" ").append(c.toGenericString()).append("\n");
  2350 + sb.append(" METHODS (").append(ms.length).append("):\n");
  2351 + for (java.lang.reflect.Method m : ms) sb.append(" ").append(m.toGenericString()).append("\n");
  2352 + XposedBridge.log(sb.toString());
  2353 + } catch (Throwable t) {
  2354 + XposedBridge.log("[WeChatHook] DUMP_API failed for " + className + ": " + t);
  2355 + }
  2356 + }
  2357 +
  2358 + // PRIMARY FIX: WeChat's own methods (LoginPasswordUI.onCreate etc.) are AOT-compiled
  2359 + // in a way that bypasses ArtMethod entry point replacement. But framework-dispatched
  2360 + // base class methods like Activity.onResume() always go through the entry point.
  2361 + // We hook onResume, filter for the login screens, and force the tablet button visible.
  2362 + // By onResume time, all views are initialized (onCreate + initView have run).
  2363 + private void hookProbe(ClassLoader cl) {
  2364 + try {
  2365 + XposedHelpers.findAndHookMethod(
  2366 + "android.app.Activity", null,
  2367 + "onResume", new XC_MethodHook() {
  2368 + @Override
  2369 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2370 + String cls = param.thisObject.getClass().getName();
  2371 + if (!cls.equals("com.tencent.mm.plugin.account.ui.LoginPasswordUI")
  2372 + && !cls.equals("com.tencent.mm.plugin.account.ui.LoginHistoryUI")) {
  2373 + return;
  2374 + }
  2375 + Object obj = param.thisObject;
  2376 + View tabletBtn = null;
  2377 + try {
  2378 + tabletBtn = (View) XposedHelpers.getObjectField(obj, "N");
  2379 + } catch (Throwable e) {
  2380 + XposedBridge.log("[WeChatHook] onResume getField N failed: " + e);
  2381 + }
  2382 + if (tabletBtn == null) {
  2383 + XposedBridge.log("[WeChatHook] onResume: N is null for " + cls);
  2384 + return;
  2385 + }
  2386 + tabletBtn.setVisibility(View.VISIBLE);
  2387 + // CRITICAL: resolve m4 from the Activity's OWN classloader. The login
  2388 + // Activities run under the Tinker CL, but hookProbe was installed with
  2389 + // the pre-Tinker CL. m4's ctor param LoginHistoryUI and the running
  2390 + // Activity are the SAME FQN but from DIFFERENT classloaders, so a
  2391 + // captured-CL m4 fails with "type LoginHistoryUI, got LoginHistoryUI".
  2392 + // Looking up m4 via obj's CL makes the types line up.
  2393 + boolean attached = false;
  2394 + try {
  2395 + ClassLoader runtimeCl = obj.getClass().getClassLoader();
  2396 + Class<?> m4Class = XposedHelpers.findClass(
  2397 + "com.tencent.mm.plugin.account.ui.m4", runtimeCl);
  2398 + java.lang.reflect.Constructor<?> chosen = null;
  2399 + for (java.lang.reflect.Constructor<?> c : m4Class.getDeclaredConstructors()) {
  2400 + Class<?>[] pt = c.getParameterTypes();
  2401 + if (pt.length == 1 && pt[0].isAssignableFrom(obj.getClass())) {
  2402 + chosen = c; break;
  2403 + }
  2404 + }
  2405 + if (chosen != null && View.OnClickListener.class.isAssignableFrom(m4Class)) {
  2406 + chosen.setAccessible(true);
  2407 + tabletBtn.setOnClickListener(
  2408 + (View.OnClickListener) chosen.newInstance(obj));
  2409 + attached = true;
  2410 + XposedBridge.log("[WeChatHook] onResume: m4 listener attached via "
  2411 + + chosen.getParameterTypes()[0].getName() + " for " + cls);
  2412 + } else {
  2413 + XposedBridge.log("[WeChatHook] onResume: no assignable m4 ctor for "
  2414 + + cls + " (obj CL=" + runtimeCl + ")");
  2415 + }
  2416 + } catch (Throwable e) {
  2417 + XposedBridge.log("[WeChatHook] onResume setListener failed: " + e);
  2418 + }
  2419 + if (!attached) {
  2420 + XposedBridge.log("[WeChatHook] onResume: N VISIBLE but NO listener for " + cls);
  2421 + }
  2422 + }
  2423 + });
  2424 + XposedBridge.log("[WeChatHook] Hooked Activity.onResume for tablet button");
  2425 + } catch (Throwable t) {
  2426 + XposedBridge.log("[WeChatHook] hookProbe/onResume failed: " + t);
  2427 + }
  2428 + }
  2429 +
  2430 + private void hookInTabletEnv(ClassLoader cl) {
  2431 + try {
  2432 + Class<?> bkClass = XposedHelpers.findClass("com.tencent.mm.ui.bk", cl);
  2433 + Class<?> x0Class = XposedHelpers.findClass("bm5.x0", cl);
  2434 + XposedHelpers.findAndHookMethod(bkClass, "B", x0Class, new XC_MethodHook() {
  2435 + @Override
  2436 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2437 + param.setResult(Boolean.TRUE);
  2438 + }
  2439 + });
  2440 + XposedHelpers.findAndHookMethod(bkClass, "A", new XC_MethodHook() {
  2441 + @Override
  2442 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2443 + XposedBridge.log("[WeChatHook] bk.A() called -> TRUE");
  2444 + param.setResult(Boolean.TRUE);
  2445 + }
  2446 + });
  2447 + XposedBridge.log("[WeChatHook] Hooked bk.B(x0) + bk.A()");
  2448 + } catch (Throwable t) {
  2449 + XposedBridge.log("[WeChatHook] hookInTabletEnv failed: " + t);
  2450 + }
  2451 + }
  2452 +
  2453 + // PRIMARY FIX: Hook LoginPasswordUI.onCreate(Bundle) afterHookedMethod.
  2454 + //
  2455 + // Previous attempts to hook initView() and LoginHistoryUI.initView() both failed
  2456 + // because ART AOT devirtualizes the call to this.initView() inside
  2457 + // LoginHistoryUI.onCreate() — the compiled native code jumps directly past the
  2458 + // Xposed entry point replacement.
  2459 + //
  2460 + // onCreate() itself is called by the Android framework via the ArtMethod pointer
  2461 + // directly (no vtable devirtualization possible), so this hook fires reliably.
  2462 + // By the time afterHookedMethod runs, super.onCreate() has completed which means
  2463 + // LoginHistoryUI.initView() has already run and this.N is assigned.
  2464 + private void hookLoginHistoryUIInitView(ClassLoader cl) {
  2465 + final Class<?> m4Class;
  2466 + try {
  2467 + m4Class = XposedHelpers.findClass("com.tencent.mm.plugin.account.ui.m4", cl);
  2468 + } catch (Throwable t) {
  2469 + XposedBridge.log("[WeChatHook] m4 class not found: " + t);
  2470 + return;
  2471 + }
  2472 +
  2473 + try {
  2474 + XposedHelpers.findAndHookMethod(
  2475 + "com.tencent.mm.plugin.account.ui.LoginPasswordUI", cl,
  2476 + "onCreate", Bundle.class, new XC_MethodHook() {
  2477 + @Override
  2478 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2479 + Object obj = param.thisObject;
  2480 + View tabletBtn = (View) XposedHelpers.getObjectField(obj, "N");
  2481 + if (tabletBtn == null) {
  2482 + XposedBridge.log("[WeChatHook] LoginPasswordUI.onCreate: N is null");
  2483 + return;
  2484 + }
  2485 + tabletBtn.setVisibility(View.VISIBLE);
  2486 + tabletBtn.setOnClickListener(
  2487 + (View.OnClickListener) XposedHelpers.newInstance(m4Class, obj));
  2488 + XposedBridge.log("[WeChatHook] LoginPasswordUI.onCreate() -> N VISIBLE + m4 attached");
  2489 + }
  2490 + });
  2491 + XposedBridge.log("[WeChatHook] Hooked LoginPasswordUI.onCreate()");
  2492 + } catch (Throwable t) {
  2493 + XposedBridge.log("[WeChatHook] hookLoginPasswordUI.onCreate failed: " + t);
  2494 + }
  2495 +
  2496 + // Belt-and-suspenders: also hook LoginHistoryUI.onCreate() for any subclass
  2497 + // that doesn't override onCreate but does have the N button.
  2498 + try {
  2499 + XposedHelpers.findAndHookMethod(
  2500 + "com.tencent.mm.plugin.account.ui.LoginHistoryUI", cl,
  2501 + "onCreate", Bundle.class, new XC_MethodHook() {
  2502 + @Override
  2503 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2504 + Object obj = param.thisObject;
  2505 + if (obj.getClass().getName().equals(
  2506 + "com.tencent.mm.plugin.account.ui.LoginPasswordUI")) return;
  2507 + View tabletBtn = (View) XposedHelpers.getObjectField(obj, "N");
  2508 + if (tabletBtn == null) {
  2509 + XposedBridge.log("[WeChatHook] LoginHistoryUI.onCreate: N is null");
  2510 + return;
  2511 + }
  2512 + tabletBtn.setVisibility(View.VISIBLE);
  2513 + tabletBtn.setOnClickListener(
  2514 + (View.OnClickListener) XposedHelpers.newInstance(m4Class, obj));
  2515 + XposedBridge.log("[WeChatHook] LoginHistoryUI.onCreate() -> N VISIBLE + m4 attached");
  2516 + }
  2517 + });
  2518 + XposedBridge.log("[WeChatHook] Hooked LoginHistoryUI.onCreate()");
  2519 + } catch (Throwable t) {
  2520 + XposedBridge.log("[WeChatHook] hookLoginHistoryUI.onCreate failed: " + t);
  2521 + }
  2522 + }
  2523 +
  2524 + private void hookLoginUIInitView(ClassLoader cl) {
  2525 + try {
  2526 + final Class<?> wbClass = XposedHelpers.findClass(
  2527 + "com.tencent.mm.plugin.account.ui.wb", cl);
  2528 + XposedHelpers.findAndHookMethod(
  2529 + "com.tencent.mm.plugin.account.ui.MobileInputUI", cl,
  2530 + "initView", new XC_MethodHook() {
  2531 + @Override
  2532 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2533 + Object mobileInputUI = param.thisObject;
  2534 + View tabletBtn = (View) XposedHelpers.getObjectField(mobileInputUI, "w");
  2535 + if (tabletBtn == null) {
  2536 + XposedBridge.log("[WeChatHook] MobileInputUI.w is null");
  2537 + return;
  2538 + }
  2539 + tabletBtn.setVisibility(View.VISIBLE);
  2540 + tabletBtn.setOnClickListener(
  2541 + (View.OnClickListener) XposedHelpers.newInstance(wbClass, mobileInputUI));
  2542 + XposedBridge.log("[WeChatHook] MobileInputUI.initView() -> w VISIBLE + wb attached");
  2543 + }
  2544 + });
  2545 + XposedBridge.log("[WeChatHook] Hooked MobileInputUI.initView()");
  2546 + } catch (Throwable t) {
  2547 + XposedBridge.log("[WeChatHook] hookLoginUIInitView(MobileInputUI) failed: " + t);
  2548 + }
  2549 + try {
  2550 + final Class<?> g7Class = XposedHelpers.findClass(
  2551 + "com.tencent.mm.plugin.account.ui.g7", cl);
  2552 + XposedHelpers.findAndHookMethod(
  2553 + "com.tencent.mm.plugin.account.ui.LoginUI", cl,
  2554 + "initView", new XC_MethodHook() {
  2555 + @Override
  2556 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2557 + Object loginUI = param.thisObject;
  2558 + View tabletBtn = (View) XposedHelpers.getObjectField(loginUI, "f992u");
  2559 + if (tabletBtn == null) return;
  2560 + tabletBtn.setVisibility(View.VISIBLE);
  2561 + tabletBtn.setOnClickListener(
  2562 + (View.OnClickListener) XposedHelpers.newInstance(g7Class, loginUI));
  2563 + XposedBridge.log("[WeChatHook] LoginUI.initView() -> f992u VISIBLE + g7 attached");
  2564 + }
  2565 + });
  2566 + XposedBridge.log("[WeChatHook] Hooked LoginUI.initView()");
  2567 + } catch (Throwable t) {
  2568 + XposedBridge.log("[WeChatHook] hookLoginUIInitView(LoginUI) failed: " + t);
  2569 + }
  2570 + }
  2571 +
  2572 + private void hookLoginSelectUICheck(ClassLoader cl) {
  2573 + try {
  2574 + Class<?> callbackClass = XposedHelpers.findClass(
  2575 + "com.tencent.mm.plugin.account.ui.LoginSelectUI$a", cl);
  2576 + XposedHelpers.findAndHookMethod(callbackClass, "a", boolean.class, new XC_MethodHook() {
  2577 + @Override
  2578 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2579 + XposedBridge.log("[WeChatHook] LoginSelectUI$a.a(" + param.args[0] + ") -> false");
  2580 + param.args[0] = false;
  2581 + }
  2582 + });
  2583 + XposedBridge.log("[WeChatHook] Hooked LoginSelectUI$a.a()");
  2584 + } catch (Throwable t) {
  2585 + XposedBridge.log("[WeChatHook] hookLoginSelectUICheck failed: " + t);
  2586 + }
  2587 + }
  2588 +
  2589 + private void hookLoginButtonClick(ClassLoader cl) {
  2590 + try {
  2591 + Class<?> ljClass = XposedHelpers.findClass(
  2592 + "com.tencent.mm.plugin.account.ui.lj", cl);
  2593 + final Class<?> loginSelectUIClass = XposedHelpers.findClass(
  2594 + "com.tencent.mm.plugin.account.ui.LoginSelectUI", cl);
  2595 + XposedHelpers.findAndHookMethod(ljClass, "onClick", View.class, new XC_MethodHook() {
  2596 + @Override
  2597 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2598 + XposedBridge.log("[WeChatHook] lj.onClick() -> forcing LoginSelectUI");
  2599 + Activity welcomeActivity = (Activity) XposedHelpers.getObjectField(
  2600 + param.thisObject, "d");
  2601 + Intent intent = new Intent(welcomeActivity, loginSelectUIClass);
  2602 + intent.putExtra("mobile_input_purpose", 1);
  2603 + welcomeActivity.startActivity(intent);
  2604 + param.setResult(null);
  2605 + }
  2606 + });
  2607 + XposedBridge.log("[WeChatHook] Hooked lj.onClick() -> LoginSelectUI");
  2608 + } catch (Throwable t) {
  2609 + XposedBridge.log("[WeChatHook] hookLoginButtonClick failed: " + t);
  2610 + }
  2611 + }
  2612 +
  2613 + // ── Send message via internal API ────────────────────────────────────────
  2614 + //
  2615 + // Registered in ALL WeChat processes. We don't yet know which process has gm0.j1
  2616 + // initialized — the first process where the receiver fires and succeeds wins.
  2617 + //
  2618 + // Trigger from ADB (must run as root — RECEIVER_NOT_EXPORTED):
  2619 + // adb shell su -c 'am broadcast -a com.hermes.wechat.SEND_MSG_INTERNAL \
  2620 + // --es to "filehelper" --es text "hello"'
  2621 + private void hookSendMessage(ClassLoader cl, String procName) {
  2622 + try {
  2623 + XposedHelpers.findAndHookMethod(
  2624 + "android.app.Application", null, "onCreate",
  2625 + new XC_MethodHook() {
  2626 + @Override
  2627 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2628 + Context ctx = (Context) param.thisObject;
  2629 + if (!"com.tencent.mm".equals(ctx.getPackageName())) return;
  2630 + sAppContext = ctx;
  2631 + // Capture Tinker-patched classloader (Tinker installs in attachBaseContext,
  2632 + // so by App.onCreate this loader has the patch DEX classes).
  2633 + sTinkerCL = ctx.getClassLoader();
  2634 + XposedBridge.log("[WeChatHook] App.onCreate proc=" + procName
  2635 + + " pid=" + android.os.Process.myPid()
  2636 + + " tinkerCL=" + (sTinkerCL != null ? sTinkerCL.getClass().getSimpleName() : "null"));
  2637 + // Re-hook with Tinker CL — w11.s1 and f9 may live in a Tinker DEX.
  2638 + // This ensures our factory and convertTo hooks fire on actual WeChat UI sends.
  2639 + if (sTinkerCL != sWeChatCL) {
  2640 + hookFactoryMethods(sTinkerCL, procName + "/tinker");
  2641 + hookF9ConvertTo(sTinkerCL, procName + "/tinker");
  2642 + hookF9ImgPathInjector(sTinkerCL, procName + "/tinker");
  2643 + hookR0H(sTinkerCL, procName + "/tinker");
  2644 + // Hook pt0.e0 in Tinker CL — real voice sends run in Tinker CL.
  2645 + hookPt0E0(sTinkerCL, procName + "/tinker");
  2646 + // NOTE: hookJg0 / hookVoiceEntry disabled — they hook WeChat's
  2647 + // generic coroutine classes (pu.o0/pu.m0) and every message
  2648 + // DB insert (g9.M9/N9), which adds anti-tamper risk and
  2649 + // destabilizes the fragile Pad login. Re-enable only for a
  2650 + // targeted investigation session, never during normal use.
  2651 + // hookJg0(sTinkerCL, procName + "/tinker");
  2652 + // hookVoiceEntry(sTinkerCL, procName + "/tinker");
  2653 + // Surgical probe: jg0.x + qi3.f0/g0 only (safe).
  2654 + hookVoiceProbe(sTinkerCL, procName + "/tinker");
  2655 + // Image send runs in Tinker CL — hook b80.u.pj/Bi there.
  2656 + hookImageSend(sTinkerCL, procName + "/tinker");
  2657 + // CDN upload trace runs in Tinker CL (real voice send path).
  2658 + hookCdnTrace(sTinkerCL, procName + "/tinker");
  2659 + // Capture the real uploadvoice cgi request in Tinker CL.
  2660 + hookVoiceCgiCapture(sTinkerCL, procName + "/tinker");
  2661 + }
  2662 + hookF9ConvertTo(sWeChatCL, procName);
  2663 + hookF9ImgPathInjector(sWeChatCL, procName);
  2664 + registerSendReceiver(ctx, procName);
  2665 + }
  2666 + });
  2667 + XposedBridge.log("[WeChatHook] Send hook registered in " + procName);
  2668 + } catch (Throwable t) {
  2669 + XposedBridge.log("[WeChatHook] hookSendMessage failed in " + procName + ": " + t);
  2670 + }
  2671 +
  2672 + // ── w11.r0 constructor hooks ───────────────────────────────────────────
  2673 + // Log "by=US" vs "by=WeChat" to tell if WeChat's own UI send uses this ctor.
  2674 + XC_MethodHook r0Hook = new XC_MethodHook() {
  2675 + @Override
  2676 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2677 + String by = sCalledByUs ? "US" : "WeChat";
  2678 + XposedBridge.log("[WeChatHook] w11.r0 ctor by=" + by
  2679 + + " args=" + param.args.length + " proc=" + procName
  2680 + + " pid=" + android.os.Process.myPid());
  2681 + if (sCalledByUs) {
  2682 + forceInitDI();
  2683 + diagMCoreStorage("before-r0-ctor");
  2684 + }
  2685 + }
  2686 + @Override
  2687 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2688 + String by = sCalledByUs ? "US" : "WeChat";
  2689 + if (param.hasThrowable()) {
  2690 + Throwable t = param.getThrowable();
  2691 + XposedBridge.log("[WeChatHook] w11.r0 ctor THREW by=" + by
  2692 + + " proc=" + procName + ": " + t);
  2693 + if (sCalledByUs)
  2694 + XposedBridge.log("[WeChatHook] r0-ctor-stack: "
  2695 + + android.util.Log.getStackTraceString(t));
  2696 + return;
  2697 + }
  2698 + sFsGReady = true;
  2699 + XposedBridge.log("[WeChatHook] w11.r0 ctor OK by=" + by + " proc=" + procName);
  2700 + }
  2701 + };
  2702 + for (Class<?>[] sig : new Class<?>[][]{
  2703 + {String.class, String.class, int.class, int.class, long.class},
  2704 + {String.class, String.class, int.class, int.class, Object.class},
  2705 + {long.class, int.class, String.class},
  2706 + {}}) {
  2707 + try {
  2708 + XposedHelpers.findAndHookConstructor("w11.r0", cl,
  2709 + appendHook(sig, r0Hook));
  2710 + XposedBridge.log("[WeChatHook] Hooked w11.r0(" + sig.length + " params)");
  2711 + } catch (Throwable t) {
  2712 + XposedBridge.log("[WeChatHook] w11.r0(" + sig.length + "p) hook failed: " + t);
  2713 + }
  2714 + }
  2715 +
  2716 + // ── w11.r0.H(String) — the actual dispatch method ─────────────────────
  2717 + // Fires for EVERY send (ours AND WeChat UI sends). Shows if WeChat uses r0.
  2718 + // For real WeChat voice sends (type=34, by=WeChat), dumps ALL r0 fields so
  2719 + // we can find which field holds the SILK audio data (root cause of spinner).
  2720 + try {
  2721 + XposedHelpers.findAndHookMethod("w11.r0", cl, "H", String.class,
  2722 + new XC_MethodHook() {
  2723 + @Override
  2724 + protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
  2725 + String by = sCalledByUs ? "US" : "WeChat";
  2726 + XposedBridge.log("[WeChatHook] w11.r0.H() called by=" + by
  2727 + + " proc=" + procName + " pid=" + android.os.Process.myPid());
  2728 + // Dump all r0 fields for real WeChat voice sends only.
  2729 + // This reveals which field holds the SILK audio data that H() uses for CDN upload.
  2730 + if (!sCalledByUs) {
  2731 + dumpR0Fields(param.thisObject, "r0.H-before");
  2732 + }
  2733 + }
  2734 + @Override
  2735 + protected void afterHookedMethod(MethodHookParam param) throws Throwable {
  2736 + if (param.hasThrowable())
  2737 + XposedBridge.log("[WeChatHook] w11.r0.H() threw: " + param.getThrowable());
  2738 + else
  2739 + XposedBridge.log("[WeChatHook] w11.r0.H() OK proc=" + procName);
  2740 + }
  2741 + });
  2742 + XposedBridge.log("[WeChatHook] Hooked w11.r0.H(String) in " + procName);
  2743 + } catch (Throwable t) {
  2744 + XposedBridge.log("[WeChatHook] w11.r0.H hook failed in " + procName + ": " + t);
  2745 + }
  2746 +
  2747 + // ── r0.I(int) and r0.K(int) — delivery completion hooks ──────────────────
  2748 + // Log when WeChat calls these so we understand their role in the send flow.
  2749 + // Our u0 stub now calls r0.I(0) after onSceneEnd — this confirms whether I()
  2750 + // is the right trigger for delivery completion and spinner removal.
  2751 + try {
  2752 + XposedHelpers.findAndHookMethod("w11.r0", cl, "I", int.class,
  2753 + new XC_MethodHook() {
  2754 + @Override protected void beforeHookedMethod(MethodHookParam p) throws Throwable {
  2755 + String by = sCalledByUs ? "US" : "WeChat";
  2756 + XposedBridge.log("[WeChatHook] r0.I(" + p.args[0] + ") by=" + by + " proc=" + procName);
  2757 + }
  2758 + });
  2759 + XposedBridge.log("[WeChatHook] Hooked w11.r0.I(int) in " + procName);
  2760 + } catch (Throwable t) {
  2761 + XposedBridge.log("[WeChatHook] r0.I hook failed in " + procName + ": " + t);
  2762 + }
  2763 + try {
  2764 + XposedHelpers.findAndHookMethod("w11.r0", cl, "K", int.class,
  2765 + new XC_MethodHook() {
  2766 + @Override protected void beforeHookedMethod(MethodHookParam p) throws Throwable {
  2767 + String by = sCalledByUs ? "US" : "WeChat";
  2768 + XposedBridge.log("[WeChatHook] r0.K(" + p.args[0] + ") by=" + by + " proc=" + procName);
  2769 + }
  2770 + });
  2771 + XposedBridge.log("[WeChatHook] Hooked w11.r0.K(int) in " + procName);
  2772 + } catch (Throwable t) {
  2773 + XposedBridge.log("[WeChatHook] r0.K hook failed in " + procName + ": " + t);
  2774 + }
  2775 +
  2776 + // ── Diagnostic probes on the constructor call chain ───────────────────
  2777 + // Each probe fires when the method is called from inside the r0 constructor
  2778 + // (by WeChat OR by us). They trace which methods succeed before the NPE.
  2779 + hookProbeMethod(cl, "gm0.j1", "u", "gm0.j1.u");
  2780 + hookProbeMethod(cl, "c01.z1", "r", "c01.z1.r");
  2781 + // gm0.b0.c() is a virtual method — probe it too
  2782 + try {
  2783 + XposedHelpers.findAndHookMethod("gm0.b0", cl, "c",
  2784 + new XC_MethodHook() {
  2785 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  2786 + XposedBridge.log("[WeChatHook] PROBE gm0.b0.c() called");
  2787 + }
  2788 + @Override protected void afterHookedMethod(MethodHookParam p) {
  2789 + if (p.hasThrowable()) XposedBridge.log("[WeChatHook] PROBE gm0.b0.c() THREW: " + p.getThrowable());
  2790 + else XposedBridge.log("[WeChatHook] PROBE gm0.b0.c() → " + p.getResult());
  2791 + }
  2792 + });
  2793 + } catch (Throwable t) {
  2794 + XposedBridge.log("[WeChatHook] gm0.b0.c probe failed: " + t);
  2795 + }
  2796 + }
  2797 +
  2798 + private static Object[] appendHook(Class<?>[] params, XC_MethodHook hook) {
  2799 + Object[] result = new Object[params.length + 1];
  2800 + System.arraycopy(params, 0, result, 0, params.length);
  2801 + result[params.length] = hook;
  2802 + return result;
  2803 + }
  2804 +
  2805 + private void hookProbeMethod(ClassLoader cl, String cls, String method, String tag) {
  2806 + try {
  2807 + XposedHelpers.findAndHookMethod(cls, cl, method,
  2808 + new XC_MethodHook() {
  2809 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  2810 + XposedBridge.log("[WeChatHook] PROBE " + tag + "() called");
  2811 + }
  2812 + @Override protected void afterHookedMethod(MethodHookParam p) {
  2813 + if (p.hasThrowable()) XposedBridge.log("[WeChatHook] PROBE " + tag + "() THREW: " + p.getThrowable());
  2814 + else XposedBridge.log("[WeChatHook] PROBE " + tag + "() → " + p.getResult());
  2815 + }
  2816 + });
  2817 + XposedBridge.log("[WeChatHook] Probe hooked: " + tag);
  2818 + } catch (Throwable t) {
  2819 + XposedBridge.log("[WeChatHook] Probe " + tag + " failed: " + t);
  2820 + }
  2821 + }
  2822 +
  2823 + private static boolean isDIReady() {
  2824 + if (sWeChatCL == null) return false;
  2825 + try {
  2826 + XposedHelpers.callStaticMethod(XposedHelpers.findClass("gm0.j1", sWeChatCL), "i");
  2827 + return true;
  2828 + } catch (Throwable e) { return false; }
  2829 + }
  2830 +
  2831 + // Hook gm0.j1.g(km0.c) to detect when WeChat DI kernel is initialized.
  2832 + // gm0.j1.g() sets gm0.j1.m (the singleton) and is called lazily — not during
  2833 + // Application.onCreate, so our broadcast often arrives first. After g() fires,
  2834 + // gm0.j1.i() will succeed and w11.r0 can be constructed.
  2835 + private static void hookDIInit(ClassLoader cl, String procName) {
  2836 + try {
  2837 + Class<?> km0cCls = XposedHelpers.findClass("km0.c", cl);
  2838 + XposedHelpers.findAndHookMethod("gm0.j1", cl, "g", km0cCls,
  2839 + new XC_MethodHook() {
  2840 + @Override
  2841 + protected void afterHookedMethod(MethodHookParam p) throws Throwable {
  2842 + XposedBridge.log("[WeChatHook] gm0.j1.g() fired — DI ready in " + procName);
  2843 + String t = sPendingTalker, x = sPendingText, pr = sPendingProc;
  2844 + if (t != null && x != null && procName.equals(pr)) {
  2845 + sPendingTalker = null; sPendingText = null; sPendingProc = null;
  2846 + XposedBridge.log("[WeChatHook] resuming pending send to=" + t + " proc=" + procName);
  2847 + new Handler(Looper.getMainLooper()).postDelayed(
  2848 + () -> trySendWithRetry(t, x, 0, procName), 50);
  2849 + }
  2850 + }
  2851 + });
  2852 + XposedBridge.log("[WeChatHook] gm0.j1.g hook OK in " + procName);
  2853 + } catch (Throwable t) {
  2854 + XposedBridge.log("[WeChatHook] gm0.j1.g hook failed in " + procName + ": " + t);
  2855 + }
  2856 + }
  2857 +
  2858 + private static void diagMCoreStorage(String where) {
  2859 + if (sWeChatCL == null) return;
  2860 + try {
  2861 + Class<?> j1Cls = XposedHelpers.findClass("gm0.j1", sWeChatCL);
  2862 + Object j1 = XposedHelpers.callStaticMethod(j1Cls, "i");
  2863 + Object mCS = (j1 != null) ? XposedHelpers.getObjectField(j1, "d") : null;
  2864 + XposedBridge.log("[WeChatHook] " + where + " mCoreStorage=" + mCS);
  2865 + } catch (Throwable e) {
  2866 + XposedBridge.log("[WeChatHook] " + where + " mCoreStorage-check: " + e);
  2867 + }
  2868 + }
  2869 +
  2870 + private static void forceInitDI() {
  2871 + if (sWeChatCL == null) return;
  2872 + try {
  2873 + Class<?> fsgCls = XposedHelpers.findClass("fs.g", sWeChatCL);
  2874 + java.lang.reflect.Field faFld = fsgCls.getDeclaredField("a");
  2875 + faFld.setAccessible(true);
  2876 + Object[] arr = (Object[]) faFld.get(null);
  2877 +
  2878 + if (arr == null || arr.length == 0 || arr[0] == null) {
  2879 + Class<?> k2Cls = XposedHelpers.findClass("fs.k2", sWeChatCL);
  2880 + java.lang.reflect.Field k2eFld = k2Cls.getDeclaredField("e");
  2881 + k2eFld.setAccessible(true);
  2882 + Object k2e = k2eFld.get(null);
  2883 + if (k2e == null) {
  2884 + XposedBridge.log("[WeChatHook] forceInitDI: fs.k2.e null");
  2885 + return;
  2886 + }
  2887 + if (arr == null || arr.length == 0) {
  2888 + arr = new Object[1];
  2889 + faFld.set(null, arr);
  2890 + }
  2891 + arr[0] = k2e;
  2892 + XposedBridge.log("[WeChatHook] forceInitDI: fs.g.a[0]=" + k2e.getClass().getName());
  2893 + }
  2894 + } catch (Throwable e) {
  2895 + XposedBridge.log("[WeChatHook] forceInitDI: " + e);
  2896 + }
  2897 + }
  2898 +
  2899 + private static void trySendWithRetry(String talker, String text, int attempt, String procName) {
  2900 + // Non-main WeChat processes (:push, :tools, etc.) lack storage init — fail immediately.
  2901 + if (procName != null && procName.contains(":")) {
  2902 + if (attempt == 0) XposedBridge.log("[WeChatHook] Skip send in non-main proc=" + procName);
  2903 + return;
  2904 + }
  2905 + // Route A2: tg3.t1 high-level service locator
  2906 + try {
  2907 + sendViaHighLevel(talker, text);
  2908 + XposedBridge.log("[WeChatHook] HighLevel send OK to=" + talker + " proc=" + procName);
  2909 + return;
  2910 + } catch (Throwable t) {
  2911 + if (attempt == 0)
  2912 + XposedBridge.log("[WeChatHook] HighLevel FAILED proc=" + procName + ": " + t);
  2913 + }
  2914 +
  2915 + // Route A1b: w11.s1 factory (mid-level)
  2916 + try {
  2917 + sendViaFactory(talker, text);
  2918 + XposedBridge.log("[WeChatHook] Factory send OK to=" + talker + " proc=" + procName);
  2919 + return;
  2920 + } catch (Throwable t) {
  2921 + // Log every 5 attempts to track what's changing
  2922 + if (attempt % 5 == 0)
  2923 + XposedBridge.log("[WeChatHook] Factory FAILED attempt=" + attempt
  2924 + + " proc=" + procName + ": " + t);
  2925 + }
  2926 +
  2927 + // Route A1: w11.r0 direct (requires gm0.j1 DI ready)
  2928 + if (isDIReady()) {
  2929 + try {
  2930 + sendViaR0(talker, text);
  2931 + XposedBridge.log("[WeChatHook] R0 send OK to=" + talker + " proc=" + procName);
  2932 + return;
  2933 + } catch (Throwable t) {
  2934 + if (attempt == 0)
  2935 + XposedBridge.log("[WeChatHook] R0 FAILED proc=" + procName + ": " + t);
  2936 + }
  2937 + }
  2938 +
  2939 + // All paths failed — poll every 1s up to 60 attempts waiting for WeChat DI init
  2940 + if (attempt < 60) {
  2941 + if (attempt == 0)
  2942 + XposedBridge.log("[WeChatHook] All paths not ready, polling proc=" + procName
  2943 + + " to=" + talker);
  2944 + new Handler(Looper.getMainLooper()).postDelayed(
  2945 + () -> trySendWithRetry(talker, text, attempt + 1, procName), 1000);
  2946 + } else {
  2947 + XposedBridge.log("[WeChatHook] GIVE UP after 60s proc=" + procName + " to=" + talker);
  2948 + }
  2949 + }
  2950 +
  2951 + // Route A1b: w11.s1 factory — SendMsgCgiFactory.a(talker) → w11.r1.e(content).b()
  2952 + private static void sendViaFactory(String talker, String text) throws Throwable {
  2953 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  2954 + if (cl == null) throw new IllegalStateException("classloader null");
  2955 + Class<?> s1 = XposedHelpers.findClass("w11.s1", cl);
  2956 + Object r1 = XposedHelpers.callStaticMethod(s1, "a", talker);
  2957 + if (r1 == null) throw new IllegalStateException("w11.s1.a() returned null");
  2958 + try {
  2959 + XposedHelpers.callMethod(r1, "e", text);
  2960 + } catch (Throwable t) {
  2961 + throw new RuntimeException("r1.e() failed: " + t, t);
  2962 + }
  2963 + try {
  2964 + XposedHelpers.callMethod(r1, "b");
  2965 + } catch (Throwable t) {
  2966 + throw new RuntimeException("r1.b() failed: " + t, t);
  2967 + }
  2968 + }
  2969 +
  2970 + // Route A2: high-level API via tg3.t1 service locator → dk5.s5.Ni().
  2971 + // This path is what WeChat UI uses — internally handles DI, account context, etc.
  2972 + private static void sendViaHighLevel(String talker, String text) throws Throwable {
  2973 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  2974 + if (cl == null) throw new IllegalStateException("classloader null");
  2975 + // Text = same PROVEN path as voice sendVoiceViaAPI: w11.r0 ctor (type=1) inserts
  2976 + // the f9 into the DB, then z2.b(NetSceneQueue) dispatches over the real network.
  2977 + // Text carries no CDN attachment, so unlike voice it completes fully. (The s1.a /
  2978 + // s1.b / dk5.s5.Ni builder paths either produced name-cards or silently failed to
  2979 + // persist — they need hidden r1 fields + MsgRetransmitUI.P6 that we can't set robustly.)
  2980 + Class<?> r0Class = XposedHelpers.findClass("w11.r0", cl);
  2981 + Object r0;
  2982 + sCalledByUs = true;
  2983 + try {
  2984 + // Object-ctor is the one that actually inserts the f9 (confirmed by
  2985 + // sendVoiceViaAPI). obj=null for text (no audio/msgsource extras).
  2986 + r0 = XposedHelpers.newInstance(r0Class,
  2987 + new Class<?>[]{String.class, String.class, int.class, int.class, Object.class},
  2988 + talker, text, 1, 0, null); // (talker, content, type=1 TEXT, flag=0, null)
  2989 + } finally { sCalledByUs = false; }
  2990 + Class<?> z2c = XposedHelpers.findClass("com.tencent.mm.modelbase.z2", cl);
  2991 + XposedHelpers.callStaticMethod(z2c, "b", r0); // enqueue → doScene → newsendmsg
  2992 + XposedBridge.log("[WeChatHook] sendViaHighLevel(TEXT via r0-obj+z2.b): OK to=" + talker);
  2993 + }
  2994 +
  2995 + private static void registerSendReceiver(Context ctx, String procName) {
  2996 + // SEND_MSG_INTERNAL: send a text message
  2997 + BroadcastReceiver sendRecv = new BroadcastReceiver() {
  2998 + @Override
  2999 + public void onReceive(Context context, Intent intent) {
  3000 + String talker = intent.getStringExtra("to");
  3001 + String rawText = intent.getStringExtra("text");
  3002 + // Non-ASCII (Chinese) via `am broadcast --es text` gets mangled by the
  3003 + // shell/am → server rejects → stuck "sending". Prefer base64: send with
  3004 + // --es text_b64 <base64(utf-8)> and we decode it here intact.
  3005 + String textB64 = intent.getStringExtra("text_b64");
  3006 + if (textB64 != null && !textB64.isEmpty()) {
  3007 + try {
  3008 + rawText = new String(android.util.Base64.decode(textB64, android.util.Base64.DEFAULT), "UTF-8");
  3009 + } catch (Throwable t) {
  3010 + XposedBridge.log("[WeChatHook] SEND_MSG_INTERNAL: bad text_b64: " + t);
  3011 + }
  3012 + }
  3013 + final String text = rawText;
  3014 + if (talker == null || talker.isEmpty() || text == null || text.isEmpty()) {
  3015 + XposedBridge.log("[WeChatHook] SEND_MSG_INTERNAL: missing 'to' or 'text'/'text_b64'");
  3016 + return;
  3017 + }
  3018 + XposedBridge.log("[WeChatHook] SEND_MSG_INTERNAL proc=" + procName
  3019 + + " pid=" + android.os.Process.myPid()
  3020 + + " to=" + talker + " len=" + text.length());
  3021 + new Handler(Looper.getMainLooper()).post(() -> trySendWithRetry(talker, text, 0, procName));
  3022 + }
  3023 + };
  3024 + ctx.registerReceiver(sendRecv, new IntentFilter(ACTION_SEND), Context.RECEIVER_NOT_EXPORTED);
  3025 +
  3026 + // SEND_IMAGE_INTERNAL: send an image via w11.s1.b internal API
  3027 + // Usage: adb shell su -c 'am broadcast -a com.hermes.wechat.SEND_IMAGE_INTERNAL \
  3028 + // --es to "filehelper" --es path "/sdcard/test.jpg"'
  3029 + BroadcastReceiver imgRecv = new BroadcastReceiver() {
  3030 + @Override
  3031 + public void onReceive(Context context, Intent intent) {
  3032 + // Only handle in main WeChat process (sub-processes lack storage init)
  3033 + if (procName.contains(":")) return;
  3034 + String talker = intent.getStringExtra("to");
  3035 + String path = intent.getStringExtra("path");
  3036 + if (talker == null || talker.isEmpty() || path == null || path.isEmpty()) {
  3037 + XposedBridge.log("[WeChatHook] SEND_IMAGE_INTERNAL: missing 'to' or 'path'");
  3038 + return;
  3039 + }
  3040 + XposedBridge.log("[WeChatHook] SEND_IMAGE_INTERNAL proc=" + procName
  3041 + + " to=" + talker + " path=" + path);
  3042 + new Handler(Looper.getMainLooper()).post(() -> {
  3043 + try {
  3044 + sendImageViaAPI(talker, path);
  3045 + } catch (Throwable t) {
  3046 + XposedBridge.log("[WeChatHook] SEND_IMAGE_INTERNAL failed: " + t
  3047 + + "\n" + android.util.Log.getStackTraceString(t));
  3048 + }
  3049 + });
  3050 + }
  3051 + };
  3052 + ctx.registerReceiver(imgRecv, new IntentFilter(ACTION_SEND_IMAGE), Context.RECEIVER_NOT_EXPORTED);
  3053 +
  3054 + // SEND_VOICE_INTERNAL: send a voice message via w11.r0 + f9 internal API.
  3055 + // The caller (root, Python helper) must pre-place the SILK file at:
  3056 + // /data/data/com.tencent.mm/MicroMsg/{hash}/voice2/{md5(id)[0:2]}/{md5(id)[2:4]}/msg_{id}.amr
  3057 + // Usage: adb shell su -c 'am broadcast -a com.hermes.wechat.SEND_VOICE_INTERNAL \
  3058 + // --es to "filehelper" --es voice_id "26hexchars" --ei duration 3000 [--es from_wxid "wxid_..."]'
  3059 + BroadcastReceiver voiceRecv = new BroadcastReceiver() {
  3060 + @Override
  3061 + public void onReceive(Context context, Intent intent) {
  3062 + if (procName.contains(":")) return;
  3063 + String talker = intent.getStringExtra("to");
  3064 + String voiceId = intent.getStringExtra("voice_id"); // pre-placed file
  3065 + String srcPath = intent.getStringExtra("src_path"); // hook copies from here
  3066 + int duration = intent.getIntExtra("duration", 0);
  3067 + String fromWxId = intent.getStringExtra("from_wxid");
  3068 + if (talker == null || talker.isEmpty()
  3069 + || (voiceId == null && srcPath == null)) {
  3070 + XposedBridge.log("[WeChatHook] SEND_VOICE_INTERNAL: need 'to' + 'voice_id' or 'src_path'");
  3071 + return;
  3072 + }
  3073 + if (duration <= 0) {
  3074 + XposedBridge.log("[WeChatHook] SEND_VOICE_INTERNAL: missing 'duration'");
  3075 + return;
  3076 + }
  3077 + XposedBridge.log("[WeChatHook] SEND_VOICE_INTERNAL proc=" + procName
  3078 + + " to=" + talker + " voice_id=" + voiceId + " src=" + srcPath + " dur=" + duration);
  3079 + final String fVoiceId = voiceId, fSrcPath = srcPath;
  3080 + new Handler(Looper.getMainLooper()).post(() -> {
  3081 + try {
  3082 + sendVoiceViaAPI(talker, fVoiceId, fSrcPath, duration, fromWxId);
  3083 + } catch (Throwable t) {
  3084 + XposedBridge.log("[WeChatHook] SEND_VOICE_INTERNAL failed: " + t
  3085 + + "\n" + android.util.Log.getStackTraceString(t));
  3086 + }
  3087 + });
  3088 + }
  3089 + };
  3090 + ctx.registerReceiver(voiceRecv, new IntentFilter(ACTION_SEND_VOICE), Context.RECEIVER_NOT_EXPORTED);
  3091 +
  3092 + // ARM_VOICE_SWAP: load our TTS SILK into memory and arm the jg0.x.w swap.
  3093 + // After arming, trigger a REAL recording (hold "按住说话") to the target chat —
  3094 + // WeChat records, but jg0.x.w uploads our TTS bytes instead → delivered.
  3095 + // Usage: am broadcast -a com.hermes.wechat.ARM_VOICE_SWAP \
  3096 + // --es src_path /data/data/com.tencent.mm/cache/hook_voice_src.amr --ei duration 3200
  3097 + BroadcastReceiver armRecv = new BroadcastReceiver() {
  3098 + @Override
  3099 + public void onReceive(Context context, Intent intent) {
  3100 + if (procName.contains(":")) return; // main process only (where recording runs)
  3101 + String srcPath = intent.getStringExtra("src_path");
  3102 + int duration = intent.getIntExtra("duration", 0);
  3103 + if (srcPath == null || srcPath.isEmpty()) {
  3104 + XposedBridge.log("[WeChatHook] ARM_VOICE_SWAP: missing 'src_path'");
  3105 + return;
  3106 + }
  3107 + try {
  3108 + java.io.File f = new java.io.File(srcPath);
  3109 + byte[] bytes = new byte[(int) f.length()];
  3110 + try (java.io.FileInputStream in = new java.io.FileInputStream(f)) {
  3111 + int off = 0, n;
  3112 + while (off < bytes.length && (n = in.read(bytes, off, bytes.length - off)) > 0) off += n;
  3113 + }
  3114 + sSwapSilk = bytes;
  3115 + sSwapDuration = duration;
  3116 + sSwapExpiresAt = System.currentTimeMillis() + Math.max(duration, 0) + 10000;
  3117 + sSwapArmed = true;
  3118 + XposedBridge.log("[WeChatHook] ARM_VOICE_SWAP: armed " + bytes.length
  3119 + + "B dur=" + duration + "ms from " + srcPath
  3120 + + " (expires in " + ((sSwapExpiresAt - System.currentTimeMillis()) / 1000)
  3121 + + "s — trigger a real recording now)");
  3122 + } catch (Throwable t) {
  3123 + XposedBridge.log("[WeChatHook] ARM_VOICE_SWAP failed: " + t);
  3124 + }
  3125 + }
  3126 + };
  3127 + ctx.registerReceiver(armRecv, new IntentFilter(ACTION_ARM_SWAP), Context.RECEIVER_NOT_EXPORTED);
  3128 +
  3129 + // DUMP_WECHAT_API: on-demand class introspection (main process only)
  3130 + // Usage: adb shell su -c 'am broadcast -a com.hermes.wechat.DUMP_WECHAT_API [--es class "w11.s1"]'
  3131 + BroadcastReceiver dumpRecv = new BroadcastReceiver() {
  3132 + @Override
  3133 + public void onReceive(Context context, Intent intent) {
  3134 + XposedBridge.log("[WeChatHook] DUMP_WECHAT_API received in " + procName);
  3135 + new Handler(Looper.getMainLooper()).post(() -> handleDumpApi(intent));
  3136 + }
  3137 + };
  3138 + ctx.registerReceiver(dumpRecv, new IntentFilter(ACTION_DUMP_API), Context.RECEIVER_NOT_EXPORTED);
  3139 +
  3140 + XposedBridge.log("[WeChatHook] BroadcastReceivers registered in " + procName);
  3141 + }
  3142 +
  3143 + private static void sendViaR0(String talker, String text) throws Throwable {
  3144 + ClassLoader cl = sTinkerCL != null ? sTinkerCL : sWeChatCL;
  3145 + if (cl == null) throw new IllegalStateException("classloader null");
  3146 + Class<?> r0Class = XposedHelpers.findClass("w11.r0", cl);
  3147 + long ts = System.currentTimeMillis();
  3148 + Object msg;
  3149 + sCalledByUs = true;
  3150 + try {
  3151 + try {
  3152 + msg = XposedHelpers.newInstance(r0Class,
  3153 + new Class<?>[]{String.class, String.class, int.class, int.class, long.class},
  3154 + talker, text, 1, 0, ts);
  3155 + } catch (Throwable t) {
  3156 + msg = XposedHelpers.newInstance(r0Class,
  3157 + new Class<?>[]{String.class, String.class, int.class, int.class, Object.class},
  3158 + talker, text, 1, 0, (Object) ts);
  3159 + }
  3160 + } finally {
  3161 + sCalledByUs = false;
  3162 + }
  3163 +
  3164 + try {
  3165 + Class<?> u0 = XposedHelpers.findClass("com.tencent.mm.modelbase.u0", cl);
  3166 + Object stub = Proxy.newProxyInstance(cl, new Class<?>[]{u0},
  3167 + (proxy, method, args) -> {
  3168 + XposedBridge.log("[WeChatHook] send-cb: " + method.getName());
  3169 + return null;
  3170 + });
  3171 + XposedHelpers.setObjectField(msg, "d", stub);
  3172 + } catch (Throwable ignored) {}
  3173 +
  3174 + sCalledByUs = true;
  3175 + try {
  3176 + XposedHelpers.callMethod(msg, "H", "");
  3177 + } finally {
  3178 + sCalledByUs = false;
  3179 + }
  3180 + }
  3181 +}
... ...
xhs_lsposed_a16_fix/wechathook_src/WeChatHook.java
... ... @@ -142,6 +142,12 @@ public class WeChatHook implements IXposedHookLoadPackage {
142 142 // SILK with our TTS audio during a real (user- or A11y-triggered) recording.
143 143 // This is the ONE route that actually delivers synthetic voice.
144 144 hookVoiceSwap(cl, lpparam.processName);
  145 +
  146 + // Trace the CDN upload submission (dn.m task + assigned aeskey/fileId) on a real
  147 + // voice send — the layer full-synthesis was missing (addSendTask / CdnManager).
  148 + hookCdnTrace(cl, lpparam.processName);
  149 + // Capture the real uploadvoice cgi request (this device uses inline-cgi, not CDN).
  150 + hookVoiceCgiCapture(cl, lpparam.processName);
145 151 }
146 152  
147 153 // ── WCDB hook ──────────────────────────────────────────────────────────────
... ... @@ -1348,6 +1354,151 @@ public class WeChatHook implements IXposedHookLoadPackage {
1348 1354 }
1349 1355 }
1350 1356  
  1357 + // ── Full field dump across the whole class hierarchy (for RE capture) ────────
  1358 + private static void dumpFieldsDeep(Object o, String tag) {
  1359 + if (o == null) { XposedBridge.log("[WeChatHook] " + tag + " = null"); return; }
  1360 + try {
  1361 + StringBuilder sb = new StringBuilder("[WeChatHook] " + tag + " (" + o.getClass().getName() + "):");
  1362 + for (Class<?> c = o.getClass(); c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1363 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1364 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1365 + f.setAccessible(true);
  1366 + Object v; try { v = f.get(o); } catch (Throwable t) { continue; }
  1367 + String vs = v == null ? "null"
  1368 + : (v instanceof byte[] ? "byte[" + ((byte[]) v).length + "]"
  1369 + : (v instanceof String || v instanceof Number || v instanceof Boolean ? v.toString()
  1370 + : v.getClass().getName() + "@" + System.identityHashCode(v)));
  1371 + if (vs.length() > 200) vs = vs.substring(0, 200) + "…";
  1372 + sb.append("\n ").append(f.getName()).append(" (").append(f.getType().getSimpleName()).append(") = ").append(vs);
  1373 + }
  1374 + }
  1375 + XposedBridge.log(sb.toString());
  1376 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] dumpFieldsDeep err: " + t); }
  1377 + }
  1378 +
  1379 + // ── Trace the CDN upload submission for voice (the missing full-synthesis layer) ─
  1380 + // Real voice send: jg0.x.u builds a dn.m task (field_fileType=15, field_fullpath=
  1381 + // voice2 amr, field_mediaId="VideoData"+id, aesKey/fileId empty) and drives the CDN
  1382 + // engine (h2.d=addSendTask → l1.u → native CdnManager.startC2CUpload). The native
  1383 + // side ASSIGNS aeskey+fileId, returned in dn.h to l1.keep_onUploadSuccessed, then
  1384 + // jg0.x.u writes them back to the voiceinfo protobuf + newsendmsg. We OBSERVE only
  1385 + // (no modification) so a real recording still delivers, and we capture the exact
  1386 + // dn.m template + assigned aeskey/fileId to replicate CDN upload for synthetic voice.
  1387 + private void hookCdnTrace(ClassLoader cl, String procName) {
  1388 + // 1) h2.d(dn.m) = addSendTask — dump the full task struct on submit.
  1389 + try {
  1390 + Class<?> h2 = XposedHelpers.findClass("com.tencent.mm.modelcdntran.h2", cl);
  1391 + Class<?> dnm = XposedHelpers.findClass("dn.m", cl);
  1392 + XposedBridge.hookMethod(h2.getDeclaredMethod("d", dnm), new XC_MethodHook() {
  1393 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1394 + XposedBridge.log("[WeChatHook] CDNTRACE h2.d(addSendTask) ENTER");
  1395 + if (p.args != null && p.args.length > 0) dumpFieldsDeep(p.args[0], "CDNTRACE addSendTask dn.m");
  1396 + }
  1397 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1398 + XposedBridge.log("[WeChatHook] CDNTRACE h2.d ret=" + p.getResult());
  1399 + }
  1400 + });
  1401 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked h2.d(addSendTask) in " + procName);
  1402 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace h2.d failed in " + procName + ": " + t); }
  1403 +
  1404 + // 2) l1.keep_onUpload* — the native CDN callback carrying assigned aeskey/fileId (dn.h).
  1405 + try {
  1406 + Class<?> l1 = XposedHelpers.findClass("com.tencent.mm.modelcdntran.l1", cl);
  1407 + int n = 0;
  1408 + for (java.lang.reflect.Method m : l1.getDeclaredMethods()) {
  1409 + if (!m.getName().startsWith("keep_onUpload")) continue;
  1410 + m.setAccessible(true);
  1411 + final String mn = m.getName();
  1412 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1413 + @Override protected void afterHookedMethod(MethodHookParam p) {
  1414 + XposedBridge.log("[WeChatHook] CDNTRACE l1." + mn + " nargs=" + (p.args == null ? 0 : p.args.length));
  1415 + if (p.args != null) for (Object a : p.args) {
  1416 + if (a != null && a.getClass().getName().equals("dn.h")) dumpFieldsDeep(a, "CDNTRACE " + mn + " dn.h");
  1417 + }
  1418 + }
  1419 + });
  1420 + n++;
  1421 + }
  1422 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked l1.keep_onUpload* x" + n + " in " + procName);
  1423 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace l1 failed in " + procName + ": " + t); }
  1424 +
  1425 + // 3) jg0.x.u — the orchestrator (builds dn.m, writes aeskey back). Log entry to
  1426 + // confirm it fires + timing vs the CDN calls.
  1427 + try {
  1428 + Class<?> x = XposedHelpers.findClass("jg0.x", cl);
  1429 + int n = 0;
  1430 + for (java.lang.reflect.Method m : x.getDeclaredMethods()) {
  1431 + if (!"u".equals(m.getName())) continue;
  1432 + m.setAccessible(true);
  1433 + XposedBridge.hookMethod(m, new XC_MethodHook() {
  1434 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1435 + XposedBridge.log("[WeChatHook] CDNTRACE jg0.x.u ENTER nargs=" + (p.args == null ? 0 : p.args.length));
  1436 + if (p.args != null && p.args.length > 1 && p.args[1] != null)
  1437 + dumpFieldsDeep(p.args[1], "CDNTRACE jg0.x.u w21.w0");
  1438 + }
  1439 + });
  1440 + n++;
  1441 + }
  1442 + XposedBridge.log("[WeChatHook] hookCdnTrace: hooked jg0.x.u x" + n + " in " + procName);
  1443 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookCdnTrace jg0.x.u failed in " + procName + ": " + t); }
  1444 + }
  1445 +
  1446 + // ── Capture the real uploadvoice cgi request (this device's actual voice path) ──
  1447 + // This device uses the INLINE-cgi branch of jg0.x.w (not CDN): it builds a
  1448 + // com.tencent.mm.modelbase.l reqresp with url /cgi-bin/micromsg-bin/uploadvoice,
  1449 + // request pb r45.cv6 carrying the SILK inline in field 7. The scene
  1450 + // (modelbase.i.f70699d, a NetScene = m1 subclass) can be submitted via z2.b — the
  1451 + // SAME queue our text send uses. Hook modelbase.l.a() (the reqresp builder, fires
  1452 + // mid-jg0.x.w) filtered to the uploadvoice url, and dump every cv6 field index so
  1453 + // we can replicate the exact wire request for fully-synthetic voice.
  1454 + private void hookVoiceCgiCapture(ClassLoader cl, String procName) {
  1455 + try {
  1456 + Class<?> lCls = XposedHelpers.findClass("com.tencent.mm.modelbase.l", cl);
  1457 + final Class<?> pbCls = XposedHelpers.findClass("com.tencent.mm.protobuf.f", cl);
  1458 + XposedBridge.hookMethod(lCls.getDeclaredMethod("a"), new XC_MethodHook() {
  1459 + @Override protected void beforeHookedMethod(MethodHookParam p) {
  1460 + try {
  1461 + // Field names differ base-vs-tinker, so locate by TYPE: the url String
  1462 + // (contains cgi-bin) + the request/response protobufs (protobuf.f).
  1463 + Object self = p.thisObject;
  1464 + String url = null;
  1465 + java.util.List<Object> pbs = new java.util.ArrayList<>();
  1466 + for (Class<?> c = self.getClass(); c != null && !c.equals(Object.class); c = c.getSuperclass()) {
  1467 + for (java.lang.reflect.Field f : c.getDeclaredFields()) {
  1468 + if (java.lang.reflect.Modifier.isStatic(f.getModifiers())) continue;
  1469 + f.setAccessible(true);
  1470 + Object v; try { v = f.get(self); } catch (Throwable t) { continue; }
  1471 + if (v instanceof String && ((String) v).contains("cgi-bin")) url = (String) v;
  1472 + else if (v != null && pbCls.isInstance(v)) pbs.add(v);
  1473 + }
  1474 + }
  1475 + if (url == null || !url.contains("uploadvoice")) return; // gate: voice cgi only
  1476 + StringBuilder sb = new StringBuilder("[WeChatHook] VOICECGI url=" + url + " pbCount=" + pbs.size());
  1477 + int idx = 0;
  1478 + for (Object req : pbs) {
  1479 + sb.append("\n -- pb#").append(idx++).append(" ").append(req.getClass().getName()).append(" --");
  1480 + for (int i = 0; i <= 25; i++) {
  1481 + Object val = null; String kind = "";
  1482 + try { Object c = XposedHelpers.callMethod(req, "getCustom", i);
  1483 + if (c != null) { val = "custom:" + c.getClass().getName(); kind = "C"; } } catch (Throwable t) {}
  1484 + if (val == null) { try { Object s = XposedHelpers.callMethod(req, "getString", i); if (s != null) { val = s; kind = "S"; } } catch (Throwable t) {} }
  1485 + if (val == null) { try { Object iv = XposedHelpers.callMethod(req, "getInteger", i); if (iv != null && ((Integer) iv) != 0) { val = iv; kind = "I"; } } catch (Throwable t) {} }
  1486 + if (val == null) { try { Object lv = XposedHelpers.callMethod(req, "getLong", i); if (lv != null && ((Long) lv) != 0L) { val = lv; kind = "L"; } } catch (Throwable t) {} }
  1487 + if (val != null) {
  1488 + String vs = String.valueOf(val);
  1489 + if (vs.length() > 140) vs = vs.substring(0, 140) + "…";
  1490 + sb.append("\n [").append(i).append("](").append(kind).append(")=").append(vs);
  1491 + }
  1492 + }
  1493 + }
  1494 + XposedBridge.log(sb.toString());
  1495 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] VOICECGI err: " + t); }
  1496 + }
  1497 + });
  1498 + XposedBridge.log("[WeChatHook] hookVoiceCgiCapture: hooked modelbase.l.a() in " + procName);
  1499 + } catch (Throwable t) { XposedBridge.log("[WeChatHook] hookVoiceCgiCapture failed in " + procName + ": " + t); }
  1500 + }
  1501 +
1351 1502 private void hookVoiceUpload(ClassLoader cl, String procName) {
1352 1503 try {
1353 1504 Class<?> g1 = XposedHelpers.findClass("w21.g1", cl);
... ... @@ -2503,6 +2654,10 @@ public class WeChatHook implements IXposedHookLoadPackage {
2503 2654 hookVoiceProbe(sTinkerCL, procName + "/tinker");
2504 2655 // Image send runs in Tinker CL — hook b80.u.pj/Bi there.
2505 2656 hookImageSend(sTinkerCL, procName + "/tinker");
  2657 + // CDN upload trace runs in Tinker CL (real voice send path).
  2658 + hookCdnTrace(sTinkerCL, procName + "/tinker");
  2659 + // Capture the real uploadvoice cgi request in Tinker CL.
  2660 + hookVoiceCgiCapture(sTinkerCL, procName + "/tinker");
2506 2661 }
2507 2662 hookF9ConvertTo(sWeChatCL, procName);
2508 2663 hookF9ImgPathInjector(sWeChatCL, procName);
... ...