# WeChat SendMsg CGI Analysis Date: 2026-06-30 Source: smali decompilation of WeChat 8.0.74 (smali_classes12/w11/r0.smali) ## CGI Endpoint ``` POST /cgi-bin/micromsg-bin/newsendmsg FuncID: 522 (0x20a) MMFunc: 237 (0xed) ``` ## Protobuf Schema ### Request: r45/ez5 ``` ez5 { d: int // message count? e: LinkedList // list of messages } ``` ### Message Element: r45/ll4 ``` ll4 { d: du5 { // content descriptor d: String // content type descriptor e: boolean // flag } e: String // talker / content reference f: int // message type (1=text, 3=image, etc.) g: int // create time (timestamp) h: int // hash code } ``` ### Response: r45/fz5 ```java fz5 { e: LinkedList // response items f: int // result code } ``` ## Transport Layer **NOT direct HTTP**. All CGI requests go through mars::stn: 1. Protobuf body is ECDH-encrypted with mars session key 2. Sent over mars QUIC/TCP long connection 3. NetScene framework (w11/r0 extends m1) dispatches via mars ## Code Reference (r0.smali) ### CGI Path Assignment (lines 1580-1618) ```smali # Build CGI request new-instance v1, Lcom/tencent/mm/modelbase/l; invoke-direct {v1}, Lcom/tencent/mm/modelbase/l;->()V new-instance v2, Lr45/ez5; # Request protobuf invoke-direct {v2}, Lr45/ez5;->()V iput-object v2, v1, Lcom/tencent/mm/modelbase/l;->a:Lcom/tencent/mm/protobuf/f; new-instance v2, Lr45/fz5; # Response protobuf invoke-direct {v2}, Lr45/fz5;->()V iput-object v2, v1, Lcom/tencent/mm/modelbase/l;->b:Lcom/tencent/mm/protobuf/f; const-string v2, "/cgi-bin/micromsg-bin/newsendmsg" iput-object v2, v1, Lcom/tencent/mm/modelbase/l;->c:Ljava/lang/String; const/16 v2, 0x20a # FuncID = 522 iput v2, v1, Lcom/tencent/mm/modelbase/l;->d:I const/16 v2, 0xed # MMFunc = 237 iput v2, v1, Lcom/tencent/mm/modelbase/l;->e:I const v2, 0x3b9acaed # Session flag iput v2, v1, Lcom/tencent/mm/modelbase/l;->f:I ``` ### getType() Method (line 1994) ```smali .method public getType()I .locals 1 const/16 v0, 0x20a return v0 .end method ``` ### onGYNetEnd Response Handler (line 2002) ```smali # Checks response type == 0x20a # Parses fz5 response # e.f (result code) determines success # Calls PluginMessengerFoundation.Di() to update message status ``` ## Why Direct HTTP Call Fails 1. **No HTTP listener**: `/cgi-bin/micromsg-bin/newsendmsg` is NOT a REST endpoint 2. **mars session required**: Body encrypted with ECDH session key 3. **Session establishment**: Requires mars ECDH handshake (native code) 4. **Cookie/header auth**: Session tokens bound to mars connection, not HTTP cookies ## Fallback Attempt (curl from Termux) ```bash # This WILL fail — no direct HTTP access curl -X POST 'https://szlong.weixin.qq.com/cgi-bin/micromsg-bin/newsendmsg' \ -H 'Content-Type: application/octet-stream' \ --data-binary @ez5_request.bin # → Connection refused or 404 (endpoint not HTTP-exposed) ``` ## Comparison with XHS BCIM | | XHS BCIM | WeChat mars | |---|---|---| | Protocol | Custom Longlink Java | mars C++ native | | Encoding | JSON | Protobuf | | Encryption | None (plain TCP) | ECDH + AES | | CGI path | N/A (pure socket) | `/cgi-bin/micromsg-bin/newsendmsg` | | HTTP fallback | None | None (CGI transported via mars) | | Replayability | Can replay via xhshook proxy | Cannot — needs mars session |