From a1c604e68af0976a791aa3444696fa98479c46d4 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Thu, 25 Jan 2024 15:50:46 +0800 Subject: [PATCH] add required win32 apis --- .../Snap.Hutao/Extension/StringExtension.cs | 14 ---- .../Snap.Hutao/Web/Hoyolab/CookieExtension.cs | 2 +- .../Takumi/GameRecord/GameRecordClient.cs | 2 +- src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs | 4 +- .../Snap.Hutao/Win32/ApiMsWinNetIsolation.cs | 75 +++++++++++++++++++ src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs | 2 + .../Win32/Foundation/FlexibleArray.cs | 10 +++ .../Snap.Hutao/Win32/Foundation/PSID.cs | 9 +++ src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs | 2 + src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs | 37 ++++++++- src/Snap.Hutao/Snap.Hutao/Win32/Macros.cs | 1 + .../Win32/Memory/IUnmanagedMemory.cs | 10 +-- .../Snap.Hutao/Win32/Memory/VirtualMemory.cs | 14 ++-- .../INET_FIREWALL_AC_BINARIES.cs | 13 ++++ .../INET_FIREWALL_AC_CAPABILITIES.cs | 13 ++++ .../INET_FIREWALL_APP_CONTAINER.cs | 21 ++++++ .../WindowsFirewall/NETISO_FLAG.cs | 10 +++ src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs | 3 + .../Snap.Hutao/Win32/Security/SID.cs | 14 ++++ .../Win32/Security/SID_AND_ATTRIBUTES.cs | 12 +++ .../Security/SID_IDENTIFIER_AUTHORITY.cs | 9 +++ src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs | 2 + .../Win32/UI/Shell/Common/SHITEMID.cs | 3 +- src/Snap.Hutao/Snap.Hutao/Win32/User32.cs | 5 ++ 24 files changed, 255 insertions(+), 32 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/ApiMsWinNetIsolation.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/Foundation/FlexibleArray.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/Foundation/PSID.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_BINARIES.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_CAPABILITIES.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_APP_CONTAINER.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/NETISO_FLAG.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/Security/SID.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_AND_ATTRIBUTES.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_IDENTIFIER_AUTHORITY.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/StringExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/StringExtension.cs index 649fb1e7..02d523aa 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/StringExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Extension/StringExtension.cs @@ -27,18 +27,4 @@ internal static class StringExtension { return source.AsSpan().TrimEnd(value).ToString(); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool EqualsAny(this string source, in ReadOnlySpan values, StringComparison comparisonType) - { - foreach (ref readonly string value in values) - { - if (source.Equals(value, comparisonType)) - { - return true; - } - } - - return false; - } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs index 1e37f57e..21e1f9ef 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs @@ -49,7 +49,7 @@ internal static class CookieExtension Must.Range(keys.Length > 0, "Empty keys is not supported"); SortedDictionary cookieMap = []; - foreach (string key in keys) + foreach (ref readonly string key in keys) { if (source.TryGetValue(key, out string? value)) { diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs index a3719026..34f78c9b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/Takumi/GameRecord/GameRecordClient.cs @@ -214,7 +214,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient .ConfigureAwait(false); // We have a verification procedure to handle - if (resp?.ReturnCode == (int)KnownReturnCode.CODE1034) + if (resp?.ReturnCode is (int)KnownReturnCode.CODE1034) { // Replace message resp.Message = SH.WebIndexOrSpiralAbyssVerificationFailed; diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs index 7d439cac..de928361 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs @@ -3,6 +3,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.Registry; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -22,8 +23,9 @@ internal static class AdvApi32 [DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] [SupportedOSPlatform("windows5.0")] - public static unsafe extern WIN32_ERROR RegOpenKeyExW(HKEY hKey, [AllowNull] PCWSTR lpSubKey, [AllowNull] uint ulOptions, REG_SAM_FLAGS samDesired, [Out] HKEY* phkResult); + public static unsafe extern WIN32_ERROR RegOpenKeyExW(HKEY hKey, [AllowNull] PCWSTR lpSubKey, [AllowNull] uint ulOptions, REG_SAM_FLAGS samDesired, HKEY* phkResult); + [DebuggerStepThrough] public static unsafe WIN32_ERROR RegOpenKeyExW(HKEY hKey, ReadOnlySpan subKey, uint ulOptions, REG_SAM_FLAGS samDesired, out HKEY hkResult) { fixed (char* lpSubKey = subKey) diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/ApiMsWinNetIsolation.cs b/src/Snap.Hutao/Snap.Hutao/Win32/ApiMsWinNetIsolation.cs new file mode 100644 index 00000000..a4259ab2 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/ApiMsWinNetIsolation.cs @@ -0,0 +1,75 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Foundation; +using Snap.Hutao.Win32.NetworkManagement.WindowsFirewall; +using Snap.Hutao.Win32.Security; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; + +namespace Snap.Hutao.Win32; + +[SuppressMessage("", "SH002")] +[SuppressMessage("", "SA1313")] +[SuppressMessage("", "SYSLIB1054")] +internal static class ApiMsWinNetIsolation +{ + [DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)] + [SupportedOSPlatform("windows8.0")] + public static unsafe extern uint NetworkIsolationEnumAppContainers(uint Flags, uint* pdwNumPublicAppCs, INET_FIREWALL_APP_CONTAINER** ppPublicAppCs); + + [DebuggerStepThrough] + public static unsafe uint NetworkIsolationEnumAppContainers(NETISO_FLAG Flags, out uint dwNumPublicAppCs, out INET_FIREWALL_APP_CONTAINER* pPublicAppCs) + { + fixed (uint* pdwNumPublicAppCs = &dwNumPublicAppCs) + { + fixed (INET_FIREWALL_APP_CONTAINER** ppPublicAppCs = &pPublicAppCs) + { + return NetworkIsolationEnumAppContainers((uint)Flags, pdwNumPublicAppCs, ppPublicAppCs); + } + } + } + + [DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)] + [SupportedOSPlatform("windows8.0")] + public static unsafe extern uint NetworkIsolationFreeAppContainers(INET_FIREWALL_APP_CONTAINER* pPublicAppCs); + + [DebuggerStepThrough] + public static unsafe uint NetworkIsolationFreeAppContainers(ref readonly INET_FIREWALL_APP_CONTAINER publicAppCs) + { + fixed (INET_FIREWALL_APP_CONTAINER* pPublicAppCs = &publicAppCs) + { + return NetworkIsolationFreeAppContainers(pPublicAppCs); + } + } + + [DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)] + [SupportedOSPlatform("windows8.0")] + public static unsafe extern uint NetworkIsolationGetAppContainerConfig(uint* pdwNumPublicAppCs, SID_AND_ATTRIBUTES** appContainerSids); + + [DebuggerStepThrough] + public static unsafe uint NetworkIsolationGetAppContainerConfig(out uint dwNumPublicAppCs, out SID_AND_ATTRIBUTES* appContainerSids) + { + fixed (uint* pdwNumPublicAppCs = &dwNumPublicAppCs) + { + fixed (SID_AND_ATTRIBUTES** pAppContainerSids = &appContainerSids) + { + return NetworkIsolationGetAppContainerConfig(pdwNumPublicAppCs, pAppContainerSids); + } + } + } + + [DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)] + [SupportedOSPlatform("windows8.0")] + public static unsafe extern uint NetworkIsolationSetAppContainerConfig(uint dwNumPublicAppCs, SID_AND_ATTRIBUTES* appContainerSids); + + [DebuggerStepThrough] + public static unsafe uint NetworkIsolationSetAppContainerConfig(ReadOnlySpan appContainerSids) + { + fixed (SID_AND_ATTRIBUTES* pAppContainerSids = appContainerSids) + { + return NetworkIsolationSetAppContainerConfig((uint)appContainerSids.Length, pAppContainerSids); + } + } +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs b/src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs index 3af8fcb0..b9269a79 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs @@ -3,6 +3,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.Graphics.Dwm; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -16,6 +17,7 @@ internal static class DwmApi [SupportedOSPlatform("windows6.0.6000")] public static unsafe extern HRESULT DwmSetWindowAttribute(HWND hwnd, uint dwAttribute, void* pvAttribute, uint cbAttribute); + [DebuggerStepThrough] public static unsafe HRESULT DwmSetWindowAttribute(HWND hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref readonly T attribute) where T : unmanaged { diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/FlexibleArray.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/FlexibleArray.cs new file mode 100644 index 00000000..e4a4ba5e --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/FlexibleArray.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Win32.Foundation; + +internal unsafe struct FlexibleArray + where T : unmanaged +{ + public T* Reference; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/PSID.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/PSID.cs new file mode 100644 index 00000000..8978cf35 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Foundation/PSID.cs @@ -0,0 +1,9 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Win32.Foundation; + +internal struct PSID +{ + public unsafe void* Value; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs index 6cf41ec0..bb910fa6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using Snap.Hutao.Win32.Graphics.Gdi; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -15,6 +16,7 @@ internal static class Gdi32 [SupportedOSPlatform("windows5.0")] public static extern int GetDeviceCaps([AllowNull] HDC hdc, int index); + [DebuggerStepThrough] public static int GetDeviceCaps([AllowNull] HDC hdc, GET_DEVICE_CAPS_INDEX index) { return GetDeviceCaps(hdc, (int)index); diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs index 333acc51..eba85da9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs @@ -5,6 +5,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.Security; using Snap.Hutao.Win32.System.Console; using Snap.Hutao.Win32.System.ProcessStatus; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -25,6 +26,18 @@ internal static class Kernel32 [SupportedOSPlatform("windows5.1.2600")] public static unsafe extern HANDLE CreateEventW([AllowNull] SECURITY_ATTRIBUTES* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, [AllowNull] PCWSTR lpName); + [DebuggerStepThrough] + public static unsafe HANDLE CreateEventW(ref readonly SECURITY_ATTRIBUTES eventAttributes, BOOL bManualReset, BOOL bInitialState, [AllowNull] ReadOnlySpan name) + { + fixed (SECURITY_ATTRIBUTES* lpEventAttributes = &eventAttributes) + { + fixed (char* lpName = name) + { + return CreateEventW(lpEventAttributes, bManualReset, bInitialState, lpName); + } + } + } + [DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)] public static extern BOOL FreeConsole(); @@ -32,6 +45,7 @@ internal static class Kernel32 public static unsafe extern BOOL GetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE* lpMode); [SuppressMessage("", "SH002")] + [DebuggerStepThrough] public static unsafe BOOL GetConsoleMode(HANDLE hConsoleHandle, out CONSOLE_MODE mode) { fixed (CONSOLE_MODE* lpMode = &mode) @@ -46,6 +60,7 @@ internal static class Kernel32 [DllImport("KERNEL32.dll", ExactSpelling = true)] public static unsafe extern BOOL K32EnumProcessModules(HANDLE hProcess, HMODULE* lphModule, uint cb, uint* lpcbNeeded); + [DebuggerStepThrough] public static unsafe BOOL K32EnumProcessModules(HANDLE hProcess, Span hModules, out uint cbNeeded) { fixed (HMODULE* lphModule = hModules) @@ -60,6 +75,7 @@ internal static class Kernel32 [DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] public static extern uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMODULE hModule, PWSTR lpBaseName, uint nSize); + [DebuggerStepThrough] public static unsafe uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMODULE hModule, Span baseName) { fixed (char* lpBaseName = baseName) @@ -69,8 +85,9 @@ internal static class Kernel32 } [DllImport("KERNEL32.dll", ExactSpelling = true)] - public static unsafe extern BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, [Out] MODULEINFO* lpmodinfo, [In] uint cb); + public static unsafe extern BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, MODULEINFO* lpmodinfo, uint cb); + [DebuggerStepThrough] public static unsafe BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, out MODULEINFO modinfo) { fixed (MODULEINFO* lpmodinfo = &modinfo) @@ -83,6 +100,7 @@ internal static class Kernel32 [SupportedOSPlatform("windows5.1.2600")] public static unsafe extern BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, [MaybeNull] nuint* lpNumberOfBytesRead); + [DebuggerStepThrough] public static unsafe BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, Span buffer, [MaybeNull] out nuint numberOfBytesRead) { fixed (byte* lpBuffer = buffer) @@ -94,6 +112,7 @@ internal static class Kernel32 } } + [DebuggerStepThrough] public static unsafe BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, ref T buffer, [MaybeNull] out nuint numberOfBytesRead) where T : unmanaged { @@ -112,7 +131,8 @@ internal static class Kernel32 [DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] public static extern BOOL SetConsoleTitleW(PCWSTR lpConsoleTitle); - public static unsafe BOOL SetConsoleTitleW(string consoleTitle) + [DebuggerStepThrough] + public static unsafe BOOL SetConsoleTitleW(ReadOnlySpan consoleTitle) { fixed (char* lpConsoleTitle = consoleTitle) { @@ -128,6 +148,19 @@ internal static class Kernel32 [SupportedOSPlatform("windows5.1.2600")] public static unsafe extern BOOL WriteProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, nuint* lpNumberOfBytesWritten); + [DebuggerStepThrough] + public static unsafe BOOL WriteProcessMemory(HANDLE hProcess, void* lpBaseAddress, ReadOnlySpan buffer, out nuint numberOfBytesWritten) + { + fixed (byte* lpBuffer = buffer) + { + fixed (nuint* lpNumberOfBytesWritten = &numberOfBytesWritten) + { + return WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, (uint)buffer.Length, lpNumberOfBytesWritten); + } + } + } + + [DebuggerStepThrough] public static unsafe BOOL WriteProcessMemory(HANDLE hProcess, void* lpBaseAddress, ref readonly T buffer, out nuint numberOfBytesWritten) where T : unmanaged { diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Macros.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Macros.cs index a261ce73..164ef402 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Macros.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Macros.cs @@ -19,6 +19,7 @@ internal static class Macros [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HRESULT HRESULT_FROM_WIN32(WIN32_ERROR x) { + // 0x80000000 or 0x80070000 | LOWBYTE(x) return x <= 0 ? (int)x : (int)(((uint)x & 0x0000FFFFU) | ((uint)FACILITY_CODE.FACILITY_WIN32 << 16) | 0x80000000U); } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs index 0de89228..efc6dddc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/IUnmanagedMemory.cs @@ -8,13 +8,13 @@ namespace Snap.Hutao.Win32.Memory; /// internal unsafe interface IUnmanagedMemory : IDisposable { - /// - /// Gets a pointer to the allocated unmanaged memory. - /// - void* Pointer { get; } - /// /// Gets size of referenced unmanaged memory, in bytes. /// uint Size { get; } + + /// + /// Gets a pointer to the allocated unmanaged memory. + /// + void* Pointer { get; } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs index 71477317..f6ebed5e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Memory/VirtualMemory.cs @@ -10,16 +10,16 @@ namespace Snap.Hutao.Win32.Memory; /// internal readonly unsafe struct VirtualMemory : IUnmanagedMemory { - /// - /// 缓冲区地址 - /// - private readonly void* pointer; - /// /// 长度 /// private readonly uint size; + /// + /// 缓冲区地址 + /// + private readonly void* pointer; + /// /// 构造一个新的本地内存 /// @@ -31,10 +31,10 @@ internal readonly unsafe struct VirtualMemory : IUnmanagedMemory } /// - public void* Pointer { get => pointer; } + public uint Size { get => size; } /// - public uint Size { get => size; } + public void* Pointer { get => pointer; } /// public void Dispose() diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_BINARIES.cs b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_BINARIES.cs new file mode 100644 index 00000000..67a4c3f9 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_BINARIES.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Foundation; + +namespace Snap.Hutao.Win32.NetworkManagement.WindowsFirewall; + +[SuppressMessage("", "SA1307")] +internal struct INET_FIREWALL_AC_BINARIES +{ + public uint count; + public unsafe PWSTR* binaries; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_CAPABILITIES.cs b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_CAPABILITIES.cs new file mode 100644 index 00000000..33419c25 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_AC_CAPABILITIES.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Security; + +namespace Snap.Hutao.Win32.NetworkManagement.WindowsFirewall; + +[SuppressMessage("", "SA1307")] +internal struct INET_FIREWALL_AC_CAPABILITIES +{ + public uint count; + public unsafe SID_AND_ATTRIBUTES* capabilities; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_APP_CONTAINER.cs b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_APP_CONTAINER.cs new file mode 100644 index 00000000..8bf59997 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/INET_FIREWALL_APP_CONTAINER.cs @@ -0,0 +1,21 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Foundation; +using Snap.Hutao.Win32.Security; + +namespace Snap.Hutao.Win32.NetworkManagement.WindowsFirewall; + +[SuppressMessage("", "SA1307")] +internal struct INET_FIREWALL_APP_CONTAINER +{ + public unsafe SID* appContainerSid; + public unsafe SID* userSid; + public PWSTR appContainerName; + public PWSTR displayName; + public PWSTR description; + public INET_FIREWALL_AC_CAPABILITIES capabilities; + public INET_FIREWALL_AC_BINARIES binaries; + public PWSTR workingDirectory; + public PWSTR packageFullName; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/NETISO_FLAG.cs b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/NETISO_FLAG.cs new file mode 100644 index 00000000..dcde8cde --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/NetworkManagement/WindowsFirewall/NETISO_FLAG.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Win32.NetworkManagement.WindowsFirewall; + +internal enum NETISO_FLAG +{ + NETISO_FLAG_FORCE_COMPUTE_BINARIES = 1, + NETISO_FLAG_MAX = 2 +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs index fef2009f..405db369 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs @@ -3,6 +3,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.System.Com; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -16,6 +17,7 @@ internal static class Ole32 [SupportedOSPlatform("windows5.0")] public static unsafe extern HRESULT CoCreateInstance(Guid* rclsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, Guid* riid, void** ppv); + [DebuggerStepThrough] public static unsafe HRESULT CoCreateInstance(ref readonly Guid clsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, ref readonly Guid iid, out T* pv) where T : unmanaged { @@ -39,6 +41,7 @@ internal static class Ole32 public static unsafe extern HRESULT CoWaitForMultipleObjects(uint dwFlags, uint dwTimeout, uint cHandles, HANDLE* pHandles, uint* lpdwindex); [SuppressMessage("", "SH002")] + [DebuggerStepThrough] public static unsafe HRESULT CoWaitForMultipleObjects(uint dwFlags, uint dwTimeout, ReadOnlySpan handles, out uint dwindex) { fixed (HANDLE* pHandles = handles) diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID.cs new file mode 100644 index 00000000..609aef30 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID.cs @@ -0,0 +1,14 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Foundation; + +namespace Snap.Hutao.Win32.Security; + +internal struct SID +{ + public byte Revision; + public byte SubAuthorityCount; + public SID_IDENTIFIER_AUTHORITY IdentifierAuthority; + public FlexibleArray SubAuthority; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_AND_ATTRIBUTES.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_AND_ATTRIBUTES.cs new file mode 100644 index 00000000..b54f7051 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_AND_ATTRIBUTES.cs @@ -0,0 +1,12 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Win32.Foundation; + +namespace Snap.Hutao.Win32.Security; + +internal struct SID_AND_ATTRIBUTES +{ + public unsafe PSID Sid; + public uint Attributes; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_IDENTIFIER_AUTHORITY.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_IDENTIFIER_AUTHORITY.cs new file mode 100644 index 00000000..0af18b10 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Security/SID_IDENTIFIER_AUTHORITY.cs @@ -0,0 +1,9 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Win32.Security; + +internal struct SID_IDENTIFIER_AUTHORITY +{ + public unsafe fixed byte Value[6]; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs index 55bda29c..7e2ee942 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs @@ -3,6 +3,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.System.Com; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -16,6 +17,7 @@ internal static class Shell32 [SupportedOSPlatform("windows6.0.6000")] public static unsafe extern HRESULT SHCreateItemFromParsingName(PCWSTR pszPath, [AllowNull] IBindCtx pbc, Guid* riid, void** ppv); + [DebuggerStepThrough] public static unsafe HRESULT SHCreateItemFromParsingName(ReadOnlySpan szPath, [AllowNull] IBindCtx pbc, ref readonly Guid riid, out T* pv) where T : unmanaged { diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/UI/Shell/Common/SHITEMID.cs b/src/Snap.Hutao/Snap.Hutao/Win32/UI/Shell/Common/SHITEMID.cs index 0e1d949f..9c13d012 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/UI/Shell/Common/SHITEMID.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/UI/Shell/Common/SHITEMID.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. using System.Runtime.InteropServices; +using Snap.Hutao.Win32.Foundation; namespace Snap.Hutao.Win32.UI.Shell.Common; @@ -10,5 +11,5 @@ namespace Snap.Hutao.Win32.UI.Shell.Common; internal struct SHITEMID { public ushort cb; - public unsafe byte* abID; + public FlexibleArray abID; } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs index 9a6ca787..2da89af9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Win32/User32.cs @@ -5,6 +5,7 @@ using Snap.Hutao.Win32.Foundation; using Snap.Hutao.Win32.Graphics.Gdi; using Snap.Hutao.Win32.UI.Input.KeyboardAndMouse; using Snap.Hutao.Win32.UI.WindowsAndMessaging; +using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Versioning; @@ -22,6 +23,7 @@ internal static class User32 [SupportedOSPlatform("windows5.0")] public static extern HWND FindWindowExW([AllowNull] HWND hWndParent, [AllowNull] HWND hWndChildAfter, [AllowNull] PCWSTR lpszClass, [AllowNull] PCWSTR lpszWindow); + [DebuggerStepThrough] public static unsafe HWND FindWindowExW([AllowNull] HWND hWndParent, [AllowNull] HWND hWndChildAfter, [AllowNull] string szClass, [AllowNull] string szWindow) { fixed (char* lpszClass = szClass) @@ -53,6 +55,7 @@ internal static class User32 [SupportedOSPlatform("windows5.0")] public static unsafe extern BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT* lpwndpl); + [DebuggerStepThrough] public static unsafe BOOL GetWindowPlacement(HWND hWnd, ref WINDOWPLACEMENT wndpl) { fixed (WINDOWPLACEMENT* lpwndpl = &wndpl) @@ -65,6 +68,7 @@ internal static class User32 [SupportedOSPlatform("windows5.0")] public static unsafe extern uint GetWindowThreadProcessId(HWND hWnd, [MaybeNull] uint* lpdwProcessId); + [DebuggerStepThrough] public static unsafe uint GetWindowThreadProcessId(HWND hWnd, [MaybeNull] out uint dwProcessId) { fixed (uint* lpdwProcessId = &dwProcessId) @@ -85,6 +89,7 @@ internal static class User32 [SupportedOSPlatform("windows5.0")] public static unsafe extern uint SendInput(uint cInputs, INPUT* pInputs, int cbSize); + [DebuggerStepThrough] public static unsafe uint SendInput(ReadOnlySpan inputs, int cbSize) { fixed (INPUT* pInputs = inputs)