瀏覽代碼

Implemented additional FileInformation structures

Tal Aloni 8 年之前
父節點
當前提交
bd76e6e5a2

+ 2 - 0
SMBLibrary/Enums/FileInformation/FileInformationClass.cs

@@ -13,6 +13,8 @@ namespace SMBLibrary
         FileStandardInformation = 0x05,        // Uses: Query
         FileInternalInformation = 0x06,        // Uses: Query
         FileEaInformation = 0x07,              // Uses: Query
+        FileAccessInformation = 0x08,          // Uses: Query
+        FileNameInformation = 0x09,            // Uses: LOCAL
         FileRenameInformation = 0x0A,          // Uses: Set
         FileLinkInformation = 0x0B,            // Uses: Set
         FileNamesInformation = 0x0C,           // Uses: Query

+ 7 - 0
SMBLibrary/SMBLibrary.csproj

@@ -489,11 +489,18 @@
     <Compile Include="Structures\ACE\Enums\AceType.cs" />
     <Compile Include="Structures\ACL.cs" />
     <Compile Include="Structures\FileInformation\FileInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileAccessInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileAlignmentInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileAllInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileAlternateNameInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileBasicInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileCompressionInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileEaInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileInternalInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileModeInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FileNameInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileNetworkOpenInformation.cs" />
+    <Compile Include="Structures\FileInformation\Query\FilePositionInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileStandardInformation.cs" />
     <Compile Include="Structures\FileInformation\Query\FileStreamInformation.cs" />
     <Compile Include="Structures\FileInformation\QueryDirectory\FileBothDirectoryInformation.cs" />

+ 8 - 6
SMBLibrary/Structures/FileInformation/FileInformation.cs

@@ -43,6 +43,8 @@ namespace SMBLibrary
                     return new FileInternalInformation(buffer, offset);
                 case FileInformationClass.FileEaInformation:
                     return new FileEaInformation(buffer, offset);
+                case FileInformationClass.FileAccessInformation:
+                    return new FileAccessInformation(buffer, offset);
                 case FileInformationClass.FileRenameInformation:
                     return new FileRenameInformationType2(buffer, offset);
                 case FileInformationClass.FileLinkInformation:
@@ -52,23 +54,23 @@ namespace SMBLibrary
                 case FileInformationClass.FileDispositionInformation:
                     return new FileDispositionInformation(buffer, offset);
                 case FileInformationClass.FilePositionInformation:
-                    throw new NotImplementedException();
+                    return new FilePositionInformation(buffer, offset);
                 case FileInformationClass.FileFullEaInformation:
                     return new FileFullEAInformation(buffer, offset);
                 case FileInformationClass.FileModeInformation:
                     return new FileModeInformation(buffer, offset);
                 case FileInformationClass.FileAlignmentInformation:
-                    throw new NotImplementedException();
+                    return new FileAlignmentInformation(buffer, offset);
                 case FileInformationClass.FileAllInformation:
-                    throw new NotImplementedException();
+                    return new FileAllInformation(buffer, offset);
                 case FileInformationClass.FileAllocationInformation:
                     return new FileAllocationInformation(buffer, offset);
                 case FileInformationClass.FileEndOfFileInformation:
                     return new FileEndOfFileInformation(buffer, offset);
                 case FileInformationClass.FileAlternateNameInformation:
-                    throw new NotImplementedException();
+                    return new FileAlternateNameInformation(buffer, offset);
                 case FileInformationClass.FileStreamInformation:
-                    throw new NotImplementedException();
+                    return new FileStreamInformation(buffer, offset);
                 case FileInformationClass.FilePipeInformation:
                     throw new NotImplementedException();
                 case FileInformationClass.FilePipeLocalInformation:
@@ -76,7 +78,7 @@ namespace SMBLibrary
                 case FileInformationClass.FilePipeRemoteInformation:
                     throw new NotImplementedException();
                 case FileInformationClass.FileCompressionInformation:
-                    throw new NotImplementedException();
+                    return new FileCompressionInformation(buffer, offset);
                 case FileInformationClass.FileNetworkOpenInformation:
                     return new FileNetworkOpenInformation(buffer, offset);
                 case FileInformationClass.FileAttributeTagInformation:

