Skip to content

Commit

Permalink
Fixes #427 - Bad impl of Kernel32.FILE_ID_128.Identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
dahall committed Sep 15, 2023
1 parent b580e8f commit 52a5454
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions PInvoke/Kernel32/WinBase.File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3961,11 +3961,11 @@ public struct FILE_FULL_DIR_INFO
// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_file_id_128 typedef struct _FILE_ID_128 { BYTE
// Identifier[16]; } FILE_ID_128, *PFILE_ID_128;
[PInvokeData("winnt.h", MSDNShortId = "254ea6a9-e1dd-4b97-91f7-2693065c4bb8")]
[StructLayout(LayoutKind.Sequential)]
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct FILE_ID_128
{
private readonly ulong id0;
private readonly ulong id1;
private ulong id0;
private ulong id1;

/// <summary>
/// <para>A byte array containing the 128 bit identifier.</para>
Expand All @@ -3974,13 +3974,16 @@ public byte[] Identifier
{
get
{
using PinnedObject pin = new(id0);
return ((IntPtr)pin).ToArray<byte>(16);
var ret = new byte[16];
BitConverter.GetBytes(id0).CopyTo(ret, 0);
BitConverter.GetBytes(id1).CopyTo(ret, 8);
return ret;
}
set
{
using PinnedObject pin = new(id0);
Marshal.Copy(value, 0, pin, 16);
if (value.Length != 16) throw new ArgumentOutOfRangeException("Array must be 16 bytes long.", nameof(value));
id0 = BitConverter.ToUInt64(value, 0);
id1 = BitConverter.ToUInt64(value, 8);
}
}
}
Expand Down

0 comments on commit 52a5454

Please sign in to comment.