~ruther/NosSmooth

b91870a525340f7604b92910f2d3dd2559930b53 — Rutherther 2 years ago 55d4c9a
feat(pcap): try to guess packet is world packet if no encryption key is detected
1 files changed, 20 insertions(+), 1 deletions(-)

M Pcap/NosSmooth.Pcap/PcapNostaleClient.cs
M Pcap/NosSmooth.Pcap/PcapNostaleClient.cs => Pcap/NosSmooth.Pcap/PcapNostaleClient.cs +20 -1
@@ 190,6 190,9 @@ public class PcapNostaleClient : BaseNostaleClient
    /// <param name="payloadData">The raw payload data of the packet.</param>
    internal void OnPacketArrival(LibPcapLiveDevice? device, TcpConnection connection, byte[] payloadData)
    {
        // TODO: cleanup this method, split it into multiple methods
        // TODO: make it more effective, currently it uses expensive operations such as Split on strings

        _lastDevice = device;

        string data;


@@ 227,6 230,23 @@ public class PcapNostaleClient : BaseNostaleClient
            if (_crypto.EncryptionKey == 0)
            { // probably login
                data = _crypto.ClientLogin.Decrypt(payloadData, _encoding);

                var splitted = data.Split(' ');
                var header = splitted.Length > 0 ? splitted[0] : string.Empty;
                bool isPacket = true;
                foreach (var c in header)
                {
                    if (!char.IsAsciiLetterOrDigit(c) && c != '#')
                    {
                        isPacket = false;
                        break;
                    }
                }

                if (!isPacket)
                { // try world crypto?
                    data = _crypto.ClientWorld.Decrypt(payloadData, _encoding);
                }
            }
            else
            {


@@ 247,7 267,6 @@ public class PcapNostaleClient : BaseNostaleClient

                _handler.HandlePacketAsync(this, source, linePacket.Trim(), _stoppingToken ?? default);
            }

        }
    }
}
\ No newline at end of file

Do not follow this link