This commit is contained in:
@@ -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) {
|
||||
// 解析Len(0-3字节)
|
||||
header.Len = binary.BigEndian.Uint32(v[0:4])
|
||||
// 解析Version(第4字节)
|
||||
header.Version = v[4]
|
||||
//header.Version = v[4]
|
||||
// 解析CMD(5-8字节)
|
||||
header.CMD = binary.BigEndian.Uint32(v[5:9])
|
||||
// 解析UserID(9-12字节)
|
||||
header.UserID = binary.BigEndian.Uint32(v[9:13])
|
||||
// 解析Result(13-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)
|
||||
|
||||
Reference in New Issue
Block a user