From b91870a525340f7604b92910f2d3dd2559930b53 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Mon, 13 Feb 2023 08:44:47 +0100 Subject: [PATCH] feat(pcap): try to guess packet is world packet if no encryption key is detected --- Pcap/NosSmooth.Pcap/PcapNostaleClient.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs b/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs index 38fdf7dcab1524440c56cd5cc8e3c0cac67f02d9..e9c428f8d759f9ec7fa3fc9963b1d9931ab813d6 100644 --- a/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs +++ b/Pcap/NosSmooth.Pcap/PcapNostaleClient.cs @@ -190,6 +190,9 @@ public class PcapNostaleClient : BaseNostaleClient /// The raw payload data of the packet. 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