Skip to content

Instantly share code, notes, and snippets.

@angelovescio
Last active May 10, 2017 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovescio/84551fa3e9a49df2f036 to your computer and use it in GitHub Desktop.
Save angelovescio/84551fa3e9a49df2f036 to your computer and use it in GitHub Desktop.
C# NTFS EA Example
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct IO_STATUS_BLOCK
{
public uint status;
public IntPtr information;
}
[DllImport("ntdll.dll", ExactSpelling = true)]
public static extern uint NtQueryEaFile(
SafeFileHandle handle,
out IO_STATUS_BLOCK ioStatus,
IntPtr buffer,
uint length,
bool retSingleEntry,
IntPtr eaList,
uint eaListLength,
IntPtr eaIndex,
bool restartScan
);
void GetEa()
{
SafeFileHandle sfh = CreateFile("C:\\Toolz\\temp.txt", 8, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0x02000000, IntPtr.Zero);
IntPtr peaGet = Marshal.AllocHGlobal(1024*1024);
//Marshal.Copy(testArr, 0, peaGet, testArr.Length);
uint status = Ntfs.NtQueryEaFile(sfh, out ioStatusBlock, peaGet, 1024 * 1024, false, IntPtr.Zero, 0, IntPtr.Zero, true);
status = (uint)Marshal.GetLastWin32Error();
if (status != NT_SUCCESS)
{
ExitWithError(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment