From 70b087bf8d2b2f05f440d5d22af395d5fa83a9e4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 5 Mar 2020 00:21:27 +0100 Subject: [PATCH] #1942: WholeProjectDecompiler: Do not use filenames that collide with names of special devices. Note: this changes the PDB structure from multi-level folders per namespace to "dotted name" folders. --- .../CSharp/WholeProjectDecompiler.cs | 36 ++++++++++++++++++- .../DebugInfo/PortablePdbWriter.cs | 3 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs index 23cce2661..74409be17 100644 --- a/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/WholeProjectDecompiler.cs @@ -512,7 +512,41 @@ namespace ICSharpCode.Decompiler.CSharp } if (b.Length == 0) b.Append('-'); - return b.ToString(); + string name = b.ToString(); + if (IsReservedFileSystemName(name)) + return name + "_"; + return name; + } + + static bool IsReservedFileSystemName(string name) + { + switch (name.ToUpperInvariant()) { + case "AUX": + case "COM1": + case "COM2": + case "COM3": + case "COM4": + case "COM5": + case "COM6": + case "COM7": + case "COM8": + case "COM9": + case "CON": + case "LPT1": + case "LPT2": + case "LPT3": + case "LPT4": + case "LPT5": + case "LPT6": + case "LPT7": + case "LPT8": + case "LPT9": + case "NUL": + case "PRN": + return true; + default: + return false; + } } public static string GetPlatformName(Metadata.PEFile module) diff --git a/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs b/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs index a329bcfbf..7a2ae24cd 100644 --- a/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs +++ b/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs @@ -84,7 +84,8 @@ namespace ICSharpCode.Decompiler.DebugInfo lock (metadata) { var sourceBlob = WriteSourceToBlob(metadata, sourceText, out var sourceCheckSum); - var name = metadata.GetOrAddDocumentName(type.GetFullTypeName(reader).ReflectionName.Replace('.', Path.DirectorySeparatorChar) + ".cs"); + var typeName = type.GetFullTypeName(reader).TopLevelTypeName; + var name = metadata.GetOrAddDocumentName(Path.Combine(WholeProjectDecompiler.CleanUpFileName(typeName.Namespace), WholeProjectDecompiler.CleanUpFileName(typeName.Name) + ".cs")); // Create Document(Handle) var document = metadata.AddDocument(name,