From 11f91dfee3eeb7445be8680e0e59ef84f2cad2f5 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 3 Dec 2025 08:16:56 +0000 Subject: [PATCH] Disable AMSI content logging in release (#26235) --- .../engine/runtime/Operations/MiscOps.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs index 50054f6501..d584666ab6 100644 --- a/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs +++ b/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs @@ -3644,6 +3644,7 @@ namespace System.Management.Automation internal static class MemberInvocationLoggingOps { +#if DEBUG private static readonly Lazy DumpLogAMSIContent = new Lazy( () => { object result = Environment.GetEnvironmentVariable("__PSDumpAMSILogContent"); @@ -3654,6 +3655,7 @@ namespace System.Management.Automation return false; } ); +#endif private static string ArgumentToString(object arg) { @@ -3708,20 +3710,24 @@ namespace System.Management.Automation string content = $"<{targetName}>.{name}({argsBuilder})"; +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine("\n=== Amsi notification report content ==="); Console.WriteLine(content); } +#endif var success = AmsiUtils.ReportContent( name: contentName, content: content); +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine($"=== Amsi notification report success: {success} ==="); } +#endif } catch (PSSecurityException) { @@ -3729,12 +3735,16 @@ namespace System.Management.Automation // must be propagated. throw; } +#pragma warning disable CS0168 // variable declared but never used catch (Exception ex) +#pragma warning restore CS0168 { +#if DEBUG if (DumpLogAMSIContent.Value) { Console.WriteLine($"!!! Amsi notification report exception: {ex} !!!"); } +#endif } } }