优化转发模式抓包

This commit is contained in:
flswld committed 2024-09-26 15:31:58 +08:00
1 parent 4d956a9b38
commit b46a4a2ef1
3 files changed
+51 -36

No files matched your search

@@ -389,20 +389,6 @@ func (c *Controller) queryRegionListForwardMode() (string, error) {
queryRegionListHttpRsp.ClientSecretKey = c.ec2b.Bytes()
endec.Xor(queryRegionListHttpRsp.ClientCustomConfigEncrypted, ec2b.XorKey())
logger.Info("ClientCustomConfigEncrypted: %v", string(queryRegionListHttpRsp.ClientCustomConfigEncrypted))
clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{
SdkEnv: "2",
CheckDevice: false,
LoadPatch: false,
ShowException: false,
RegionConfig: "pm|fk|add",
DownloadMode: 0,
DebugMenu: true,
DebugLogSwitch: []int32{0},
DebugLog: true,
CodeSwitch: []int32{3628},
CoverSwitch: []int32{40},
})
queryRegionListHttpRsp.ClientCustomConfigEncrypted = clientCustomConfig
endec.Xor(queryRegionListHttpRsp.ClientCustomConfigEncrypted, c.ec2b.XorKey())
regionListData, err := pb.Marshal(queryRegionListHttpRsp)
if err != nil {
@@ -508,31 +494,9 @@ func (c *Controller) queryCurRegionForwardMode(version int, gateServerAddr *api.
regionCurr.RegionInfo.GateserverPort = gateServerAddr.KcpPort
endec.Xor(regionCurr.RegionCustomConfigEncrypted, ec2b.XorKey())
logger.Info("RegionCustomConfigEncrypted: %v", string(regionCurr.RegionCustomConfigEncrypted))
regionCustomConfig, _ := json.Marshal(&RegionCustomConfig{
CloseAntiDebug: true,
ForceKill: false,
AntiDebugPc: false,
AntiDebugIos: false,
AntiDebugAndroid: false,
})
regionCurr.RegionCustomConfigEncrypted = regionCustomConfig
endec.Xor(regionCurr.RegionCustomConfigEncrypted, c.ec2b.XorKey())
endec.Xor(regionCurr.ClientRegionCustomConfigEncrypted, ec2b.XorKey())
logger.Info("ClientRegionCustomConfigEncrypted: %v", string(regionCurr.ClientRegionCustomConfigEncrypted))
clientCustomConfig, _ := json.Marshal(&ClientCustomConfig{
SdkEnv: "2",
CheckDevice: false,
LoadPatch: false,
ShowException: false,
RegionConfig: "pm|fk|add",
DownloadMode: 0,
DebugMenu: true,
DebugLogSwitch: []int32{0},
DebugLog: true,
CodeSwitch: []int32{3628},
CoverSwitch: []int32{40},
})
regionCurr.ClientRegionCustomConfigEncrypted = clientCustomConfig
endec.Xor(regionCurr.ClientRegionCustomConfigEncrypted, c.ec2b.XorKey())
return regionCurr, nil
}
+24
View File
@@ -2,6 +2,7 @@ package net
import (
"bytes"
"encoding/base64"
"encoding/json"
"reflect"
"strings"
@@ -24,6 +25,9 @@ type ProtoMsg struct {
CmdId uint16
HeadMessage *proto.PacketHead
PayloadMessage pb.Message
NotParse bool
HeadRaw string
PayloadRaw string
}
type ProtoMessage struct {
@@ -34,43 +38,61 @@ type ProtoMessage struct {
func ProtoDecode(kcpMsg *KcpMsg,
serverCmdProtoMap *cmd.CmdProtoMap, clientCmdProtoMap *client_proto.ClientCmdProtoMap) (protoMsgList []*ProtoMsg) {
protoMsgList = make([]*ProtoMsg, 0)
notParseDumpRaw := func() {
protoMsgList = append(protoMsgList, &ProtoMsg{
SessionId: kcpMsg.SessionId,
CmdId: kcpMsg.CmdId,
HeadMessage: nil,
PayloadMessage: nil,
NotParse: true,
HeadRaw: base64.StdEncoding.EncodeToString(kcpMsg.HeadData),
PayloadRaw: base64.StdEncoding.EncodeToString(kcpMsg.ProtoData),
})
}
if config.GetConfig().Hk4e.ClientProtoProxyEnable {
clientCmdId := kcpMsg.CmdId
clientProtoData := kcpMsg.ProtoData
cmdName := clientCmdProtoMap.GetClientCmdNameByCmdId(clientCmdId)
if cmdName == "" {
logger.Error("get cmdName is nil, clientCmdId: %v", clientCmdId)
notParseDumpRaw()
return protoMsgList
}
clientProtoObj := GetClientProtoObjByName(cmdName, clientCmdProtoMap)
if clientProtoObj == nil {
logger.Error("get client proto obj is nil, cmdName: %v", cmdName)
notParseDumpRaw()
return protoMsgList
}
err := pb.Unmarshal(clientProtoData, clientProtoObj)
if err != nil {
logger.Error("unmarshal client proto error: %v", err)
notParseDumpRaw()
return protoMsgList
}
serverCmdId := serverCmdProtoMap.GetCmdIdByCmdName(cmdName)
if serverCmdId == 0 {
logger.Error("get server cmdId is nil, cmdName: %v", cmdName)
notParseDumpRaw()
return protoMsgList
}
serverProtoObj := serverCmdProtoMap.GetProtoObjByCmdId(serverCmdId)
if serverProtoObj == nil {
logger.Error("get server proto obj is nil, serverCmdId: %v", serverCmdId)
notParseDumpRaw()
return protoMsgList
}
err = object.CopyProtoBufSameField(serverProtoObj, clientProtoObj)
if err != nil {
logger.Error("copy proto obj error: %v", err)
notParseDumpRaw()
return protoMsgList
}
ConvClientPbDataToServer(serverProtoObj, clientCmdProtoMap)
serverProtoData, err := pb.Marshal(serverProtoObj)
if err != nil {
logger.Error("marshal server proto error: %v", err)
notParseDumpRaw()
return protoMsgList
}
kcpMsg.CmdId = serverCmdId
@@ -85,6 +107,7 @@ func ProtoDecode(kcpMsg *KcpMsg,
err := pb.Unmarshal(kcpMsg.HeadData, headMsg)
if err != nil {
logger.Error("unmarshal head data err: %v", err)
notParseDumpRaw()
return protoMsgList
}
protoMsg.HeadMessage = headMsg
@@ -96,6 +119,7 @@ func ProtoDecode(kcpMsg *KcpMsg,
ProtoDecodePayloadLoop(kcpMsg.CmdId, kcpMsg.ProtoData, &protoMessageList, serverCmdProtoMap, clientCmdProtoMap)
if len(protoMessageList) == 0 {
logger.Error("decode proto object is nil")
notParseDumpRaw()
return protoMsgList
}
if kcpMsg.CmdId == cmd.UnionCmdNotify && !config.GetConfig().Hk4e.ForwardModeEnable {
+27
View File
@@ -26,6 +26,9 @@ type Packet struct {
CmdName string `json:"cmd_name"`
HeadMsg string `json:"head_msg"`
PayloadMsg string `json:"payload_msg"`
NotParse bool `json:"not_parse"`
HeadRaw string `json:"head_raw"`
PayloadRaw string `json:"payload_raw"`
}
type Session struct {
@@ -135,6 +138,30 @@ func (s *Session) recvHandle() {
for _, v := range kcpMsgList {
protoMsgList := hk4egatenet.ProtoDecode(v, s.ServerCmdProtoMap, s.ClientCmdProtoMap)
for _, vv := range protoMsgList {
if vv.NotParse {
packet := &Packet{
Time: uint64(time.Now().UnixMilli()),
Dir: "RECV",
CmdId: uint32(vv.CmdId),
CmdName: "",
HeadMsg: "",
PayloadMsg: "",
NotParse: true,
HeadRaw: vv.HeadRaw,
PayloadRaw: vv.PayloadRaw,
}
packetData, _ := json.Marshal(packet)
s.PktLock.Lock()
s.PktList = append(s.PktList, packet)
if s.PktCapWsConn != nil {
err := s.PktCapWsConn.WriteMessage(websocket.TextMessage, packetData)
if err != nil {
s.PktCapWsConn = nil
}
}
s.PktLock.Unlock()
continue
}
s.RecvChan <- vv
cmdName := string(vv.PayloadMessage.ProtoReflect().Descriptor().FullName())
headMsg, _ := json.Marshal(vv.HeadMessage)