1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-06-18 21:45:04 +08:00

fix(jce): replacment not equivalent

This commit is contained in:
fumiama 2021-12-09 22:47:16 +08:00
parent b041fc20e8
commit f1d2259956
3 changed files with 109 additions and 109 deletions

View File

@ -80,13 +80,13 @@ func writeObject(w io.Writer, v reflect.Value, tag byte, name string) {
}
switch k {
case reflect.Uint8, reflect.Int8:
w.Write([]byte(fmt.Sprintf("\tw.WriteByte(byte(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteByte(pkt.%s, %d)\n", name, tag)))
case reflect.Uint16, reflect.Int16:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt16(int16(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt16(pkt.%s, %d)\n", name, tag)))
case reflect.Uint32, reflect.Int32:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt32(int32(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt32(pkt.%s, %d)\n", name, tag)))
case reflect.Uint64, reflect.Int64:
w.Write([]byte(fmt.Sprintf("\tw.WriteInt64(int64(pkt.%s), %d)\n", name, tag)))
w.Write([]byte(fmt.Sprintf("\tw.WriteInt64(pkt.%s, %d)\n", name, tag)))
case reflect.String:
w.Write([]byte(fmt.Sprintf("\tw.WriteString(pkt.%s, %d)\n", name, tag)))
default:
@ -148,9 +148,9 @@ func writeJceStructRaw(w io.Writer, s interface{}) {
}
func WriteJceStruct(w io.Writer, s jce.IJceStruct) {
w.Write([]byte(fmt.Sprintf("func (pkt %s) ToBytes() []byte {\n", strings.ReplaceAll(reflect.TypeOf(s).String(), "jce.", ""))))
w.Write([]byte(fmt.Sprintf("\nfunc (pkt %s) ToBytes() []byte {\n", strings.ReplaceAll(reflect.TypeOf(s).String(), "jce.", ""))))
w.Write([]byte("\tw := NewJceWriter()\n"))
writeJceStructRaw(w, s)
w.Write([]byte("\treturn w.Bytes()\n"))
w.Write([]byte("}\n\n"))
w.Write([]byte("}\n"))
}

View File

@ -2,16 +2,17 @@
package jce
func (pkt *RequestPacket) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt16(int16(pkt.IVersion), 1)
w.WriteByte(byte(pkt.CPacketType), 2)
w.WriteInt32(int32(pkt.IMessageType), 3)
w.WriteInt32(int32(pkt.IRequestId), 4)
w.WriteInt16(pkt.IVersion, 1)
w.WriteByte(pkt.CPacketType, 2)
w.WriteInt32(pkt.IMessageType, 3)
w.WriteInt32(pkt.IRequestId, 4)
w.WriteString(pkt.SServantName, 5)
w.WriteString(pkt.SFuncName, 6)
w.WriteBytes(pkt.SBuffer, 7)
w.WriteInt32(int32(pkt.ITimeout), 8)
w.WriteInt32(pkt.ITimeout, 8)
w.writeMapStrStr(pkt.Context, 9)
w.writeMapStrStr(pkt.Status, 10)
return w.Bytes()
@ -31,65 +32,65 @@ func (pkt *RequestDataVersion2) ToBytes() []byte {
func (pkt *SvcReqRegister) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteInt64(int64(pkt.Bid), 1)
w.WriteByte(byte(pkt.ConnType), 2)
w.WriteInt64(pkt.Uin, 0)
w.WriteInt64(pkt.Bid, 1)
w.WriteByte(pkt.ConnType, 2)
w.WriteString(pkt.Other, 3)
w.WriteInt32(int32(pkt.Status), 4)
w.WriteByte(byte(pkt.OnlinePush), 5)
w.WriteByte(byte(pkt.IsOnline), 6)
w.WriteByte(byte(pkt.IsShowOnline), 7)
w.WriteByte(byte(pkt.KickPC), 8)
w.WriteByte(byte(pkt.KickWeak), 9)
w.WriteInt64(int64(pkt.Timestamp), 10)
w.WriteInt64(int64(pkt.IOSVersion), 11)
w.WriteByte(byte(pkt.NetType), 12)
w.WriteInt32(pkt.Status, 4)
w.WriteByte(pkt.OnlinePush, 5)
w.WriteByte(pkt.IsOnline, 6)
w.WriteByte(pkt.IsShowOnline, 7)
w.WriteByte(pkt.KickPC, 8)
w.WriteByte(pkt.KickWeak, 9)
w.WriteInt64(pkt.Timestamp, 10)
w.WriteInt64(pkt.IOSVersion, 11)
w.WriteByte(pkt.NetType, 12)
w.WriteString(pkt.BuildVer, 13)
w.WriteByte(byte(pkt.RegType), 14)
w.WriteByte(pkt.RegType, 14)
w.WriteBytes(pkt.DevParam, 15)
w.WriteBytes(pkt.Guid, 16)
w.WriteInt32(int32(pkt.LocaleId), 17)
w.WriteByte(byte(pkt.SilentPush), 18)
w.WriteInt32(pkt.LocaleId, 17)
w.WriteByte(pkt.SilentPush, 18)
w.WriteString(pkt.DevName, 19)
w.WriteString(pkt.DevType, 20)
w.WriteString(pkt.OSVer, 21)
w.WriteByte(byte(pkt.OpenPush), 22)
w.WriteInt64(int64(pkt.LargeSeq), 23)
w.WriteInt64(int64(pkt.LastWatchStartTime), 24)
w.WriteInt64(int64(pkt.OldSSOIp), 26)
w.WriteInt64(int64(pkt.NewSSOIp), 27)
w.WriteByte(pkt.OpenPush, 22)
w.WriteInt64(pkt.LargeSeq, 23)
w.WriteInt64(pkt.LastWatchStartTime, 24)
w.WriteInt64(pkt.OldSSOIp, 26)
w.WriteInt64(pkt.NewSSOIp, 27)
w.WriteString(pkt.ChannelNo, 28)
w.WriteInt64(int64(pkt.CPID), 29)
w.WriteInt64(pkt.CPID, 29)
w.WriteString(pkt.VendorName, 30)
w.WriteString(pkt.VendorOSName, 31)
w.WriteString(pkt.IOSIdfa, 32)
w.WriteBytes(pkt.B769, 33)
w.WriteByte(byte(pkt.IsSetStatus), 34)
w.WriteByte(pkt.IsSetStatus, 34)
w.WriteBytes(pkt.ServerBuf, 35)
w.WriteByte(byte(pkt.SetMute), 36)
w.WriteInt64(int64(pkt.ExtOnlineStatus), 38)
w.WriteInt32(int32(pkt.BatteryStatus), 39)
w.WriteByte(pkt.SetMute, 36)
w.WriteInt64(pkt.ExtOnlineStatus, 38)
w.WriteInt32(pkt.BatteryStatus, 39)
return w.Bytes()
}
func (pkt *FriendListRequest) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt32(int32(pkt.Reqtype), 0)
w.WriteByte(byte(pkt.IfReflush), 1)
w.WriteInt64(int64(pkt.Uin), 2)
w.WriteInt16(int16(pkt.StartIndex), 3)
w.WriteInt16(int16(pkt.FriendCount), 4)
w.WriteByte(byte(pkt.GroupId), 5)
w.WriteByte(byte(pkt.IfGetGroupInfo), 6)
w.WriteByte(byte(pkt.GroupStartIndex), 7)
w.WriteByte(byte(pkt.GroupCount), 8)
w.WriteByte(byte(pkt.IfGetMSFGroup), 9)
w.WriteByte(byte(pkt.IfShowTermType), 10)
w.WriteInt64(int64(pkt.Version), 11)
w.WriteInt32(pkt.Reqtype, 0)
w.WriteByte(pkt.IfReflush, 1)
w.WriteInt64(pkt.Uin, 2)
w.WriteInt16(pkt.StartIndex, 3)
w.WriteInt16(pkt.FriendCount, 4)
w.WriteByte(pkt.GroupId, 5)
w.WriteByte(pkt.IfGetGroupInfo, 6)
w.WriteByte(pkt.GroupStartIndex, 7)
w.WriteByte(pkt.GroupCount, 8)
w.WriteByte(pkt.IfGetMSFGroup, 9)
w.WriteByte(pkt.IfShowTermType, 10)
w.WriteInt64(pkt.Version, 11)
w.WriteInt64Slice(pkt.UinList, 12)
w.WriteInt32(int32(pkt.AppType), 13)
w.WriteByte(byte(pkt.IfGetDOVId), 14)
w.WriteByte(byte(pkt.IfGetBothFlag), 15)
w.WriteInt32(pkt.AppType, 13)
w.WriteByte(pkt.IfGetDOVId, 14)
w.WriteByte(pkt.IfGetBothFlag, 15)
w.WriteBytes(pkt.D50, 16)
w.WriteBytes(pkt.D6B, 17)
w.WriteInt64Slice(pkt.SnsTypeList, 18)
@ -98,22 +99,22 @@ func (pkt *FriendListRequest) ToBytes() []byte {
func (pkt *SummaryCardReq) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteInt32(int32(pkt.ComeFrom), 1)
w.WriteInt64(int64(pkt.QzoneFeedTimestamp), 2)
w.WriteByte(byte(pkt.IsFriend), 3)
w.WriteInt64(int64(pkt.GroupCode), 4)
w.WriteInt64(int64(pkt.GroupUin), 5)
w.WriteInt64(int64(pkt.GetControl), 8)
w.WriteInt32(int32(pkt.AddFriendSource), 9)
w.WriteInt64(pkt.Uin, 0)
w.WriteInt32(pkt.ComeFrom, 1)
w.WriteInt64(pkt.QzoneFeedTimestamp, 2)
w.WriteByte(pkt.IsFriend, 3)
w.WriteInt64(pkt.GroupCode, 4)
w.WriteInt64(pkt.GroupUin, 5)
w.WriteInt64(pkt.GetControl, 8)
w.WriteInt32(pkt.AddFriendSource, 9)
w.WriteBytes(pkt.SecureSig, 10)
w.WriteBytesSlice(pkt.ReqServices, 14)
w.WriteInt64(int64(pkt.TinyId), 15)
w.WriteInt64(int64(pkt.LikeSource), 16)
w.WriteByte(byte(pkt.ReqMedalWallInfo), 18)
w.WriteInt64(pkt.TinyId, 15)
w.WriteInt64(pkt.LikeSource, 16)
w.WriteByte(pkt.ReqMedalWallInfo, 18)
w.WriteInt64Slice(pkt.Req0x5ebFieldId, 19)
w.WriteByte(byte(pkt.ReqNearbyGodInfo), 20)
w.WriteByte(byte(pkt.ReqExtendCard), 22)
w.WriteByte(pkt.ReqNearbyGodInfo, 20)
w.WriteByte(pkt.ReqExtendCard, 22)
return w.Bytes()
}
@ -121,53 +122,53 @@ func (pkt *SummaryCardReqSearch) ToBytes() []byte {
w := NewJceWriter()
w.WriteString(pkt.Keyword, 0)
w.WriteString(pkt.CountryCode, 1)
w.WriteInt32(int32(pkt.Version), 2)
w.WriteInt32(pkt.Version, 2)
w.WriteBytesSlice(pkt.ReqServices, 3)
return w.Bytes()
}
func (pkt *TroopListRequest) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteByte(byte(pkt.GetMSFMsgFlag), 1)
w.WriteInt64(pkt.Uin, 0)
w.WriteByte(pkt.GetMSFMsgFlag, 1)
w.WriteBytes(pkt.Cookies, 2)
w.WriteInt64Slice(pkt.GroupInfo, 3)
w.WriteByte(byte(pkt.GroupFlagExt), 4)
w.WriteInt32(int32(pkt.Version), 5)
w.WriteInt64(int64(pkt.CompanyId), 6)
w.WriteInt64(int64(pkt.VersionNum), 7)
w.WriteByte(byte(pkt.GetLongGroupName), 8)
w.WriteByte(pkt.GroupFlagExt, 4)
w.WriteInt32(pkt.Version, 5)
w.WriteInt64(pkt.CompanyId, 6)
w.WriteInt64(pkt.VersionNum, 7)
w.WriteByte(pkt.GetLongGroupName, 8)
return w.Bytes()
}
func (pkt *TroopMemberListRequest) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteInt64(int64(pkt.GroupCode), 1)
w.WriteInt64(int64(pkt.NextUin), 2)
w.WriteInt64(int64(pkt.GroupUin), 3)
w.WriteInt64(int64(pkt.Version), 4)
w.WriteInt64(int64(pkt.ReqType), 5)
w.WriteInt64(int64(pkt.GetListAppointTime), 6)
w.WriteByte(byte(pkt.RichCardNameVer), 7)
w.WriteInt64(pkt.Uin, 0)
w.WriteInt64(pkt.GroupCode, 1)
w.WriteInt64(pkt.NextUin, 2)
w.WriteInt64(pkt.GroupUin, 3)
w.WriteInt64(pkt.Version, 4)
w.WriteInt64(pkt.ReqType, 5)
w.WriteInt64(pkt.GetListAppointTime, 6)
w.WriteByte(pkt.RichCardNameVer, 7)
return w.Bytes()
}
func (pkt *SvcRespPushMsg) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteInt64(pkt.Uin, 0)
w.WriteJceStructSlice(pkt.DelInfos, 1)
w.WriteInt32(int32(pkt.Svrip), 2)
w.WriteInt32(pkt.Svrip, 2)
w.WriteBytes(pkt.PushToken, 3)
w.WriteInt32(int32(pkt.ServiceType), 4)
w.WriteInt32(pkt.ServiceType, 4)
return w.Bytes()
}
func (pkt *ModifyGroupCardRequest) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Zero), 0)
w.WriteInt64(int64(pkt.GroupCode), 1)
w.WriteInt64(int64(pkt.NewSeq), 2)
w.WriteInt64(pkt.Zero, 0)
w.WriteInt64(pkt.GroupCode, 1)
w.WriteInt64(pkt.NewSeq, 2)
w.WriteJceStructSlice(pkt.UinInfo, 3)
return w.Bytes()
}
@ -176,30 +177,29 @@ func (pkt *SvcReqGetDevLoginInfo) ToBytes() []byte {
w := NewJceWriter()
w.WriteBytes(pkt.Guid, 0)
w.WriteString(pkt.AppName, 1)
w.WriteInt64(int64(pkt.LoginType), 2)
w.WriteInt64(int64(pkt.Timestamp), 3)
w.WriteInt64(int64(pkt.NextItemIndex), 4)
w.WriteInt64(int64(pkt.RequireMax), 5)
w.WriteInt64(int64(pkt.GetDevListType), 6)
w.WriteInt64(pkt.LoginType, 2)
w.WriteInt64(pkt.Timestamp, 3)
w.WriteInt64(pkt.NextItemIndex, 4)
w.WriteInt64(pkt.RequireMax, 5)
w.WriteInt64(pkt.GetDevListType, 6)
return w.Bytes()
}
func (pkt *SvcReqRegisterNew) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.RequestOptional), 0)
w.WriteByte(byte(pkt.DisGroupMsgFilter), 14)
w.WriteByte(byte(pkt.GroupMask), 15)
w.WriteInt64(int64(pkt.EndSeq), 16)
w.WriteInt64(pkt.RequestOptional, 0)
w.WriteByte(pkt.DisGroupMsgFilter, 14)
w.WriteByte(pkt.GroupMask, 15)
w.WriteInt64(pkt.EndSeq, 16)
w.WriteBytes(pkt.O769Body, 20)
return w.Bytes()
}
func (pkt *DelFriendReq) ToBytes() []byte {
w := NewJceWriter()
w.WriteInt64(int64(pkt.Uin), 0)
w.WriteInt64(int64(pkt.DelUin), 1)
w.WriteByte(byte(pkt.DelType), 2)
w.WriteInt32(int32(pkt.Version), 3)
w.WriteInt64(pkt.Uin, 0)
w.WriteInt64(pkt.DelUin, 1)
w.WriteByte(pkt.DelType, 2)
w.WriteInt32(pkt.Version, 3)
return w.Bytes()
}