+ 52 - 0
SMBLibrary/Structures/FileInformation/Query/FileAccessInformation.cs

@@ -0,0 +1,52 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.1 - FileAccessInformation
+    /// </summary>
+    public class FileAccessInformation : FileInformation
+    {
+        public const int FixedLength = 4;
+
+        public AccessMask AccessFlags;
+
+        public FileAccessInformation()
+        {
+        }
+
+        public FileAccessInformation(byte[] buffer, int offset)
+        {
+            AccessFlags = (AccessMask)LittleEndianConverter.ToUInt32(buffer, offset + 0);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)AccessFlags);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileAccessInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return FixedLength;
+            }
+        }
+    }
+}

+ 52 - 0
SMBLibrary/Structures/FileInformation/Query/FileAlignmentInformation.cs

@@ -0,0 +1,52 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.3 - FileAlignmentInformation
+    /// </summary>
+    public class FileAlignmentInformation : FileInformation
+    {
+        public const int FixedLength = 4;
+
+        public uint AlignmentRequirement;
+
+        public FileAlignmentInformation()
+        {
+        }
+
+        public FileAlignmentInformation(byte[] buffer, int offset)
+        {
+            AlignmentRequirement = LittleEndianConverter.ToUInt32(buffer, offset + 0);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            LittleEndianWriter.WriteUInt32(buffer, offset + 0, AlignmentRequirement);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileAlignmentInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return FixedLength;
+            }
+        }
+    }
+}

+ 74 - 0
SMBLibrary/Structures/FileInformation/Query/FileAllInformation.cs

@@ -0,0 +1,74 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.2 - FileAllInformation
+    /// </summary>
+    public class FileAllInformation : FileInformation
+    {
+        public FileBasicInformation BasicInformation;
+        public FileStandardInformation StandardInformation;
+        public FileInternalInformation InternalInformation;
+        public FileEaInformation EaInformation;
+        public FileAccessInformation AccessInformation;
+        public FilePositionInformation PositionInformation;
+        public FileModeInformation ModeInformation;
+        public FileAlignmentInformation AlignmentInformation;
+        public FileNameInformation NameInformation;
+
+        public FileAllInformation()
+        {
+        }
+
+        public FileAllInformation(byte[] buffer, int offset)
+        {
+            BasicInformation = new FileBasicInformation(buffer, offset + 0);
+            StandardInformation = new FileStandardInformation(buffer, offset + 40);
+            InternalInformation = new FileInternalInformation(buffer, offset + 64);
+            EaInformation = new FileEaInformation(buffer, offset + 72);
+            AccessInformation = new FileAccessInformation(buffer, offset + 76);
+            PositionInformation = new FilePositionInformation(buffer, offset + 80);
+            ModeInformation = new FileModeInformation(buffer, offset + 88);
+            AlignmentInformation = new FileAlignmentInformation(buffer, offset + 92);
+            NameInformation = new FileNameInformation(buffer, offset + 96);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            BasicInformation.WriteBytes(buffer, offset + 0);
+            StandardInformation.WriteBytes(buffer, offset + 40);
+            InternalInformation.WriteBytes(buffer, offset + 64);
+            EaInformation.WriteBytes(buffer, offset + 72);
+            AccessInformation.WriteBytes(buffer, offset + 76);
+            PositionInformation.WriteBytes(buffer, offset + 80);
+            ModeInformation.WriteBytes(buffer, offset + 88);
+            AlignmentInformation.WriteBytes(buffer, offset + 92);
+            NameInformation.WriteBytes(buffer, offset + 96);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileAllInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return 96 + NameInformation.Length;
+            }
+        }
+    }
+}

+ 34 - 0
SMBLibrary/Structures/FileInformation/Query/FileAlternateNameInformation.cs

@@ -0,0 +1,34 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.5 - FileAlternateNameInformation
+    /// </summary>
+    public class FileAlternateNameInformation : FileNameInformation
+    {
+        public FileAlternateNameInformation() : base()
+        {
+        }
+
+        public FileAlternateNameInformation(byte[] buffer, int offset) : base(buffer, offset)
+        {
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileAlternateNameInformation;
+            }
+        }
+    }
+}

