prevent reading past message board packet

This commit is contained in:
wish
2023-04-10 18:52:12 +10:00
parent b0d53431c0
commit 4ffb176049
2 changed files with 44 additions and 34 deletions

View File

@@ -2,6 +2,7 @@ package mhfpacket
import (
"errors"
"erupe-ce/common/stringsupport"
"erupe-ce/common/byteframe"
"erupe-ce/network"
@@ -10,9 +11,16 @@ import (
// MsgMhfUpdateGuildMessageBoard represents the MSG_MHF_UPDATE_GUILD_MESSAGE_BOARD
type MsgMhfUpdateGuildMessageBoard struct {
AckHandle uint32
MessageOp uint32
Request []byte
AckHandle uint32
MessageOp uint32
PostType uint32
StampID uint32
TitleLength uint32
BodyLength uint32
Title string
Body string
PostID uint32
LikeState bool
}
// Opcode returns the ID associated with this packet type.
@@ -24,9 +32,31 @@ func (m *MsgMhfUpdateGuildMessageBoard) Opcode() network.PacketID {
func (m *MsgMhfUpdateGuildMessageBoard) Parse(bf *byteframe.ByteFrame, ctx *clientctx.ClientContext) error {
m.AckHandle = bf.ReadUint32()
m.MessageOp = bf.ReadUint32()
if m.MessageOp != 5 {
m.Request = bf.DataFromCurrent()
bf.Seek(int64(len(bf.Data())-2), 0)
switch m.MessageOp {
case 0:
m.PostType = bf.ReadUint32()
m.StampID = bf.ReadUint32()
m.TitleLength = bf.ReadUint32()
m.BodyLength = bf.ReadUint32()
m.Title = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
m.Body = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
case 1:
m.PostID = bf.ReadUint32()
case 2:
m.PostID = bf.ReadUint32()
bf.ReadBytes(8)
m.TitleLength = bf.ReadUint32()
m.BodyLength = bf.ReadUint32()
m.Title = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.TitleLength)))
m.Body = stringsupport.SJISToUTF8(bf.ReadBytes(uint(m.BodyLength)))
case 3:
m.PostID = bf.ReadUint32()
bf.ReadBytes(8)
m.StampID = bf.ReadUint32()
case 4:
m.PostID = bf.ReadUint32()
bf.ReadBytes(8)
m.LikeState = bf.ReadBool()
}
return nil
}