Update Microsoft.Windows.CsWin32

This commit is contained in:
Haselnussbomber 2025-12-05 00:35:52 +01:00
parent 98a4c0d4fd
commit 7cf20fe102
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
3 changed files with 21 additions and 6 deletions

View file

@ -1,6 +1,8 @@
using System.Runtime.InteropServices;
using System.Text;
using Windows.Win32.Foundation;
namespace Dalamud;
/// <summary>
@ -28,12 +30,18 @@ public static class SafeMemory
/// <returns>Whether the read succeeded.</returns>
public static unsafe bool ReadBytes(IntPtr address, int count, out byte[] buffer)
{
if (Handle.IsClosed || Handle.IsInvalid)
{
buffer = [];
return false;
}
buffer = new byte[count <= 0 ? 0 : count];
fixed (byte* p = buffer)
{
UIntPtr bytesRead;
if (!Windows.Win32.PInvoke.ReadProcessMemory(
Handle,
(HANDLE)Handle.DangerousGetHandle(),
address.ToPointer(),
p,
new UIntPtr((uint)count),
@ -54,6 +62,9 @@ public static class SafeMemory
/// <returns>Whether the write succeeded.</returns>
public static unsafe bool WriteBytes(IntPtr address, byte[] buffer)
{
if (Handle.IsClosed || Handle.IsInvalid)
return false;
if (buffer.Length == 0)
return true;
@ -61,7 +72,7 @@ public static class SafeMemory
fixed (byte* p = buffer)
{
if (!Windows.Win32.PInvoke.WriteProcessMemory(
Handle,
(HANDLE)Handle.DangerousGetHandle(),
address.ToPointer(),
p,
new UIntPtr((uint)buffer.Length),

View file

@ -1,7 +1,8 @@
using System.ComponentModel;
using System.ComponentModel;
using System.IO;
using System.Text;
using Windows.Win32.Foundation;
using Windows.Win32.Storage.FileSystem;
namespace Dalamud.Utility;
@ -61,8 +62,11 @@ public static class FilesystemUtil
// Write the data
uint bytesWritten = 0;
if (!Windows.Win32.PInvoke.WriteFile(tempFile, new ReadOnlySpan<byte>(bytes), &bytesWritten, null))
throw new Win32Exception();
fixed (byte* ptr = bytes)
{
if (!Windows.Win32.PInvoke.WriteFile((HANDLE)tempFile.DangerousGetHandle(), ptr, (uint)bytes.Length, &bytesWritten, null))
throw new Win32Exception();
}
if (bytesWritten != bytes.Length)
throw new Exception($"Could not write all bytes to temp file ({bytesWritten} of {bytes.Length})");

View file

@ -27,7 +27,7 @@
<!-- DirectX / Win32 -->
<PackageVersion Include="TerraFX.Interop.Windows" Version="10.0.26100.5" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.183" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.259" />
<!-- Logging -->
<PackageVersion Include="Serilog" Version="4.0.2" />