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