From 253983430d7de09e0db9d736f7702e784718b693 Mon Sep 17 00:00:00 2001 From: Xpl0itR Date: Tue, 2 May 2023 18:23:30 +0100 Subject: [PATCH] bugfixes --- Program.cs | 8 ++++---- Protodec.cs | 13 +++++++------ README.md | 10 +++++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Program.cs b/Program.cs index 85ab0bf..c713806 100644 --- a/Program.cs +++ b/Program.cs @@ -6,13 +6,13 @@ using protodec; const string indent = " "; const string help = """ - Usage: protodec(.exe) [options] - Options: - --skip_enums Skip parsing enums and replace references to then with int32. - --include_runtime_assemblies Add the assemblies of the current runtime to the search path. + Usage: protodec(.exe) [options] Arguments: target_assembly_path Either a single assembly or a directory of assemblies to be parsed. out_path An existing directory to output into individual files, otherwise output to a single file. + Options: + --skip_enums Skip parsing enums and replace references to then with int32. + --include_runtime_assemblies Add the assemblies of the current runtime to the search path. """; if (args.Length < 2) diff --git a/Protodec.cs b/Protodec.cs index 4271526..8843a03 100644 --- a/Protodec.cs +++ b/Protodec.cs @@ -97,9 +97,9 @@ public sealed class Protodec else { ParseMessage(type, skipEnums); - message.Imports.Add(type.Name); } + message.Imports.Add(type.Name); return type.Name; } } @@ -107,7 +107,7 @@ public sealed class Protodec private void ParseEnum(Type enumEnum, ProtobufMessage message) { - if ((enumEnum.IsNested && message.Nested.ContainsKey(enumEnum.Name)) + if ((enumEnum.IsNested && message.Nested.ContainsKey(enumEnum.Name)) || Enums.ContainsKey(enumEnum.Name)) return; @@ -120,7 +120,7 @@ public sealed class Protodec ?.ConstructorArguments[0] .Value as string - ?? TranslateEnumFieldName(field.Name); + ?? TranslateEnumFieldName(enumEnum.Name, field.Name); protoEnum.Fields.Add(enumFieldId, enumFieldName); } @@ -131,7 +131,6 @@ public sealed class Protodec } else { - message.Imports.Add(protoEnum.Name); Enums.Add(protoEnum.Name, protoEnum); } } @@ -161,8 +160,10 @@ public sealed class Protodec name.IsBeebyted() ? name : name.ToSnakeCaseLower(); [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static string TranslateEnumFieldName(string name) => - name.IsBeebyted() ? name : name.ToSnakeCaseUpper(); + private static string TranslateEnumFieldName(string enumName, string fieldName) => + enumName.IsBeebyted() + ? enumName + '_' + fieldName.ToSnakeCaseUpper() + : (enumName + fieldName).ToSnakeCaseUpper(); private bool TryParseWriteToMethod(Type targetClass) { diff --git a/README.md b/README.md index caea989..ada96fc 100644 --- a/README.md +++ b/README.md @@ -5,14 +5,14 @@ A tool to decompile protobuf parser/serializer classes compiled by [protoc](http Usage ----- ``` -Usage: protodec(.exe) [options] -Options: - --skip_enums Skip parsing enums and replace references to then with int32. - --include_runtime_assemblies Add the assemblies of the current runtime to the search path. +Usage: protodec(.exe) [options] Arguments: target_assembly_path Either a single assembly or a directory of assemblies to be parsed. out_path An existing directory to output into individual files, otherwise output to a single file. - ``` +Options: + --skip_enums Skip parsing enums and replace references to then with int32. + --include_runtime_assemblies Add the assemblies of the current runtime to the search path. +``` Limitations -----------