# WeChat Send Message — Complete Smali Code Trace Date: 2026-06-30 Source: Direct smali reading from wechat_decompiled/ (apktool, 261MB APK → 2.4GB) ## Entry Point: sk.p0() — The Text Send Method File: `smali_classes11/com/tencent/mm/ui/chatting/component/sk.smali` (1169 lines) ``` .method public final p0(Ljava/lang/String;ILjava/lang/String;)Z ``` Parameters: - p1 = String (message text) - p2 = int (message type, typically 1 for text) - p3 = String (extra — talker/content/attachment info) Log tag: `"MicroMsg.ChattingUI.SendTextComponent"` ### Method Flow 1. **Clean input** (line 416): `t8.K(p1)` — strip/clean the text 2. **Empty check** (line 426): Return false if empty 3. **Command processing** (line 435-472): `CommandProcessorEvent` — checks for `/command` syntax 4. **Hardware coder setup** (lines 474-548): `WXHardCoderJNI` — boosts CPU for send 5. **Message construction**: Builds protobuf, writes to DB 6. **Observer registration**: Calls `o0()` to register for onSceneEnd callback 7. **Network dispatch**: Creates NetSceneSendMsg → mars::stn 8. **Recursive retry**: Lines 1061, 1074 — self-calls `p0()` for split/long messages ### Observer Method: o0() Line 283. Registers the ChattingUI reference (`p0.e` = `i9` instance) into a synchronized list `mo3/l.d`. Sets up notification listener for send completion. ### Response Handler: onSceneEnd() Line 367. Checks `p4.getType() == 0x20a` (522 = NetSceneSendMsg funcID). Stops hardware coder performance boost on completion. ## NetSceneSendMsg: w11/r0.smali File: `smali_classes12/w11/r0.smali` (2948 lines) ### Constructor (line ~1580) Key lines: ``` 1598: const-string v2, "/cgi-bin/micromsg-bin/newsendmsg" 1602: const/16 v2, 0x20a # funcID = 522 1606: const/16 v2, 0xed # MMFunc = 237 1610: const v2, 0x3b9acaed # session flag ``` Request/Response protobuf setup: ``` 1586: new-instance v2, Lr45/ez5; # request protobuf 1592: new-instance v2, Lr45/fz5; # response protobuf ``` ### getType() Method Line 1994. Returns `0x20a` (522). This is the funcID that `onSceneEnd` checks against. ### Response Handling: onGYNetEnd() Line 2002. Processes the server response. Extracts messages from `r45/fz5.e` (LinkedList), iterates through results, dispatches to `PluginMessengerFoundation`. ## Protobuf Structures ### SendMsgRequest: r45/ez5.smali File: `smali_classes12/r45/ez5.smali` (328 lines) Fields: ``` d: int # message count e: LinkedList # list of r45/ll4 (individual messages) ``` Constructor initializes `e` as new LinkedList. The `b()` method builds the full CGI request with funcID 522. ### Per-Message: r45/ll4.smali Each element in ez5.e: ``` d: r45/du5 # sub-object { d:String, e:boolean } e: String # talker ID (e.g., "filehelper", "wxid_xxx") f: int # message type (1=text, 3=image, ...) g: int # createTime (timestamp) h: int # hash code (from talker string hash) ``` ### Sub-Object: r45/du5.smali ``` d: String # content/metadata string e: boolean # flag ``` ### Construction in r0.smali (lines ~1769-1833) ``` 1769: v10.A0() → ll4.f (type) 1783: v10.Q0() → du5.d (content string from message storage) 1787: iput → du5.d 1789: iput-boolean v4 → du5.e = true 1791: iput → ll4.d (set du5 into ll4) 1793: v10.getCreateTime() → ll4.g (timestamp) 1805: v10.getType() → ll4.f 1811: v10.j() → ll4.e (talker string) 1829: .hashCode() → ll4.h ``` Message data source: `com/tencent/mm/storage/f9` (WeChat's message storage object) ## CGI Dispatch Path ``` sk.p0() → o0() — register observer → NetSceneSendMsg(w11/r0) constructor → r45/ez5 ← r45/ll4 list → CGI path: /cgi-bin/micromsg-bin/newsendmsg → funcID: 522 → mars::stn dispatch (ECDH encrypted tunnel) → WeChat Server ← onSceneEnd() — handle response ``` ## Why Direct CGI Call Fails The `/cgi-bin/micromsg-bin/newsendmsg` path is NOT an HTTP URL. It's a logical route identifier used by mars::stn to dispatch through the ECDH-encrypted long connection. The actual bytes are: 1. Protobuf-serialized `ez5` request 2. AES-encrypted with session key (from ECDH handshake) 3. Wrapped in mars binary framing 4. Sent over TCP/QUIC to WeChat server Cannot be called with `curl` — requires the full mars session state. ## EnMicroMsg.db Status Codes Query result (2026-06-30): | status | isSend | Count | Meaning | |--------|--------|-------|---------| | 2 | 1 | 37 | Sent | | 3 | 0 | 2692 | Received | | 3 | 1 | 25 | Delivered | | null | 0 | 19 | System | | 4 | 0 | 17 | Other | | 6 | 0 | 204 | Special | **Key**: No status=0 or status=1 → no pending/sending queue in DB. mars uses in-memory task queue (`mars::stn::NetSource::StartTask()`). ## Module Skeleton Location: `/data/data/com.termux/files/home/WeChatHook/` ### WeChatHook.java (current state — passive logger) ```java public class WeChatHook implements IXposedHookLoadPackage { private static final String TARGET_CLASS = "com.tencent.mm.ui.chatting.component.sk"; private static final String TARGET_METHOD = "p0"; @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) { if (!lpparam.packageName.equals("com.tencent.mm")) return; XposedHelpers.findAndHookMethod(TARGET_CLASS, lpparam.classLoader, TARGET_METHOD, String.class, int.class, String.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) { String msg = (String) param.args[0]; int type = (int) param.args[1]; String extra = (String) param.args[2]; Log.i(TAG, "[HOOK] sk.p0: " + msg); } }); } } ``` ### Required Changes for Active Send The current module only logs. To make it an active sender, add: 1. **Save sk instance**: `param.thisObject` in `beforeHookedMethod` 2. **File command queue**: Poll `/sdcard/wechat_send_cmd.txt` every 2 seconds 3. **Command format**: `talkerId|messageText|type` 4. **Trigger send**: Call the saved instance's `p0(msg, type, extra)` The `sk` instance holds `Lyb5/d` (ChattingUI context) in field `d`, which provides: - `t()` → current talker (chat username) - `x()` → talker username - `g()` → Activity context **Compilation**: Must be done on Mac/PC with Android Studio. Termux lacks Android SDK, gradle, d8, zipalign, apksigner.