mirror of
https://github.com/yincongcyincong/wechat_chatter.git
synced 2026-07-15 10:26:52 +08:00
@@ -14,6 +14,10 @@ import (
|
||||
func HandleProtobufMsgAndSend(payload map[string]interface{}) {
|
||||
jsonData, err := HandleProtobufMsg(payload)
|
||||
if err != nil {
|
||||
if isUnsupportedProtobufMessage(err) {
|
||||
Warn("跳过不匹配的protobuf消息", "err", err)
|
||||
return
|
||||
}
|
||||
Error("protobuf消息处理失败", "err", err)
|
||||
return
|
||||
}
|
||||
@@ -29,6 +33,18 @@ func HandleProtobufMsgAndSend(payload map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func isUnsupportedProtobufMessage(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
message := err.Error()
|
||||
return strings.Contains(message, "cannot parse invalid wire-format data") ||
|
||||
strings.Contains(message, "cannot extract message data") ||
|
||||
strings.Contains(message, "missing required fields") ||
|
||||
strings.Contains(message, "no messages found")
|
||||
}
|
||||
|
||||
func HandleProtobufMsg(payload map[string]interface{}) ([]byte, error) {
|
||||
dataInter, ok := payload["data"]
|
||||
if !ok {
|
||||
@@ -52,10 +68,7 @@ func HandleProtobufMsg(payload map[string]interface{}) ([]byte, error) {
|
||||
msg := &wxproto.WxRecvMsg{}
|
||||
err := proto.Unmarshal(rawBytes, msg)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "cannot parse invalid wire-format data") {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("protobuf unmarshal failed: %w", err)
|
||||
return nil, fmt.Errorf("protobuf unmarshal failed (data_len=%d): %w", len(rawBytes), err)
|
||||
}
|
||||
|
||||
data := getWxMsgData(msg)
|
||||
|
||||
+16
-9
@@ -1047,20 +1047,27 @@ function setReceiver() {
|
||||
|
||||
pendingBuf2RespTaskId = 0;
|
||||
pendingSendMsgType = "";
|
||||
}
|
||||
|
||||
if (x2 < 4) {
|
||||
return;
|
||||
}
|
||||
if (x2 > MAX_FRIDA_MESSAGE_BYTES) {
|
||||
console.warn("[skip] protobuf_msg length out of range: " + x2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (x2 < 4 || x2 > MAX_FRIDA_MESSAGE_BYTES) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. field 2 wrapper长度 < 128 (单字节varint) → wrapper内容过小,非聊天消息
|
||||
if (currentPtr.add(2).readU8() === 0x10 || currentPtr.add(2).readU8() === 0x16 || (currentPtr.add(3).readU8() & 0x80) === 0) {
|
||||
return;
|
||||
}
|
||||
const mem = readByteArrayIfReadable(currentPtr, x2);
|
||||
if (!mem) return;
|
||||
if (!mem) {
|
||||
console.warn("[skip] protobuf_msg memory read failed, length=" + x2);
|
||||
return;
|
||||
}
|
||||
const uint8Array = new Uint8Array(mem);
|
||||
// 与已验证稳定的旧版本保持一致,只做最宽松的消息候选判断。
|
||||
// 具体结构交给 Go 解析,宁可产生误判日志,也不要在 JS 层漏掉消息。
|
||||
if (uint8Array[0] !== 0x08) {
|
||||
return;
|
||||
}
|
||||
|
||||
send({
|
||||
type: "protobuf_msg",
|
||||
|
||||
Reference in New Issue
Block a user