Esempio n. 1
0
 public void OpenGlobalDosDeviceDirectory()
 {
     using (var directory = HandleMethods.OpenDirectoryObject(@"\Global??"))
     {
         directory.IsInvalid.Should().BeFalse();
     }
 }
Esempio n. 2
0
 public void OpenCDriveSymbolicLink()
 {
     using (var link = HandleMethods.OpenSymbolicLinkObject(@"\??\C:"))
     {
         link.IsInvalid.Should().BeFalse();
     }
 }
Esempio n. 3
0
 public void OpenRootDirectory()
 {
     using (var directory = HandleMethods.OpenDirectoryObject(@"\"))
     {
         directory.IsInvalid.Should().BeFalse();
     }
 }
Esempio n. 4
0
 public void GetTargetForCDriveSymbolicLink()
 {
     using (var link = HandleMethods.OpenSymbolicLinkObject(@"\??\C:"))
     {
         string target = HandleMethods.GetSymbolicLinkTarget(link);
         target.Should().StartWith(@"\Device\");
     }
 }
Esempio n. 5
0
        public void GetHandleTypeBasic()
        {
            string tempPath = FileMethods.GetTempPath();

            using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath))
            {
                string name = HandleMethods.GetObjectType(directory);
                name.Should().Be("File");
            }
        }
Esempio n. 6
0
 public void GetRootDirectoryEntries()
 {
     using (var directory = HandleMethods.OpenDirectoryObject(@"\"))
     {
         IEnumerable <ObjectInformation> objects = HandleMethods.GetDirectoryEntries(directory);
         objects.Should().NotBeEmpty();
         objects.Should().Contain(new ObjectInformation {
             Name = "Device", TypeName = "Directory"
         });
     }
 }
Esempio n. 7
0
        public void GetHandleNameBasic()
        {
            string tempPath = FileMethods.GetTempPath();

            using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath))
            {
                // This will give back the NT path (\Device\HarddiskVolumen...)
                string name = HandleMethods.GetObjectName(directory);

                // Skip past the C:\
                Paths.AddTrailingSeparator(name).Should().EndWith(tempPath.Substring(3));
            }
        }
Esempio n. 8
0
 public void NoMoreFiles()
 {
     _info = null;
     if (_pending == null || _pending.Count == 0)
     {
         _lastEntryFound = true;
     }
     else
     {
         // Grab the next directory to parse
         var next = _pending.Dequeue();
         HandleMethods.CloseHandle(_directory);
         _directory = next.Item1;
         _path      = next.Item2;
         FindNextFile();
     }
 }
Esempio n. 9
0
        public void QueryDosVolumePathBasic()
        {
            string tempPath = FileMethods.GetTempPath();

            using (var directory = DirectoryMethods.CreateDirectoryHandle(tempPath))
            {
                // This will give back the NT path (\Device\HarddiskVolumen...)
                string fullName   = HandleMethods.GetObjectName(directory);
                string fileName   = FileMethods.GetFileName(directory);
                string deviceName = fullName.Substring(0, fullName.Length - fileName.Length);

                string dosVolumePath = DeviceMethods.QueryDosVolumePath(deviceName);

                tempPath.Should().StartWith(dosVolumePath);
                tempPath.Should().Be(dosVolumePath + fileName + @"\");
            }
        }
Esempio n. 10
0
            protected void Dispose(bool disposing)
            {
                HeapBuffer buffer = Interlocked.Exchange(ref _buffer, null);

                if (buffer != null)
                {
                    StringBuffer.Cache.Release((StringBuffer)buffer);
                }

                var queue = Interlocked.Exchange(ref _pending, null);

                if (queue != null)
                {
                    while (queue.Count > 0)
                    {
                        HandleMethods.CloseHandle(queue.Dequeue().Item1);
                    }
                }

                HandleMethods.CloseHandle(_directory);
            }
Esempio n. 11
0
        public void GetPipeObjectInfo()
        {
            var fileHandle = FileMethods.CreateFileSystemIo(
                @"\\.\pipe\",
                0,                  // We don't care about read or write, we're just getting metadata with this handle
                System.IO.FileShare.ReadWrite,
                System.IO.FileMode.Open,
                0,
                FileFlags.OpenReparsePoint           // To avoid traversing links
                | FileFlags.BackupSemantics);        // To open directories

            string name = HandleMethods.GetObjectName(fileHandle);

            name.Should().Be(@"\Device\NamedPipe\");

            string typeName = HandleMethods.GetObjectType(fileHandle);

            typeName.Should().Be(@"File");

            string fileName = FileMethods.GetFileName(fileHandle);

            fileName.Should().Be(@"\");
        }
Esempio n. 12
0
        public void GetPipeObjectInfoNoTrailingSlash()
        {
            var fileHandle = FileMethods.CreateFileSystemIo(
                @"\\.\pipe",
                0,                  // We don't care about read or write, we're just getting metadata with this handle
                System.IO.FileShare.ReadWrite,
                System.IO.FileMode.Open,
                0,
                FileFlags.OpenReparsePoint           // To avoid traversing links
                | FileFlags.BackupSemantics);        // To open directories

            string name = HandleMethods.GetObjectName(fileHandle);

            name.Should().Be(@"\Device\NamedPipe");

            string typeName = HandleMethods.GetObjectType(fileHandle);

            typeName.Should().Be(@"File");

            // Not sure why this is- probably the source of why so many other things go wrong
            Action action = () => FileMethods.GetFileName(fileHandle);

            action.ShouldThrow <ArgumentException>().And.HResult.Should().Be(unchecked ((int)0x80070057));
        }
Esempio n. 13
0
 protected override bool ReleaseHandle()
 {
     HandleMethods.CloseHandle(handle);
     return(true);
 }