1
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
昔念
2026-02-08 02:11:46 +08:00
parent af29b13ba4
commit 2b25ae6b35
9 changed files with 64 additions and 44 deletions

View File

@@ -172,6 +172,36 @@ func NewClientData(c gnet.Conn) *ClientData {
}
// XORDecrypt 异或解密函数密钥改为uint32版本
// 核心逻辑将uint32密钥拆分为4字节数组大端序适配AS3二进制处理习惯循环与加密数据异或
// 参数:
//
// encryptedData - 待解密的字节数组
// key - 32位无符号整数密钥替代原字符串密钥
//
// 返回值:解密后的字节数组
func XORDecryptU(encryptedData []byte, key uint32) []byte {
// 边界条件:待解密数据为空,直接返回空
if len(encryptedData) == 0 {
return []byte{}
}
// 1. 将uint32密钥转换为4字节数组关键步骤
// 字节序选择BigEndian大端是AS3/Java等语言的默认二进制处理方式若需小端可改为binary.LittleEndian
keyBytes := make([]byte, 4) // uint32固定占4个字节
binary.BigEndian.PutUint32(keyBytes, key)
keyLen := len(keyBytes) // 固定为4无需额外判断长度
// 2. 执行异或解密(逻辑与原版本一致,仅密钥来源不同)
decrypted := make([]byte, len(encryptedData))
for i, b := range encryptedData {
// 循环复用4字节密钥索引取模i%4
keyIndex := i % keyLen
decrypted[i] = b ^ keyBytes[keyIndex]
}
return decrypted
}
func XORDecrypt(encryptedData []byte, keyStr string) []byte {
if len(encryptedData) == 0 || keyStr == "" {
return []byte{}
@@ -211,16 +241,17 @@ func (h *ClientData) OnEvent(v []byte) {
// 解析Len0-3字节
header.Len = binary.BigEndian.Uint32(v[0:4])
// 解析Version第4字节
header.Version = v[4]
//header.Version = v[4]
// 解析CMD5-8字节
header.CMD = binary.BigEndian.Uint32(v[5:9])
// 解析UserID9-12字节
header.UserID = binary.BigEndian.Uint32(v[9:13])
// 解析Result13-16字节
header.Result = binary.BigEndian.Uint32(v[13:17])
//header.Result = binary.BigEndian.Uint32(v[13:17])
// 解析数据部分17字节之后
if len(v) > 17 {
header.Data = XORDecrypt(v[17:], "CWF")
header.Data = v[17:]
} else {
header.Data = []byte{} // 数据部分为空时显式初始化
}
@@ -233,6 +264,7 @@ func (h *ClientData) OnEvent(v []byte) {
fmt.Println(header.UserID, "未创建角色")
return
}
header.Data = XORDecryptU(header.Data, t.Player.Hash)
}
if cool.Config.ServerInfo.IsDebug != 0 {
fmt.Println("接收数据", header.UserID, header.CMD)