mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-11 01:37:24 +01:00
Update Microsoft.Windows.CsWin32
This commit is contained in:
parent
98a4c0d4fd
commit
7cf20fe102
3 changed files with 21 additions and 6 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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})");
|
||||
|
|
|
|||
|
|
@ -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" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue