Address SYSLIB1054

This commit is contained in:
JustArchi
2022-11-14 23:42:44 +01:00
parent 8bf2504acf
commit 0a5a447b6d
3 changed files with 87 additions and 58 deletions

View File

@@ -0,0 +1,84 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
// |
// Copyright 2015-2022 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
// |
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/LICENSE-2.0
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace ArchiSteamFarm.Core;
internal static partial class NativeMethods {
[SupportedOSPlatform("Windows")]
internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous;
[SupportedOSPlatform("Windows")]
internal const uint EnableQuickEditMode = 0x0040;
[SupportedOSPlatform("Windows")]
internal const sbyte StandardInputHandle = -10;
#pragma warning disable CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("libc", EntryPoint = "chmod", SetLastError = true, StringMarshalling = StringMarshalling.Utf8)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal static partial int Chmod(string path, int mode);
#pragma warning restore CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("libc", EntryPoint = "geteuid", SetLastError = true)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal static partial uint GetEuid();
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static partial IntPtr GetStdHandle(int nStdHandle);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[LibraryImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static partial EExecutionState SetThreadExecutionState(EExecutionState executionState);
[Flags]
[SupportedOSPlatform("Windows")]
internal enum EExecutionState : uint {
None = 0,
SystemRequired = 0x00000001,
AwayModeRequired = 0x00000040,
Continuous = 0x80000000
}
}

View File

@@ -148,7 +148,7 @@ internal static class OS {
}
if (OperatingSystem.IsFreeBSD() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
return NativeMethods.GetEUID() == 0;
return NativeMethods.GetEuid() == 0;
}
// We can't determine whether user is running as root or not, so fallback to that not happening
@@ -344,60 +344,4 @@ internal static class OS {
UserRead = 0x100,
Combined777 = UserRead | UserWrite | UserExecute | GroupRead | GroupWrite | GroupExecute | OtherRead | OtherWrite | OtherExecute
}
private static class NativeMethods {
[SupportedOSPlatform("Windows")]
internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous;
[SupportedOSPlatform("Windows")]
internal const uint EnableQuickEditMode = 0x0040;
[SupportedOSPlatform("Windows")]
internal const sbyte StandardInputHandle = -10;
#pragma warning disable CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal static extern int Chmod(string path, int mode);
#pragma warning restore CA2101 // False positive, we can't use unicode charset on Unix, and it uses UTF-8 by default anyway
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("libc", EntryPoint = "geteuid", SetLastError = true)]
[SupportedOSPlatform("FreeBSD")]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("MacOS")]
internal static extern uint GetEUID();
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static extern IntPtr GetStdHandle(int nStdHandle);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DllImport("kernel32.dll")]
[SupportedOSPlatform("Windows")]
internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState);
[Flags]
[SupportedOSPlatform("Windows")]
internal enum EExecutionState : uint {
None = 0,
SystemRequired = 0x00000001,
AwayModeRequired = 0x00000040,
Continuous = 0x80000000
}
}
}

View File

@@ -4,6 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<ApplicationIcon>../resources/ASF.ico</ApplicationIcon>
<Authors>JustArchi</Authors>
@@ -70,7 +71,7 @@
<DebugType>none</DebugType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<WarningsNotAsErrors>CS8002,IL2026,IL2057,IL2072,IL2075,IL2104,SYSLIB1045,SYSLIB1054</WarningsNotAsErrors>
<WarningsNotAsErrors>CS8002,IL2026,IL2057,IL2072,IL2075,IL2104,SYSLIB1045</WarningsNotAsErrors>
</PropertyGroup>
<!-- Enable public signing if not part of Visual Studio, which is too stupid to understand what public signing is -->