Commit a5606b3fa4c44df944d8dcc7091d65aede4b89c3

Authored by yibo
1 parent 93b22c42

feat(wechathook): 图片 CDN 上传打通 — 内部 API 发图完全可用 ✅

攻克图片发送最后一公里(LSPosed,微信 8.0.74,真机验证全分辨率送达):

根因: b80.u.oj(o70.k) 只做「插消息 f9 + 插 ImgInfo b0 + 建缩略图」并
返回 List<o70.l> CDN 上传描述符,自己不提交 CDN。旧代码拿到 res 就丢掉
list → 上传永不触发(缩略图渲染但全图转圈)。真实编排 pe5.f.a 才循环
list 逐图提交(b80.s 只是 prebuild service checkPreBuildImg,不含 oj)。

补上第二步(照搬 pe5.f.a): oj() 后对每个 o70.l:
  cdnSvc = n0.c(xs.d1.class)  // v70.w MsgImgFeatureService
  g = new r70.g(l.e, compress, c01.z1.r()/*self wxid*/, talker, k70.i0{a=3})
  cdnSvc.oj(g, l)             // → 启动 CDN 上传协程 e80.c

真机: oj() DONE res=size=1 + CDN submit DONE items=1,无异常;filehelper
收到消息点开是全分辨率原图(有原图+保存按钮,不再转圈)。

坑: v70.w.oj 内部走 ViewModelProvider.get 须主线程调(广播 receiver 本就在
主线程);jadx 字段名末位字母=真实 dex 字段;XposedHelpers stub 无
getLongField 用原生反射。逆向靠拉 Tinker dex + jadx --single-class。

产物: WECHAT_SEND_API.md §3 完整两步实现 + API 表;backups 源码快照。

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