Exemple #1
0
 internal static extern NTSTATUS NtQueryDirectoryFile(
     SafeFileHandle fileHandle,
     IntPtr eventHandle,
     IntPtr apcRoutime,
     IntPtr appContext,
     ref IO_STATUS_BLOCK ioStatusBlock,
     IntPtr FileInformation,
     UInt32 length,
     FILE_INFORMATION_CLASS fileInformationClass,
     [MarshalAs(UnmanagedType.Bool)] bool returnSingleEntry,
     IntPtr fileName,
     [MarshalAs(UnmanagedType.Bool)] bool restartScan);
 public static unsafe extern int NtQueryDirectoryFile(
     IntPtr FileHandle,
     IntPtr Event,
     IntPtr ApcRoutine,
     IntPtr ApcContext,
     IO_STATUS_BLOCK *IoStatusBlock,
     IntPtr FileInformation,
     uint Length,
     FILE_INFORMATION_CLASS FileInformationClass,
     BOOLEAN ReturnSingleEntry,
     UNICODE_STRING *FileName,
     BOOLEAN RestartScan);
Exemple #3
0
        unsafe private static void GetFileInformation(SafeFileHandle fileHandle, FILE_INFORMATION_CLASS fileInformationClass, void *value, uint size)
        {
            IO_STATUS_BLOCK ioStatus;

            NTSTATUS status = Direct.NtQueryInformationFile(
                FileHandle: fileHandle,
                IoStatusBlock: out ioStatus,
                FileInformation: value,
                Length: size,
                FileInformationClass: fileInformationClass);

            if (status != NTSTATUS.STATUS_SUCCESS)
            {
                throw ErrorHelper.GetIoExceptionForNTStatus(status);
            }
        }
Exemple #4
0
        private static string GetFileInformationString(SafeFileHandle fileHandle, FILE_INFORMATION_CLASS fileInformationClass)
        {
            return(BufferHelper.CachedInvoke((StringBuffer buffer) =>
            {
                NTSTATUS status = NTSTATUS.STATUS_BUFFER_OVERFLOW;
                uint nameLength = 260 * sizeof(char);

                IO_STATUS_BLOCK ioStatus;
                var reader = new CheckedReader(buffer);

                while (status == NTSTATUS.STATUS_BUFFER_OVERFLOW)
                {
                    // Add space for the FileNameLength
                    buffer.EnsureByteCapacity(nameLength + sizeof(uint));

                    unsafe
                    {
                        status = Direct.NtQueryInformationFile(
                            FileHandle: fileHandle,
                            IoStatusBlock: out ioStatus,
                            FileInformation: buffer.VoidPointer,
                            Length: checked ((uint)buffer.ByteCapacity),
                            FileInformationClass: fileInformationClass);
                    }

                    if (status == NTSTATUS.STATUS_SUCCESS || status == NTSTATUS.STATUS_BUFFER_OVERFLOW)
                    {
                        reader.ByteOffset = 0;
                        nameLength = reader.ReadUint();
                    }
                }

                if (status != NTSTATUS.STATUS_SUCCESS)
                {
                    throw ErrorHelper.GetIoExceptionForNTStatus(status);
                }

                // The string isn't null terminated so we have to explicitly pass the size
                return reader.ReadString(checked ((int)nameLength) / sizeof(char));
            }));
        }
 private static extern NTSTATUS NtQueryInformationFile(IntPtr FileHandle,
     ref IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, int FileInformationLength, 
     FILE_INFORMATION_CLASS FileInformationClass);
Exemple #6
0
 public static extern int NtSetInformationFile(
     SafeFileHandle FileHandle,
     ref IO_STATUS_BLOCK ioStatus,
     IntPtr FileInformation,
     Int32 Length,
     FILE_INFORMATION_CLASS fileClass);
Exemple #7
0
 public static extern IntPtr NtQueryInformationFile(IntPtr fileHandle, ref IO_STATUS_BLOCK IoStatusBlock, IntPtr pInfoBlock, uint length, FILE_INFORMATION_CLASS fileInformation);
Exemple #8
0
 private static extern NTSTATUS NtQueryInformationFile(IntPtr FileHandle,
                                                       ref IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, int FileInformationLength,
                                                       FILE_INFORMATION_CLASS FileInformationClass);
 public static extern NTSTATUS NtSetInformationFile(
     IntPtr FileHandle,
     ref IO_STATUS_BLOCK IoStatusBlock,
     ref FILE_CASE_SENSITIVE_INFORMATION FileInformation,
     int Length,
     FILE_INFORMATION_CLASS FileInformationClass);
Exemple #10
0
 unsafe public static extern NTSTATUS NtQueryInformationFile(
     SafeFileHandle FileHandle,
     out IO_STATUS_BLOCK IoStatusBlock,
     void *FileInformation,
     uint Length,
     FILE_INFORMATION_CLASS FileInformationClass);
Exemple #11
0
      public static extern uint NtQueryInformationFile(SafeFileHandle FileHandle,
 ref IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, uint Length,
 FILE_INFORMATION_CLASS FileInformationClass);
 static extern Int32 NtQueryInformationFile(SafeHandle handle, out IO_STATUS_BLOCK ioStatusBlock,
                                            out FILE_STANDARD_INFORMATION info, Int32 length, FILE_INFORMATION_CLASS fileInformationClass);
 static extern uint NtSetInformationFile(IntPtr FileHandle,
                                         IO_STATUS_BLOCK IoStatusBlock,
                                         IntPtr FileInformation,
                                         uint Length,
                                         FILE_INFORMATION_CLASS FileInformationClass);
 public static extern IntPtr NtQueryInformationFile(IntPtr fileHandle, ref IO_STATUS_BLOCK IoStatusBlock, IntPtr pInfoBlock, uint length, FILE_INFORMATION_CLASS fileInformation);
Exemple #15
0
 internal static extern uint NtQueryInformationFile(SafeFileHandle fileHandle, ref IO_STATUS_BLOCK IoStatusBlock,
                                                    IntPtr pInfoBlock, uint length, FILE_INFORMATION_CLASS fileInformation);