예제 #1
0
        public NTStatus QueryDirectory(out List <QueryDirectoryFileInformation> result, object handle, string fileName, FileInformationClass informationClass)
        {
            IO_STATUS_BLOCK ioStatusBlock;

            byte[]         buffer            = new byte[4096];
            UNICODE_STRING fileNameStructure = new UNICODE_STRING(fileName);

            result = new List <QueryDirectoryFileInformation>();
            bool restartScan = true;

            while (true)
            {
                NTStatus status = NtQueryDirectoryFile((IntPtr)handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out ioStatusBlock, buffer, (uint)buffer.Length, (byte)informationClass, false, ref fileNameStructure, restartScan);
                if (status == NTStatus.STATUS_NO_MORE_FILES)
                {
                    break;
                }
                else if (status != NTStatus.STATUS_SUCCESS)
                {
                    return(status);
                }
                int numberOfBytesWritten = (int)ioStatusBlock.Information;
                buffer = ByteReader.ReadBytes(buffer, 0, numberOfBytesWritten);
                List <QueryDirectoryFileInformation> page = QueryDirectoryFileInformation.ReadFileInformationList(buffer, 0, informationClass);
                result.AddRange(page);
                restartScan = false;
            }
            fileNameStructure.Dispose();
            return(NTStatus.STATUS_SUCCESS);
        }
예제 #2
0
        public List <QueryDirectoryFileInformation> GetFileInformationList(FileInformationClass fileInformationClass)
        {
            if (OutputBuffer.Length > 0)
            {
                return(QueryDirectoryFileInformation.ReadFileInformationList(OutputBuffer, 0, fileInformationClass));
            }

            return(new List <QueryDirectoryFileInformation>());
        }