From f26ea32073d6739ee63ade182b45e7f3257ff4a2 Mon Sep 17 00:00:00 2001 From: Sehkah Date: Sun, 5 May 2024 00:22:41 +0200 Subject: [PATCH 1/2] Add support for packet ID / name filtering to the packet command. --- Arrowgene.Ddon.Cli/Command/PacketCommand.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Arrowgene.Ddon.Cli/Command/PacketCommand.cs b/Arrowgene.Ddon.Cli/Command/PacketCommand.cs index fc7d2b22e..f9ec3c24d 100644 --- a/Arrowgene.Ddon.Cli/Command/PacketCommand.cs +++ b/Arrowgene.Ddon.Cli/Command/PacketCommand.cs @@ -23,9 +23,10 @@ public class PacketCommand : ICommand private static string ByteDumpPrefixSwitch => "--byte-dump-prefix"; private static string Utf8StringDumpSwitch => "--utf8-dump"; private static string StructureDumpSwitch => "--structure-dump"; + private static string PacketIncludeFilterSwitch => "--packet-include-filter"; public string Description => - $"Usage: `{Key} \"E:\\dumps\\58_9.yaml` [{DecryptionKeySwitch}=]J2g4pE2_heyqIAengWy0N6D1SEklxz8I [{ByteDumpSwitch}[=,]] [{ByteDumpPrefixSwitch}=0x] [{Utf8StringDumpSwitch}] [{StructureDumpSwitch}[=JSON|YAML]]"; + $"Usage: `{Key} \"E:\\dumps\\58_9.yaml` [{DecryptionKeySwitch}=]J2g4pE2_heyqIAengWy0N6D1SEklxz8I [{ByteDumpSwitch}[=,]] [{ByteDumpPrefixSwitch}=0x] [{Utf8StringDumpSwitch}] [{StructureDumpSwitch}[=JSON|YAML]] [{PacketIncludeFilterSwitch}=11.21.2,S2C_QUEST_QUEST_PROGRESS_RES,...]"; public CommandResultType Run(CommandParameter parameter) @@ -41,10 +42,11 @@ public CommandResultType Run(CommandParameter parameter) bool addUtf8StringDump = parameter.Switches.Contains(Utf8StringDumpSwitch) || parameter.SwitchMap.ContainsKey(Utf8StringDumpSwitch); bool addStructureDump = parameter.Switches.Contains(StructureDumpSwitch) || parameter.SwitchMap.ContainsKey(StructureDumpSwitch); string structureDumpFormat = parameter.SwitchMap.GetValueOrDefault(StructureDumpSwitch, "JSON").ToLowerInvariant(); + string packetIncludeFilter = parameter.SwitchMap.GetValueOrDefault(PacketIncludeFilterSwitch, ""); List decryptedPcapPackets = DecryptPackets(yamlPath, camelliaKeyBytes); string annotatedDump = GetAnnotatedPacketDump(decryptedPcapPackets, addByteDump, addUtf8StringDump, addStructureDump, byteDumpSeparator, byteDumpPrefix, - structureDumpFormat); + structureDumpFormat, packetIncludeFilter); string outputPath = yamlPath + ".annotated.txt"; File.WriteAllText(outputPath, annotatedDump); @@ -108,14 +110,20 @@ public List DecryptPackets(List pcapPackets, byte[] came } public string GetAnnotatedPacketDump(List decryptedPcapPackets, bool addByteDump, bool addUtf8ByteDump, bool addStructureDump, string byteDumpSeparator = "", - string byteDumpPrefix = "", string structureDumpFormat = "") + string byteDumpPrefix = "", string structureDumpFormat = "", string packetIncludeFilter = "") { + HashSet packetIncludeFilterSet = new HashSet(packetIncludeFilter.ToLowerInvariant().Split(',')); StringBuilder annotated = new StringBuilder(); { foreach (PcapPacket pcapPacket in decryptedPcapPackets) { foreach (IPacket resolvedPacket in pcapPacket.ResolvedPackets) { + if (!(packetIncludeFilterSet.Contains(resolvedPacket.Id.Name.ToLowerInvariant()) || packetIncludeFilterSet.Contains(resolvedPacket.Id.ToString()))) + { + continue; + } + annotated.AppendLine($"{resolvedPacket.PrintHeader()} Pcap(No:{pcapPacket.Packet} Ts:{pcapPacket.TimeStamp})"); annotated.Append(resolvedPacket.PrintData()); if (addStructureDump && resolvedPacket is IStructurePacket) From db52e12400793f204283d266040b722df57741a4 Mon Sep 17 00:00:00 2001 From: Sehkah Date: Thu, 9 May 2024 20:33:25 +0200 Subject: [PATCH 2/2] Only activate packet filter when it's not empty. --- Arrowgene.Ddon.Cli/Command/PacketCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arrowgene.Ddon.Cli/Command/PacketCommand.cs b/Arrowgene.Ddon.Cli/Command/PacketCommand.cs index f9ec3c24d..fcaf18c15 100644 --- a/Arrowgene.Ddon.Cli/Command/PacketCommand.cs +++ b/Arrowgene.Ddon.Cli/Command/PacketCommand.cs @@ -119,7 +119,7 @@ public string GetAnnotatedPacketDump(List decryptedPcapPackets, bool { foreach (IPacket resolvedPacket in pcapPacket.ResolvedPackets) { - if (!(packetIncludeFilterSet.Contains(resolvedPacket.Id.Name.ToLowerInvariant()) || packetIncludeFilterSet.Contains(resolvedPacket.Id.ToString()))) + if (packetIncludeFilter != "" && !packetIncludeFilterSet.Contains(resolvedPacket.Id.Name.ToLowerInvariant()) && !packetIncludeFilterSet.Contains(resolvedPacket.Id.ToString())) { continue; }