+ 67 - 0
SMBLibrary/Structures/FileInformation/Query/FileCompressionInformation.cs

@@ -0,0 +1,67 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.9 - FileCompressionInformation
+    /// </summary>
+    public class FileCompressionInformation : FileInformation
+    {
+        public const int FixedLength = 16;
+
+        public ulong CompressedFileSize;
+        public CompressionFormat CompressionFormat;
+        public byte CompressionUnitShift;
+        public byte ChunkShift;
+        public byte ClusterShift;
+        public byte[] Reserved; // 3 bytes
+
+        public FileCompressionInformation()
+        {
+        }
+
+        public FileCompressionInformation(byte[] buffer, int offset)
+        {
+            CompressedFileSize = LittleEndianConverter.ToUInt64(buffer, offset + 0);
+            CompressionFormat = (CompressionFormat)LittleEndianConverter.ToUInt16(buffer, offset + 8);
+            CompressionUnitShift = ByteReader.ReadByte(buffer, offset + 10);
+            ChunkShift = ByteReader.ReadByte(buffer, offset + 11);
+            ClusterShift = ByteReader.ReadByte(buffer, offset + 12);
+            Reserved = ByteReader.ReadBytes(buffer, offset + 13, 3);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            LittleEndianWriter.WriteUInt64(buffer, offset + 0, CompressedFileSize);
+            LittleEndianWriter.WriteUInt16(buffer, offset + 8, (ushort)CompressionFormat);
+            ByteWriter.WriteByte(buffer, offset + 10, CompressionUnitShift);
+            ByteWriter.WriteByte(buffer, offset + 11, ChunkShift);
+            ByteWriter.WriteByte(buffer, offset + 12, ClusterShift);
+            ByteWriter.WriteBytes(buffer, offset + 13, Reserved, 3);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileCompressionInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return FixedLength;
+            }
+        }
+    }
+}

+ 57 - 0
SMBLibrary/Structures/FileInformation/Query/FileNameInformation.cs

@@ -0,0 +1,57 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.1.7 - FILE_NAME_INFORMATION
+    /// [MS-FSCC] 2.4.25 - FileNameInformation
+    /// </summary>
+    public class FileNameInformation : FileInformation
+    {
+        public const int FixedLength = 4;
+
+        private uint FileNameLength;
+        public string FileName = String.Empty;
+
+        public FileNameInformation()
+        {
+        }
+
+        public FileNameInformation(byte[] buffer, int offset)
+        {
+            FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 0);
+            FileName = ByteReader.ReadUTF16String(buffer, offset + 4, (int)FileNameLength / 2);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            FileNameLength = (uint)(FileName.Length * 2);
+            LittleEndianWriter.WriteUInt32(buffer, offset + 0, FileNameLength);
+            ByteWriter.WriteUTF16String(buffer, offset + 4, FileName);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FileNameInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return FixedLength + FileName.Length * 2;
+            }
+        }
+    }
+}

+ 52 - 0
SMBLibrary/Structures/FileInformation/Query/FilePositionInformation.cs

@@ -0,0 +1,52 @@
+/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using Utilities;
+
+namespace SMBLibrary
+{
+    /// <summary>
+    /// [MS-FSCC] 2.4.32 - FilePositionInformation
+    /// </summary>
+    public class FilePositionInformation : FileInformation
+    {
+        public const int FixedLength = 8;
+
+        public long CurrentByteOffset;
+
+        public FilePositionInformation()
+        {
+        }
+
+        public FilePositionInformation(byte[] buffer, int offset)
+        {
+            CurrentByteOffset = LittleEndianConverter.ToInt64(buffer, offset + 0);
+        }
+
+        public override void WriteBytes(byte[] buffer, int offset)
+        {
+            LittleEndianWriter.WriteInt64(buffer, offset + 0, CurrentByteOffset);
+        }
+
+        public override FileInformationClass FileInformationClass
+        {
+            get
+            {
+                return FileInformationClass.FilePositionInformation;
+            }
+        }
+
+        public override int Length
+        {
+            get
+            {
+                return FixedLength;
+            }
+        }
+    }
+}