View File

@ -19,7 +19,7 @@ func NewJceWriter() *JceWriter {
func (w *JceWriter) writeHead(t, tag byte) {
if tag < 0xF {
w.buf.WriteByte(byte(tag<<4) | t)
w.buf.WriteByte(tag<<4 | t)
} else {
w.buf.WriteByte(0xF0 | t)
w.buf.WriteByte(tag)
@ -145,7 +145,7 @@ func (w *JceWriter) WriteBytes(l []byte, tag byte) *JceWriter {
func (w *JceWriter) WriteInt64Slice(l []int64, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
@ -157,7 +157,7 @@ func (w *JceWriter) WriteInt64Slice(l []int64, tag byte) {
func (w *JceWriter) WriteBytesSlice(l [][]byte, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
@ -180,7 +180,7 @@ func (w *JceWriter) writeSlice(slice reflect.Value, tag byte) {
}
w.writeHead(9, tag)
if slice.Len() == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(slice.Len()), 0)
@ -193,7 +193,7 @@ func (w *JceWriter) writeSlice(slice reflect.Value, tag byte) {
func (w *JceWriter) WriteJceStructSlice(l []IJceStruct, tag byte) {
w.writeHead(9, tag)
if len(l) == 0 {
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.WriteInt32(int32(len(l)), 0)
@ -213,7 +213,7 @@ func (w *JceWriter) WriteMap(m interface{}, tag byte) {
func (w *JceWriter) writeMap(m reflect.Value, tag byte) {
if m.IsNil() {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
if m.Kind() != reflect.Map {
@ -231,7 +231,7 @@ func (w *JceWriter) writeMap(m reflect.Value, tag byte) {
func (w *JceWriter) writeMapStrStr(m map[string]string, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)
@ -245,7 +245,7 @@ func (w *JceWriter) writeMapStrStr(m map[string]string, tag byte) {
func (w *JceWriter) writeMapStrBytes(m map[string][]byte, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)
@ -259,7 +259,7 @@ func (w *JceWriter) writeMapStrBytes(m map[string][]byte, tag byte) {
func (w *JceWriter) writeMapStrMapStrBytes(m map[string]map[string][]byte, tag byte) {
if m == nil {
w.writeHead(8, tag)
w.buf.WriteByte(0) // w.WriteInt32(0, 0)
w.writeHead(12, 0) // w.WriteInt32(0, 0)
return
}
w.writeHead(8, tag)