From cd497c287c7a02e5a987ad922cacf8fe775ac405 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Sat, 22 Aug 2020 17:59:45 +0100 Subject: [PATCH 1/2] Run dotnet-format The following rules were disabled as they resulted in a high number of changes: ``` dotnet_sort_system_directives_first = true csharp_preserve_single_line_statements = false csharp_new_line_before_open_brace = all ``` --- .../PdhHelper.cs | 2 +- .../commands/management/Process.cs | 136 +++++++++--------- .../host/msh/ManagedEntrance.cs | 4 +- .../Eventing/UnsafeNativeMethods.cs | 56 ++++---- .../CoreCLR/CorePsAssemblyLoadContext.cs | 2 +- .../CoreCLR/CorePsPlatform.cs | 20 +-- .../engine/COM/ComDispatch.cs | 2 +- .../engine/ComInterop/ComRuntimeHelpers.cs | 2 +- .../engine/ComInterop/VariantArray.cs | 2 +- .../engine/Modules/ImportModuleCommand.cs | 4 +- .../engine/ReflectionParameterBinder.cs | 9 +- .../CommandPrediction/CommandPrediction.cs | 3 +- .../engine/remoting/fanin/WSManNativeAPI.cs | 22 +-- .../engine/remoting/fanin/WSManPlugin.cs | 8 +- .../namespaces/FileSystemProvider.cs | 2 +- .../namespaces/RegistryProvider.cs | 6 +- .../security/SecureStringHelper.cs | 24 ++-- .../security/SecurityManager.cs | 6 +- .../security/SecuritySupport.cs | 8 +- .../security/nativeMethods.cs | 2 +- .../utils/CryptoUtils.cs | 4 +- 21 files changed, 166 insertions(+), 158 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs index 130a7f41804..83c9248c7a4 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs @@ -375,7 +375,7 @@ private static extern uint PdhExpandWildCardPathH(PdhSafeDataSourceHandle hDataS private static extern uint PdhValidatePath(string szFullPathBuffer); [DllImport("pdh.dll", CharSet = CharSet.Unicode)] - private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)]bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer); + private static extern uint PdhGetCounterInfo(IntPtr hCounter, [MarshalAs(UnmanagedType.U1)] bool bRetrieveExplainText, ref IntPtr pdwBufferSize, IntPtr lpBuffer); [DllImport("pdh.dll", CharSet = CharSet.Unicode)] private static extern uint PdhGetCounterTimeBase(IntPtr hCounter, out UInt64 pTimeBase); diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index c20ef98a80d..9761489bb61 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -2350,82 +2350,82 @@ private static byte[] ConvertEnvVarsToByteArray(StringDictionary sd) private void SetStartupInfo(ProcessStartInfo startinfo, ref ProcessNativeMethods.STARTUPINFO lpStartupInfo, ref int creationFlags) { - // RedirectionStandardInput - if (_redirectstandardinput != null) - { - startinfo.RedirectStandardInput = true; - _redirectstandardinput = ResolveFilePath(_redirectstandardinput); - lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING); - } - else - { - lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false); - } + // RedirectionStandardInput + if (_redirectstandardinput != null) + { + startinfo.RedirectStandardInput = true; + _redirectstandardinput = ResolveFilePath(_redirectstandardinput); + lpStartupInfo.hStdInput = GetSafeFileHandleForRedirection(_redirectstandardinput, ProcessNativeMethods.OPEN_EXISTING); + } + else + { + lpStartupInfo.hStdInput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-10), false); + } - // RedirectionStandardOutput - if (_redirectstandardoutput != null) - { - startinfo.RedirectStandardOutput = true; - _redirectstandardoutput = ResolveFilePath(_redirectstandardoutput); - lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS); - } - else - { - lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false); - } + // RedirectionStandardOutput + if (_redirectstandardoutput != null) + { + startinfo.RedirectStandardOutput = true; + _redirectstandardoutput = ResolveFilePath(_redirectstandardoutput); + lpStartupInfo.hStdOutput = GetSafeFileHandleForRedirection(_redirectstandardoutput, ProcessNativeMethods.CREATE_ALWAYS); + } + else + { + lpStartupInfo.hStdOutput = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-11), false); + } - // RedirectionStandardError - if (_redirectstandarderror != null) - { - startinfo.RedirectStandardError = true; - _redirectstandarderror = ResolveFilePath(_redirectstandarderror); - lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS); - } - else - { - lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false); - } + // RedirectionStandardError + if (_redirectstandarderror != null) + { + startinfo.RedirectStandardError = true; + _redirectstandarderror = ResolveFilePath(_redirectstandarderror); + lpStartupInfo.hStdError = GetSafeFileHandleForRedirection(_redirectstandarderror, ProcessNativeMethods.CREATE_ALWAYS); + } + else + { + lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false); + } - // STARTF_USESTDHANDLES - lpStartupInfo.dwFlags = 0x100; + // STARTF_USESTDHANDLES + lpStartupInfo.dwFlags = 0x100; - if (startinfo.CreateNoWindow) - { - // No new window: Inherit the parent process's console window - creationFlags = 0x00000000; - } - else - { - // CREATE_NEW_CONSOLE - creationFlags |= 0x00000010; + if (startinfo.CreateNoWindow) + { + // No new window: Inherit the parent process's console window + creationFlags = 0x00000000; + } + else + { + // CREATE_NEW_CONSOLE + creationFlags |= 0x00000010; - // STARTF_USESHOWWINDOW - lpStartupInfo.dwFlags |= 0x00000001; + // STARTF_USESHOWWINDOW + lpStartupInfo.dwFlags |= 0x00000001; - // On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'. - switch (startinfo.WindowStyle) - { - case ProcessWindowStyle.Normal: - // SW_SHOWNORMAL - lpStartupInfo.wShowWindow = 1; - break; - case ProcessWindowStyle.Minimized: - // SW_SHOWMINIMIZED - lpStartupInfo.wShowWindow = 2; - break; - case ProcessWindowStyle.Maximized: - // SW_SHOWMAXIMIZED - lpStartupInfo.wShowWindow = 3; - break; - case ProcessWindowStyle.Hidden: - // SW_HIDE - lpStartupInfo.wShowWindow = 0; - break; - } + // On headless SKUs like NanoServer and IoT, window style can only be the default value 'Normal'. + switch (startinfo.WindowStyle) + { + case ProcessWindowStyle.Normal: + // SW_SHOWNORMAL + lpStartupInfo.wShowWindow = 1; + break; + case ProcessWindowStyle.Minimized: + // SW_SHOWMINIMIZED + lpStartupInfo.wShowWindow = 2; + break; + case ProcessWindowStyle.Maximized: + // SW_SHOWMAXIMIZED + lpStartupInfo.wShowWindow = 3; + break; + case ProcessWindowStyle.Hidden: + // SW_HIDE + lpStartupInfo.wShowWindow = 0; + break; } + } - // Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly. - creationFlags |= 0x00000004; + // Create the new process suspended so we have a chance to get a corresponding Process object in case it terminates quickly. + creationFlags |= 0x00000004; } /// diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs index d0ee497307a..6dbc21ab242 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs @@ -33,7 +33,7 @@ public sealed class UnmanagedPSEntry /// Length of the passed in argument array. /// [Obsolete("Callers should now use UnmanagedPSEntry.Start(string[], int)", error: true)] - public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)]string[] args, int argc) + public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] string[] args, int argc) { return Start(args, argc); } @@ -47,7 +47,7 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray /// /// Length of the passed in argument array. /// - public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)]string[] args, int argc) + public static int Start([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 1)] string[] args, int argc) { if (args == null) { diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs index 5da8809897d..abc1bb03335 100644 --- a/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs +++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/UnsafeNativeMethods.cs @@ -121,9 +121,9 @@ [In] void* callbackContext [SecurityCritical] internal static extern unsafe uint EventRegister( [In] ref Guid providerId, - [In]EtwEnableCallback enableCallback, - [In]void* callbackContext, - [In][Out]ref long registrationHandle + [In] EtwEnableCallback enableCallback, + [In] void* callbackContext, + [In][Out] ref long registrationHandle ); [DllImport(EventProviderDllName, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)] @@ -553,8 +553,8 @@ internal enum EvtSeekFlags [SecurityCritical] internal static extern EventLogHandle EvtQuery( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string path, - [MarshalAs(UnmanagedType.LPWStr)]string query, + [MarshalAs(UnmanagedType.LPWStr)] string path, + [MarshalAs(UnmanagedType.LPWStr)] string query, int flags); // SEEK @@ -566,7 +566,7 @@ internal static extern bool EvtSeek( long position, EventLogHandle bookmark, int timeout, - [MarshalAs(UnmanagedType.I4)]EvtSeekFlags flags + [MarshalAs(UnmanagedType.I4)] EvtSeekFlags flags ); [DllImport(WEVTAPI, CallingConvention = CallingConvention.Winapi, SetLastError = true)] @@ -603,7 +603,7 @@ IntPtr eventHandle internal static extern bool EvtGetEventInfo( EventLogHandle eventHandle, // int propertyId - [MarshalAs(UnmanagedType.I4)]EvtEventPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtEventPropertyId propertyId, int bufferSize, IntPtr bufferPtr, out int bufferUsed @@ -614,7 +614,7 @@ out int bufferUsed [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetQueryInfo( EventLogHandle queryHandle, - [MarshalAs(UnmanagedType.I4)]EvtQueryPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtQueryPropertyId propertyId, int bufferSize, IntPtr buffer, ref int bufferRequired @@ -686,7 +686,7 @@ int flags [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetEventMetadataProperty( EventLogHandle eventMetadata, - [MarshalAs(UnmanagedType.I4)] EvtEventMetadataPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtEventMetadataPropertyId propertyId, int flags, int eventMetadataPropertyBufferSize, IntPtr eventMetadataPropertyBuffer, @@ -708,7 +708,7 @@ internal static extern bool EvtNextChannelPath( EventLogHandle channelEnum, int channelPathBufferSize, // StringBuilder channelPathBuffer, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder channelPathBuffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder channelPathBuffer, out int channelPathBufferUsed ); @@ -725,7 +725,7 @@ int flags internal static extern bool EvtNextPublisherId( EventLogHandle publisherEnum, int publisherIdBufferSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder publisherIdBuffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder publisherIdBuffer, out int publisherIdBufferUsed ); @@ -733,7 +733,7 @@ out int publisherIdBufferUsed [SecurityCritical] internal static extern EventLogHandle EvtOpenChannelConfig( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]String channelPath, + [MarshalAs(UnmanagedType.LPWStr)] String channelPath, int flags ); @@ -750,7 +750,7 @@ int flags [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtSetChannelConfigProperty( EventLogHandle channelConfig, - [MarshalAs(UnmanagedType.I4)]EvtChannelConfigPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtChannelConfigPropertyId propertyId, int flags, ref EvtVariant propertyValue ); @@ -760,7 +760,7 @@ ref EvtVariant propertyValue [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetChannelConfigProperty( EventLogHandle channelConfig, - [MarshalAs(UnmanagedType.I4)]EvtChannelConfigPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtChannelConfigPropertyId propertyId, int flags, int propertyValueBufferSize, IntPtr propertyValueBuffer, @@ -773,7 +773,7 @@ out int propertyValueBufferUsed internal static extern EventLogHandle EvtOpenLog( EventLogHandle session, [MarshalAs(UnmanagedType.LPWStr)] string path, - [MarshalAs(UnmanagedType.I4)]PathType flags + [MarshalAs(UnmanagedType.I4)] PathType flags ); [DllImport(WEVTAPI, CharSet = CharSet.Unicode, SetLastError = true)] @@ -781,7 +781,7 @@ internal static extern EventLogHandle EvtOpenLog( [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtGetLogInfo( EventLogHandle log, - [MarshalAs(UnmanagedType.I4)]EvtLogPropertyId propertyId, + [MarshalAs(UnmanagedType.I4)] EvtLogPropertyId propertyId, int propertyValueBufferSize, IntPtr propertyValueBuffer, out int propertyValueBufferUsed @@ -793,9 +793,9 @@ out int propertyValueBufferUsed [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtExportLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string channelPath, - [MarshalAs(UnmanagedType.LPWStr)]string query, - [MarshalAs(UnmanagedType.LPWStr)]string targetFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string channelPath, + [MarshalAs(UnmanagedType.LPWStr)] string query, + [MarshalAs(UnmanagedType.LPWStr)] string targetFilePath, int flags ); @@ -804,7 +804,7 @@ int flags [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtArchiveExportedLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string logFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string logFilePath, int locale, int flags ); @@ -814,8 +814,8 @@ int flags [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EvtClearLog( EventLogHandle session, - [MarshalAs(UnmanagedType.LPWStr)]string channelPath, - [MarshalAs(UnmanagedType.LPWStr)]string targetFilePath, + [MarshalAs(UnmanagedType.LPWStr)] string channelPath, + [MarshalAs(UnmanagedType.LPWStr)] string targetFilePath, int flags ); @@ -826,7 +826,7 @@ internal static extern EventLogHandle EvtCreateRenderContext( Int32 valuePathsCount, [MarshalAs(UnmanagedType.LPArray,ArraySubType = UnmanagedType.LPWStr)] string[] valuePaths, - [MarshalAs(UnmanagedType.I4)]EvtRenderContextFlags flags + [MarshalAs(UnmanagedType.I4)] EvtRenderContextFlags flags ); [DllImport(WEVTAPI, CallingConvention = CallingConvention.Winapi, SetLastError = true)] @@ -837,7 +837,7 @@ internal static extern bool EvtRender( EventLogHandle eventHandle, EvtRenderFlags flags, int buffSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder buffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer, out int buffUsed, out int propCount ); @@ -877,9 +877,9 @@ internal static extern bool EvtFormatMessage( uint messageId, int valueCount, EvtStringVariant[] values, - [MarshalAs(UnmanagedType.I4)]EvtFormatMessageFlags flags, + [MarshalAs(UnmanagedType.I4)] EvtFormatMessageFlags flags, int bufferSize, - [Out, MarshalAs(UnmanagedType.LPWStr)]StringBuilder buffer, + [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer, out int bufferUsed ); @@ -892,7 +892,7 @@ internal static extern bool EvtFormatMessageBuffer( uint messageId, int valueCount, IntPtr values, - [MarshalAs(UnmanagedType.I4)]EvtFormatMessageFlags flags, + [MarshalAs(UnmanagedType.I4)] EvtFormatMessageFlags flags, int bufferSize, IntPtr buffer, out int bufferUsed @@ -902,7 +902,7 @@ out int bufferUsed [DllImport(WEVTAPI, CharSet = CharSet.Unicode, SetLastError = true)] [SecurityCritical] internal static extern EventLogHandle EvtOpenSession( - [MarshalAs(UnmanagedType.I4)]EvtLoginClass loginClass, + [MarshalAs(UnmanagedType.I4)] EvtLoginClass loginClass, ref EvtRpcLogin login, int timeout, int flags diff --git a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs index 293c3599267..d3bfc2d6b03 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadContext.cs @@ -580,7 +580,7 @@ public class PowerShellAssemblyLoadContextInitializer /// Base directory paths that are separated by semicolon ';'. /// They will be the default paths to probe assemblies. /// - public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)]string basePaths) + public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)] string basePaths) { if (string.IsNullOrEmpty(basePaths)) throw new ArgumentNullException(nameof(basePaths)); diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 4e572586c98..7fa8a4710b9 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -1008,11 +1008,11 @@ internal static class NativeMethods internal static extern int GetPPid(int pid); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int GetLinkCount([MarshalAs(UnmanagedType.LPStr)]string filePath, out int linkCount); + internal static extern int GetLinkCount([MarshalAs(UnmanagedType.LPStr)] string filePath, out int linkCount); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.I1)] - internal static extern bool IsExecutable([MarshalAs(UnmanagedType.LPStr)]string filePath); + internal static extern bool IsExecutable([MarshalAs(UnmanagedType.LPStr)] string filePath); [DllImport(psLib, CharSet = CharSet.Ansi)] internal static extern uint GetCurrentThreadId(); @@ -1069,16 +1069,16 @@ internal static UnixTm DateTimeToUnixTm(DateTime date) internal static extern unsafe int SetDate(UnixTm* tm); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, - [MarshalAs(UnmanagedType.LPStr)]string target); + internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)] string filePath, + [MarshalAs(UnmanagedType.LPStr)] string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, - [MarshalAs(UnmanagedType.LPStr)]string target); + internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)] string filePath, + [MarshalAs(UnmanagedType.LPStr)] string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.LPStr)] - internal static extern string FollowSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath); + internal static extern string FollowSymLink([MarshalAs(UnmanagedType.LPStr)] string filePath); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.LPStr)] @@ -1086,11 +1086,11 @@ internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.I1)] - internal static extern bool IsSameFileSystemItem([MarshalAs(UnmanagedType.LPStr)]string filePathOne, - [MarshalAs(UnmanagedType.LPStr)]string filePathTwo); + internal static extern bool IsSameFileSystemItem([MarshalAs(UnmanagedType.LPStr)] string filePathOne, + [MarshalAs(UnmanagedType.LPStr)] string filePathTwo); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int GetInodeData([MarshalAs(UnmanagedType.LPStr)]string path, + internal static extern int GetInodeData([MarshalAs(UnmanagedType.LPStr)] string path, out UInt64 device, out UInt64 inode); /// diff --git a/src/System.Management.Automation/engine/COM/ComDispatch.cs b/src/System.Management.Automation/engine/COM/ComDispatch.cs index 9199ef9f48f..3f6afa6440e 100644 --- a/src/System.Management.Automation/engine/COM/ComDispatch.cs +++ b/src/System.Management.Automation/engine/COM/ComDispatch.cs @@ -33,7 +33,7 @@ void Invoke( [MarshalAs(UnmanagedType.LPStruct)] Guid iid, int lcid, COM.INVOKEKIND wFlags, - [In, Out] [MarshalAs(UnmanagedType.LPArray)] COM.DISPPARAMS[] paramArray, + [In, Out][MarshalAs(UnmanagedType.LPArray)] COM.DISPPARAMS[] paramArray, out object pVarResult, out ComInvoker.EXCEPINFO pExcepInfo, out uint puArgErr); diff --git a/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs b/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs index 8458a36c026..bea667277a7 100644 --- a/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs +++ b/src/System.Management.Automation/engine/ComInterop/ComRuntimeHelpers.cs @@ -365,7 +365,7 @@ public static unsafe int IDispatchInvoke( fixed (ExcepInfo* pExcepInfo = &excepInfo) fixed (uint* pArgErr = &argErr) { - var pfnIDispatchInvoke = (delegate* stdcall ) + var pfnIDispatchInvoke = (delegate* stdcall) (*(*(void***)dispatchPointer + 6 /* IDispatch.Invoke slot */)); int hresult = pfnIDispatchInvoke(dispatchPointer, diff --git a/src/System.Management.Automation/engine/ComInterop/VariantArray.cs b/src/System.Management.Automation/engine/ComInterop/VariantArray.cs index 83ea62e51f4..a196eb96079 100644 --- a/src/System.Management.Automation/engine/ComInterop/VariantArray.cs +++ b/src/System.Management.Automation/engine/ComInterop/VariantArray.cs @@ -74,7 +74,7 @@ internal static Type GetStructType(int args) // See if we can find an existing type foreach (Type t in s_generatedTypes) { - int arity = int.Parse(t.Name.AsSpan("VariantArray".Length), NumberStyles.Integer, CultureInfo.InvariantCulture); + int arity = int.Parse(t.Name.AsSpan("VariantArray".Length), NumberStyles.Integer, CultureInfo.InvariantCulture); if (size == arity) { return t; diff --git a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs index f6641930bf7..4c5f14cadf5 100644 --- a/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs +++ b/src/System.Management.Automation/engine/Modules/ImportModuleCommand.cs @@ -2024,7 +2024,7 @@ internal override IList ImportModulesUsingWinCompat(IEnumerable ImportModulesUsingWinCompat(IEnumerable ((GetModuleCommand)o).FullyQualifiedName = (ModuleSpecification[])v); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "ErrorAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).ErrorAction = (ActionPreference)v; }); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "WarningAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).WarningAction = (ActionPreference)v; }); s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "InformationAction"), - (o, v) => { + (o, v) => + { v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference)); ((CommonParameters)o).InformationAction = (ActionPreference)v; }); diff --git a/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs b/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs index f77072ea376..30deb1b3093 100644 --- a/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs +++ b/src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs @@ -82,7 +82,8 @@ public static class CommandPrediction ICommandPredictor predictor = predictors[i]; tasks[i] = Task.Factory.StartNew( - state => { + state => + { var predictor = (ICommandPredictor)state!; List? texts = predictor.GetSuggestion(context, cancellationSource.Token); return texts?.Count > 0 ? new PredictionResult(predictor.Id, predictor.Name, texts) : null; diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs index 1b1fe2b2163..91d0bce9ca0 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManNativeAPI.cs @@ -2357,7 +2357,7 @@ internal struct WSManKeyStruct /// [DllImport(WSManNativeApi.WSManClientApiDll, SetLastError = false, CharSet = CharSet.Unicode)] internal static extern int WSManInitialize(int flags, - [In, Out] ref IntPtr wsManAPIHandle); + [In, Out] ref IntPtr wsManAPIHandle); /// /// This API deinitializes the Winrm client stack; all operations will @@ -2390,11 +2390,11 @@ internal static extern int WSManInitialize(int flags, /// [DllImport(WSManNativeApi.WSManClientApiDll, SetLastError = false, CharSet = CharSet.Unicode)] internal static extern int WSManCreateSession(IntPtr wsManAPIHandle, - [MarshalAs(UnmanagedType.LPWStr)]string connection, + [MarshalAs(UnmanagedType.LPWStr)] string connection, int flags, IntPtr authenticationCredentials, IntPtr proxyInfo, - [In, Out] ref IntPtr wsManSessionHandle); + [In, Out] ref IntPtr wsManSessionHandle); /// /// Frees memory of session and closes all related operations before returning; @@ -2553,13 +2553,13 @@ internal static void WSManCreateShellEx(IntPtr wsManSessionHandle, [DllImport(WSManNativeApi.WSManClientApiDll, EntryPoint = "WSManCreateShellEx", SetLastError = false, CharSet = CharSet.Unicode)] private static extern void WSManCreateShellExInternal(IntPtr wsManSessionHandle, int flags, - [MarshalAs(UnmanagedType.LPWStr)]string resourceUri, - [MarshalAs(UnmanagedType.LPWStr)]string shellId, + [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, + [MarshalAs(UnmanagedType.LPWStr)] string shellId, IntPtr startupInfo, IntPtr optionSet, IntPtr openContent, IntPtr asyncCallback, - [In, Out] ref IntPtr shellOperationHandle); + [In, Out] ref IntPtr shellOperationHandle); /// /// @@ -2574,12 +2574,12 @@ private static extern void WSManCreateShellExInternal(IntPtr wsManSessionHandle, [DllImport(WSManNativeApi.WSManClientApiDll, EntryPoint = "WSManConnectShell", SetLastError = false, CharSet = CharSet.Unicode)] internal static extern void WSManConnectShellEx(IntPtr wsManSessionHandle, int flags, - [MarshalAs(UnmanagedType.LPWStr)]string resourceUri, - [MarshalAs(UnmanagedType.LPWStr)]string shellId, + [MarshalAs(UnmanagedType.LPWStr)] string resourceUri, + [MarshalAs(UnmanagedType.LPWStr)] string shellId, IntPtr optionSet, IntPtr connectXml, IntPtr asyncCallback, - [In, Out] ref IntPtr shellOperationHandle); + [In, Out] ref IntPtr shellOperationHandle); /// /// @@ -2685,7 +2685,7 @@ internal static extern void WSManReceiveShellOutputEx(IntPtr shellOperationHandl int flags, IntPtr desiredStreamSet, IntPtr asyncCallback, - [In, Out] ref IntPtr receiveOperationHandle); + [In, Out] ref IntPtr receiveOperationHandle); /// /// Send data to the remote end. @@ -2726,7 +2726,7 @@ private static extern void WSManSendShellInputExInternal(IntPtr shellOperationHa IntPtr streamData, bool endOfStream, IntPtr asyncCallback, - [In, Out] ref IntPtr sendOperationHandle); + [In, Out] ref IntPtr sendOperationHandle); /// /// Closes a shell or a command; if the callback associated with the operation diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs index d5eb990ec57..93443a42c10 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs @@ -305,10 +305,10 @@ internal void CreateShell( PSOpcode.Connect, PSTask.None, PSKeyword.ManagedPlugin | PSKeyword.UseAlwaysAnalytic, requestDetails.ToString(), senderInfo.UserInfo.Identity.Name, requestDetails.resourceUri); - ServerRemoteSession remoteShellSession = ServerRemoteSession.CreateServerRemoteSession(senderInfo, - requestDetails.resourceUri, - extraInfo, - serverTransportMgr); + ServerRemoteSession remoteShellSession = ServerRemoteSession.CreateServerRemoteSession(senderInfo, + requestDetails.resourceUri, + extraInfo, + serverTransportMgr); if (remoteShellSession == null) { diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index c1a539fb3ac..50a6df90c79 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -7699,7 +7699,7 @@ public SwitchParameter NoNewline /// public class FileSystemContentReaderDynamicParameters : FileSystemContentDynamicParametersBase { - internal FileSystemContentReaderDynamicParameters(FileSystemProvider provider) : base (provider) { } + internal FileSystemContentReaderDynamicParameters(FileSystemProvider provider) : base(provider) { } /// /// Gets or sets the delimiter to use when reading the file. Custom delimiters diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index cb2963f40c7..30e0335151f 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -3833,7 +3833,8 @@ private static object ConvertValueToKind(object value, RegistryValueKind kind) { value = 0; } - } break; + } + break; case RegistryValueKind.ExpandString: value = (value != null) @@ -3870,7 +3871,8 @@ private static object ConvertValueToKind(object value, RegistryValueKind kind) { value = 0; } - } break; + } + break; case RegistryValueKind.String: value = (value != null) diff --git a/src/System.Management.Automation/security/SecureStringHelper.cs b/src/System.Management.Automation/security/SecureStringHelper.cs index e6180dc39b7..4c0782e55d5 100644 --- a/src/System.Management.Automation/security/SecureStringHelper.cs +++ b/src/System.Management.Automation/security/SecureStringHelper.cs @@ -617,23 +617,23 @@ internal static bool ErrorMayBeCausedByUnloadedProfile(int errorCode) [DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptProtectData( - [In] IntPtr pDataIn, - [In] string szDataDescr, - [In] IntPtr pOptionalEntropy, - [In] IntPtr pvReserved, - [In] IntPtr pPromptStruct, - [In] uint dwFlags, + [In] IntPtr pDataIn, + [In] string szDataDescr, + [In] IntPtr pOptionalEntropy, + [In] IntPtr pvReserved, + [In] IntPtr pPromptStruct, + [In] uint dwFlags, [In, Out] IntPtr pDataBlob); [DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CryptUnprotectData( - [In] IntPtr pDataIn, - [In] IntPtr ppszDataDescr, - [In] IntPtr pOptionalEntropy, - [In] IntPtr pvReserved, - [In] IntPtr pPromptStruct, - [In] uint dwFlags, + [In] IntPtr pDataIn, + [In] IntPtr ppszDataDescr, + [In] IntPtr pOptionalEntropy, + [In] IntPtr pvReserved, + [In] IntPtr pPromptStruct, + [In] uint dwFlags, [In, Out] IntPtr pDataBlob); [DllImport("ntdll.dll", EntryPoint = "RtlZeroMemory", SetLastError = true)] diff --git a/src/System.Management.Automation/security/SecurityManager.cs b/src/System.Management.Automation/security/SecurityManager.cs index f6ae0fdf1f3..44699ba1373 100644 --- a/src/System.Management.Automation/security/SecurityManager.cs +++ b/src/System.Management.Automation/security/SecurityManager.cs @@ -383,7 +383,8 @@ private bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Excep { TrustPublisher(signature); policyCheckPassed = true; - } break; + } + break; case RunPromptDecision.DoNotRun: policyCheckPassed = false; reasonMessage = StringUtil.Format(Authenticode.Reason_DoNotRun, path); @@ -395,7 +396,8 @@ private bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Excep reasonMessage = StringUtil.Format(Authenticode.Reason_NeverRun, path); reason = new UnauthorizedAccessException(reasonMessage); policyCheckPassed = false; - } break; + } + break; } return policyCheckPassed; diff --git a/src/System.Management.Automation/security/SecuritySupport.cs b/src/System.Management.Automation/security/SecuritySupport.cs index 90d4a71d73b..4303075d8eb 100644 --- a/src/System.Management.Automation/security/SecuritySupport.cs +++ b/src/System.Management.Automation/security/SecuritySupport.cs @@ -1605,7 +1605,7 @@ internal enum AMSI_RESULT [DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)] [DllImportAttribute("amsi.dll", EntryPoint = "AmsiInitialize", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiInitialize( - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string appName, ref System.IntPtr amsiContext); + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string appName, ref System.IntPtr amsiContext); /// Return Type: void ///amsiContext: HAMSICONTEXT->HAMSICONTEXT__* @@ -1638,7 +1638,7 @@ internal static extern int AmsiInitialize( [DllImportAttribute("amsi.dll", EntryPoint = "AmsiScanBuffer", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiScanBuffer( System.IntPtr amsiContext, System.IntPtr buffer, uint length, - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); /// Return Type: HRESULT->LONG->int ///amsiContext: HAMSICONTEXT->HAMSICONTEXT__* @@ -1649,8 +1649,8 @@ internal static extern int AmsiScanBuffer( [DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)] [DllImportAttribute("amsi.dll", EntryPoint = "AmsiScanString", CallingConvention = CallingConvention.StdCall)] internal static extern int AmsiScanString( - System.IntPtr amsiContext, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string @string, - [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); + System.IntPtr amsiContext, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string @string, + [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string contentName, System.IntPtr amsiSession, ref AMSI_RESULT result); } } } diff --git a/src/System.Management.Automation/security/nativeMethods.cs b/src/System.Management.Automation/security/nativeMethods.cs index 7cda5b88260..8381c64bfe5 100644 --- a/src/System.Management.Automation/security/nativeMethods.cs +++ b/src/System.Management.Automation/security/nativeMethods.cs @@ -1154,7 +1154,7 @@ DWORD idxCert ///ppCertContext: void** ///phWVTStateData: HANDLE* [DllImportAttribute("wintrust.dll", EntryPoint = "WTGetSignatureInfo", CallingConvention = CallingConvention.StdCall)] - internal static extern int WTGetSignatureInfo([InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string pszFile, [InAttribute()] System.IntPtr hFile, SIGNATURE_INFO_FLAGS sigInfoFlags, ref SIGNATURE_INFO psiginfo, ref System.IntPtr ppCertContext, ref System.IntPtr phWVTStateData); + internal static extern int WTGetSignatureInfo([InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string pszFile, [InAttribute()] System.IntPtr hFile, SIGNATURE_INFO_FLAGS sigInfoFlags, ref SIGNATURE_INFO psiginfo, ref System.IntPtr ppCertContext, ref System.IntPtr phWVTStateData); internal static void FreeWVTStateData(System.IntPtr phWVTStateData) { diff --git a/src/System.Management.Automation/utils/CryptoUtils.cs b/src/System.Management.Automation/utils/CryptoUtils.cs index 4b747eeab82..4a4e9036979 100644 --- a/src/System.Management.Automation/utils/CryptoUtils.cs +++ b/src/System.Management.Automation/utils/CryptoUtils.cs @@ -64,7 +64,7 @@ internal static class PSCryptoNativeConverter private static int ToInt32LE(byte[] bytes, int offset) { - return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1 ] << 8) | bytes[offset]; + return (bytes[offset + 3] << 24) | (bytes[offset + 2] << 16) | (bytes[offset + 1] << 8) | bytes[offset]; } private static uint ToUInt32LE(byte[] bytes, int offset) @@ -140,7 +140,7 @@ private static RSAParameters GetParametersFromCapiPublicKeyBlob(byte[] blob, int try { - if ((blob[offset] != PUBLICKEYBLOB) || // PUBLICKEYBLOB (0x06) + if ((blob[offset] != PUBLICKEYBLOB) || // PUBLICKEYBLOB (0x06) (blob[offset + 1] != CUR_BLOB_VERSION) || // Version (0x02) (blob[offset + 2] != 0x00) || // Reserved (word) (blob[offset + 3] != 0x00) || From 5037e9dcb4ae0236137454c608af0247293d49fd Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Fri, 28 Aug 2020 21:58:55 +0100 Subject: [PATCH 2/2] Fix CodeFactor issues --- src/System.Management.Automation/namespaces/RegistryProvider.cs | 2 ++ src/System.Management.Automation/security/SecurityManager.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/System.Management.Automation/namespaces/RegistryProvider.cs b/src/System.Management.Automation/namespaces/RegistryProvider.cs index 30e0335151f..ab8cab3fc0b 100644 --- a/src/System.Management.Automation/namespaces/RegistryProvider.cs +++ b/src/System.Management.Automation/namespaces/RegistryProvider.cs @@ -3834,6 +3834,7 @@ private static object ConvertValueToKind(object value, RegistryValueKind kind) value = 0; } } + break; case RegistryValueKind.ExpandString: @@ -3872,6 +3873,7 @@ private static object ConvertValueToKind(object value, RegistryValueKind kind) value = 0; } } + break; case RegistryValueKind.String: diff --git a/src/System.Management.Automation/security/SecurityManager.cs b/src/System.Management.Automation/security/SecurityManager.cs index 44699ba1373..035ce85997b 100644 --- a/src/System.Management.Automation/security/SecurityManager.cs +++ b/src/System.Management.Automation/security/SecurityManager.cs @@ -384,6 +384,7 @@ private bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Excep TrustPublisher(signature); policyCheckPassed = true; } + break; case RunPromptDecision.DoNotRun: policyCheckPassed = false; @@ -397,6 +398,7 @@ private bool SetPolicyFromAuthenticodePrompt(string path, PSHost host, ref Excep reason = new UnauthorizedAccessException(reasonMessage); policyCheckPassed = false; } + break; }