mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +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.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
using Windows.Win32.Foundation;
|
||||||
|
|
||||||
namespace Dalamud;
|
namespace Dalamud;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -28,12 +30,18 @@ public static class SafeMemory
|
||||||
/// <returns>Whether the read succeeded.</returns>
|
/// <returns>Whether the read succeeded.</returns>
|
||||||
public static unsafe bool ReadBytes(IntPtr address, int count, out byte[] buffer)
|
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];
|
buffer = new byte[count <= 0 ? 0 : count];
|
||||||
fixed (byte* p = buffer)
|
fixed (byte* p = buffer)
|
||||||
{
|
{
|
||||||
UIntPtr bytesRead;
|
UIntPtr bytesRead;
|
||||||
if (!Windows.Win32.PInvoke.ReadProcessMemory(
|
if (!Windows.Win32.PInvoke.ReadProcessMemory(
|
||||||
Handle,
|
(HANDLE)Handle.DangerousGetHandle(),
|
||||||
address.ToPointer(),
|
address.ToPointer(),
|
||||||
p,
|
p,
|
||||||
new UIntPtr((uint)count),
|
new UIntPtr((uint)count),
|
||||||
|
|
@ -54,6 +62,9 @@ public static class SafeMemory
|
||||||
/// <returns>Whether the write succeeded.</returns>
|
/// <returns>Whether the write succeeded.</returns>
|
||||||
public static unsafe bool WriteBytes(IntPtr address, byte[] buffer)
|
public static unsafe bool WriteBytes(IntPtr address, byte[] buffer)
|
||||||
{
|
{
|
||||||
|
if (Handle.IsClosed || Handle.IsInvalid)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (buffer.Length == 0)
|
if (buffer.Length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
@ -61,7 +72,7 @@ public static class SafeMemory
|
||||||
fixed (byte* p = buffer)
|
fixed (byte* p = buffer)
|
||||||
{
|
{
|
||||||
if (!Windows.Win32.PInvoke.WriteProcessMemory(
|
if (!Windows.Win32.PInvoke.WriteProcessMemory(
|
||||||
Handle,
|
(HANDLE)Handle.DangerousGetHandle(),
|
||||||
address.ToPointer(),
|
address.ToPointer(),
|
||||||
p,
|
p,
|
||||||
new UIntPtr((uint)buffer.Length),
|
new UIntPtr((uint)buffer.Length),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
using Windows.Win32.Foundation;
|
||||||
using Windows.Win32.Storage.FileSystem;
|
using Windows.Win32.Storage.FileSystem;
|
||||||
|
|
||||||
namespace Dalamud.Utility;
|
namespace Dalamud.Utility;
|
||||||
|
|
@ -61,8 +62,11 @@ public static class FilesystemUtil
|
||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
uint bytesWritten = 0;
|
uint bytesWritten = 0;
|
||||||
if (!Windows.Win32.PInvoke.WriteFile(tempFile, new ReadOnlySpan<byte>(bytes), &bytesWritten, null))
|
fixed (byte* ptr = bytes)
|
||||||
throw new Win32Exception();
|
{
|
||||||
|
if (!Windows.Win32.PInvoke.WriteFile((HANDLE)tempFile.DangerousGetHandle(), ptr, (uint)bytes.Length, &bytesWritten, null))
|
||||||
|
throw new Win32Exception();
|
||||||
|
}
|
||||||
|
|
||||||
if (bytesWritten != bytes.Length)
|
if (bytesWritten != bytes.Length)
|
||||||
throw new Exception($"Could not write all bytes to temp file ({bytesWritten} of {bytes.Length})");
|
throw new Exception($"Could not write all bytes to temp file ({bytesWritten} of {bytes.Length})");
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<!-- DirectX / Win32 -->
|
<!-- DirectX / Win32 -->
|
||||||
<PackageVersion Include="TerraFX.Interop.Windows" Version="10.0.26100.5" />
|
<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 -->
|
<!-- Logging -->
|
||||||
<PackageVersion Include="Serilog" Version="4.0.2" />
|
<PackageVersion Include="Serilog" Version="4.0.2" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue