Implement TrafficAnalyzer utility
This commit is contained in:
parent
aedf0c0fea
commit
86ad11723b
3 changed files with 79 additions and 1 deletions
54
TrafficAnalyzer/Program.cs
Normal file
54
TrafficAnalyzer/Program.cs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
using Google.Protobuf;
|
||||||
|
using Protocol;
|
||||||
|
|
||||||
|
namespace TrafficAnalyzer;
|
||||||
|
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private const int StdInSize = 65535;
|
||||||
|
private const string ProtoAssembly = "Protocol";
|
||||||
|
private const string ProtoNamespace = "Protocol";
|
||||||
|
private const string MessageParserProperty = "Parser";
|
||||||
|
|
||||||
|
private static readonly DumpOptions s_objectDumperOpts = new() { DumpStyle = DumpStyle.CSharp, IndentSize = 4, IndentChar = ' ' };
|
||||||
|
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.SetIn(new StreamReader(Console.OpenStandardInput(StdInSize), Console.InputEncoding, false, StdInSize));
|
||||||
|
|
||||||
|
List<Tuple<int, byte[]>> inList = [];
|
||||||
|
|
||||||
|
string? idInput;
|
||||||
|
string? payloadInput;
|
||||||
|
|
||||||
|
while (!string.IsNullOrEmpty(idInput = Console.ReadLine()) && !string.IsNullOrEmpty(payloadInput = Console.ReadLine()))
|
||||||
|
{
|
||||||
|
int messageId = int.Parse(idInput);
|
||||||
|
byte[] payload = Convert.FromHexString(payloadInput);
|
||||||
|
|
||||||
|
inList.Add(Tuple.Create(messageId, payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
foreach ((int messageId, byte[] payload) in inList)
|
||||||
|
{
|
||||||
|
string messageName = ((MessageId)messageId).ToString();
|
||||||
|
|
||||||
|
Type? type = Type.GetType($"{ProtoNamespace}.{messageName},{ProtoAssembly}");
|
||||||
|
if (type is null)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Message with id {messageName} wasn't found in proto definition.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageParser parser = (MessageParser)type.GetProperty(MessageParserProperty)!.GetValue(null)!;
|
||||||
|
IMessage message = parser.ParseFrom(payload);
|
||||||
|
|
||||||
|
string outputInitializer = ObjectDumper.Dump(message, s_objectDumperOpts);
|
||||||
|
|
||||||
|
Console.WriteLine($"Message: {messageName}");
|
||||||
|
Console.WriteLine(outputInitializer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
TrafficAnalyzer/TrafficAnalyzer.csproj
Normal file
18
TrafficAnalyzer/TrafficAnalyzer.csproj
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="ObjectDumper.NET" Version="4.1.15" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Protocol\Protocol.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -16,7 +16,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KcpSharp", "KcpSharp\KcpSha
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocol", "Protocol\Protocol.csproj", "{9900A88C-7818-4335-84F7-1538ECC8B338}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Protocol", "Protocol\Protocol.csproj", "{9900A88C-7818-4335-84F7-1538ECC8B338}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{C025BDED-6DC7-493D-8D10-05DCCB3072F3}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{C025BDED-6DC7-493D-8D10-05DCCB3072F3}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrafficAnalyzer", "TrafficAnalyzer\TrafficAnalyzer.csproj", "{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -44,6 +46,10 @@ Global
|
||||||
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C025BDED-6DC7-493D-8D10-05DCCB3072F3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7DA57BA1-215F-4DD8-86A9-CAC62908A6F3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
Loading…
Reference in a new issue