Ejemplo n.º 1
0
        public void GetHandleNameBasic()
        {
            string tempPath = FileMethods.GetTempPath();

            using (var directory = FileMethods.CreateFile(tempPath, DesiredAccess.GENERIC_READ, ShareMode.FILE_SHARE_READWRITE, CreationDisposition.OPEN_EXISTING,
                                                          FileAttributes.NONE, FileFlags.FILE_FLAG_BACKUP_SEMANTICS))
            {
                // This will give back the NT path (\Device\HarddiskVolumen...)
                string name = HandleDesktopMethods.GetObjectName(directory);

                // Skip past the C:\
                Paths.AddTrailingSeparator(name).Should().EndWith(tempPath.Substring(3));
            }
        }
Ejemplo n.º 2
0
        public void QueryDosVolumePathBasic()
        {
            string tempPath = FileMethods.GetTempPath();

            using (var directory = FileMethods.CreateFile(tempPath, DesiredAccess.GENERIC_READ, ShareMode.FILE_SHARE_READWRITE, CreationDisposition.OPEN_EXISTING,
                                                          FileAttributes.NONE, FileFlags.FILE_FLAG_BACKUP_SEMANTICS))
            {
                // This will give back the NT path (\Device\HarddiskVolumen...)
                string fullName   = HandleDesktopMethods.GetObjectName(directory);
                string fileName   = FileMethods.GetFileNameByHandle(directory);
                string deviceName = fullName.Substring(0, fullName.Length - fileName.Length);

                string dosVolumePath = DeviceDesktopMethods.QueryDosVolumePath(deviceName);

                tempPath.Should().StartWith(dosVolumePath);
                tempPath.Should().Be(dosVolumePath + fileName + @"\");
            }
        }
Ejemplo n.º 3
0
        public void GetPipeObjectInfo()
        {
            var fileHandle = FileMethods.CreateFile(
                @"\\.\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.FILE_FLAG_OPEN_REPARSE_POINT          // To avoid traversing links
                | FileFlags.FILE_FLAG_BACKUP_SEMANTICS);        // To open directories

            string name = HandleDesktopMethods.GetObjectName(fileHandle);

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

            string typeName = HandleDesktopMethods.GetObjectType(fileHandle);

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

            string fileName = FileMethods.GetFileNameByHandle(fileHandle);

            fileName.Should().Be(@"\");
        }
Ejemplo n.º 4
0
        public void GetPipeObjectInfoNoTrailingSlash()
        {
            var fileHandle = FileMethods.CreateFile(
                @"\\.\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.FILE_FLAG_OPEN_REPARSE_POINT          // To avoid traversing links
                | FileFlags.FILE_FLAG_BACKUP_SEMANTICS);        // To open directories

            string name = HandleDesktopMethods.GetObjectName(fileHandle);

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

            string typeName = HandleDesktopMethods.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.GetFileNameByHandle(fileHandle);

            action.ShouldThrow <ArgumentException>().And.HResult.Should().Be(unchecked ((int)0x80070057));
        }