Add some sanity checking for stream_parser so it's less likely to pickup other protocols as an everquest protocol.

This commit is contained in:
KimLS 2024-10-26 10:03:57 -07:00
parent c1651b7dca
commit b7c93e12de
2 changed files with 34 additions and 17 deletions

View File

@ -176,6 +176,11 @@ namespace StreamParser.Common.Daybreak
case Opcode.SessionResponse:
if (_connect_code == 0)
{
if(data.Length != 21)
{
return;
}
_connect_code = BitConverter.ToUInt32(data.Slice(2, 4));
_encode_key = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data.Slice(6, 4)));
_crc_bytes = data[10];
@ -442,6 +447,8 @@ namespace StreamParser.Common.Daybreak
}
private bool ValidateCRC(ReadOnlySpan<byte> p)
{
try
{
if (_crc_bytes == 0)
{
@ -464,6 +471,10 @@ namespace StreamParser.Common.Daybreak
}
return actual == calculated;
} catch(Exception ex)
{
return false;
}
}
private byte[] Decompress(byte[] p, int offset, int length)

View File

@ -87,6 +87,12 @@ namespace StreamParser.Common.Daybreak
}
else if (data[0] == 0 && data[1] == Opcode.SessionRequest)
{
if(data.Length != 24)
{
_logger.LogTrace("Tossing packet, {0} was not the right size for a SessionRequest", data.Length);
return;
}
c = new Connection(this, srcAddr, srcPort, dstAddr, dstPort);
_connections.Add(c);
c.ProcessPacket(srcAddr, srcPort, packetTime, data);