mirror of
https://github.com/yincongcyincong/wechat_chatter.git
synced 2026-07-15 10:26:52 +08:00
修复下载分片还没全部到齐,GetDownloadPath 就判断开始解密导致的误报Error
This commit is contained in:
@@ -52,6 +52,9 @@ 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)
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -162,7 +162,14 @@ func SilkToMp3(silkBytes []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func GetFilePath(data []byte, key []byte) (string, error) {
|
||||
block, _ := aes.NewCipher(key)
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(data) == 0 || len(data)%block.BlockSize() != 0 {
|
||||
return "", fmt.Errorf("invalid encrypted data length: %d, block_size: %d", len(data), block.BlockSize())
|
||||
}
|
||||
|
||||
decrypted := make([]byte, len(data))
|
||||
bs := block.BlockSize()
|
||||
for i := 0; i < len(data); i += bs {
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
@@ -334,6 +335,16 @@ func GetDownloadPath(cdnUrl, aesKeyStr string) (string, error) {
|
||||
|
||||
// 数据接收完成,尝试解密
|
||||
if len(downloadReq.Media) > 0 {
|
||||
if len(downloadReq.Media)%aes.BlockSize != 0 {
|
||||
Info("文件数据仍未对齐 AES 块,继续等待", "url", cdnUrl, "times", i, "media_len", len(downloadReq.Media), "block_size", aes.BlockSize)
|
||||
if i < 9 {
|
||||
time.Sleep(2 * time.Second)
|
||||
continue
|
||||
}
|
||||
userID2FileMsgMap.Delete(cdnUrl)
|
||||
return "", fmt.Errorf("文件数据长度不是 AES 块大小倍数: media_len=%d block_size=%d", len(downloadReq.Media), aes.BlockSize)
|
||||
}
|
||||
|
||||
aesKey, err := hex.DecodeString(aesKeyStr)
|
||||
if err != nil {
|
||||
Error("AES key 解码失败", "err", err)
|
||||
|
||||
Reference in New Issue
Block a user