diff --git a/SMBLibrary/Enums/FileAttributes.cs b/SMBLibrary/Enums/FileAttributes.cs new file mode 100644 index 0000000..5acc8ad --- /dev/null +++ b/SMBLibrary/Enums/FileAttributes.cs @@ -0,0 +1,32 @@ +using System; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.6 - FileAttributes + /// + [Flags] + public enum FileAttributes : uint + { + ReadOnly = 0x00000001, // FILE_ATTRIBUTE_READONLY + Hidden = 0x00000002, // FILE_ATTRIBUTE_HIDDEN + System = 0x00000004, // FILE_ATTRIBUTE_SYSTEM + Directory = 0x00000010, // FILE_ATTRIBUTE_DIRECTORY + Archive = 0x00000020, // FILE_ATTRIBUTE_ARCHIVE + + /// + /// A file that does not have other attributes set. + /// This attribute is valid only when used alone. + /// + Normal = 0x00000080, // FILE_ATTRIBUTE_NORMAL + Temporary = 0x00000100, // FILE_ATTRIBUTE_TEMPORARY + SparseFile = 0x00000200, // FILE_ATTRIBUTE_SPARSE_FILE + ReparsePoint = 0x00000400, // FILE_ATTRIBUTE_REPARSE_POINT + Compressed = 0x00000800, // FILE_ATTRIBUTE_COMPRESSED + Offline = 0x00001000, // FILE_ATTRIBUTE_OFFLINE + NotContentIndexed = 0x00002000, // FILE_ATTRIBUTE_NOT_CONTENT_INDEXED + Encrypted = 0x00004000, // FILE_ATTRIBUTE_ENCRYPTED + IntegrityStream = 0x00008000, // FILE_ATTRIBUTE_INTEGRITY_STREAM + NoScrubData = 0x00020000, // FILE_ATTRIBUTE_NO_SCRUB_DATA + } +} diff --git a/SMBLibrary/Enums/FileInformationClass.cs b/SMBLibrary/Enums/FileInformationClass.cs new file mode 100644 index 0000000..c53f847 --- /dev/null +++ b/SMBLibrary/Enums/FileInformationClass.cs @@ -0,0 +1,40 @@ + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4 - File Information Classes + /// + public enum FileInformationClass : byte + { + FileDirectoryInformation = 0x01, // Uses: Query + FileFullDirectoryInformation = 0x02, // Uses: Query + FileBothDirectoryInformation = 0x03, // Uses: Query + FileBasicInformation = 0x04, // Uses: Query, Set + FileStandardInformation = 0x05, // Uses: Query + FileInternalInformation = 0x06, // Uses: Query + FileEaInformation = 0x07, // Uses: Query + FileRenameInformation = 0x0A, // Uses: Set + FileLinkInformation = 0x0B, // Uses: Set + FileNamesInformation = 0x0C, // Uses: Query + FileDispositionInformation = 0x0D, // Uses: Set + FilePositionInformation = 0x0E, // Uses: Query, Set + FileFullEaInformation = 0x0F, // Uses: Query, Set + FileModeInformation = 0x10, // Uses: Query, Set + FileAlignmentInformation = 0x11, // Uses: Query + FileAllInformation = 0x12, // Uses: Query + FileAllocationInformation = 0x13, // Uses: Set + FileEndOfFileInformation = 0x14, // Uses: Set + FileAlternateNameInformation = 0x15, // Uses: Query + FileStreamInformation = 0x16, // Uses: Query + FilePipeInformation = 0x17, // Uses: Query, Set + FilePipeLocalInformation = 0x18, // Uses: Query + FilePipeRemoteInformation = 0x19, // Uses: Query + FileCompressionInformation = 0x1C, // Uses: Query + FileNetworkOpenInformation = 0x22, // Uses: Query + FileAttributeTagInformation = 0x23, // Uses: Query + FileIdBothDirectoryInformation = 0x25, // Uses: Query + FileIdFullDirectoryInformation = 0x26, // Uses: Query + FileValidDataLengthInformation = 0x27, // Uses: Set + FileShortNameInformation = 0x28, // Uses: Set + } +} diff --git a/SMBLibrary/Enums/FileSystemInformation/FileSystemControlFlags.cs b/SMBLibrary/Enums/FileSystemInformation/FileSystemControlFlags.cs new file mode 100644 index 0000000..9e97e06 --- /dev/null +++ b/SMBLibrary/Enums/FileSystemInformation/FileSystemControlFlags.cs @@ -0,0 +1,16 @@ + +namespace SMBLibrary +{ + public enum FileSystemControlFlags : uint + { + QuotaTrack = 0x00000001, // FILE_VC_QUOTA_TRACK + QuotaEnforce = 0x00000002, // FILE_VC_QUOTA_ENFORCE + ContentIndexingDisabled = 0x00000008, // FILE_VC_CONTENT_INDEX_DISABLED + LogQuotaThreshold = 0x00000010, // FILE_VC_LOG_QUOTA_THRESHOLD + LogQuotaLimit = 0x00000020, // FILE_VC_LOG_QUOTA_LIMIT + LogVolumeThreshold = 0x00000040, // FILE_VC_LOG_VOLUME_THRESHOLD + LogVolumeLimit = 0x00000080, // FILE_VC_LOG_VOLUME_LIMIT + QuotasIncomplete = 0x00000100, // FILE_VC_QUOTAS_INCOMPLETE + QuotasRebuilding = 0x00000200, // FILE_VC_QUOTAS_REBUILDING + } +} diff --git a/SMBLibrary/Enums/FileSystemInformation/FileSystemInformationClass.cs b/SMBLibrary/Enums/FileSystemInformation/FileSystemInformationClass.cs new file mode 100644 index 0000000..30b3fbf --- /dev/null +++ b/SMBLibrary/Enums/FileSystemInformation/FileSystemInformationClass.cs @@ -0,0 +1,21 @@ + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.5 - File System Information Classes + /// + public enum FileSystemInformationClass : byte + { + FileFsVolumeInformation = 0x01, // Uses: Query + FileFsLabelInformation = 0x02, + FileFsSizeInformation = 0x03, // Uses: Query + FileFsDeviceInformation = 0x04, // Uses: Query + FileFsAttributeInformation = 0x05, // Uses: Query + FileFsControlInformation = 0x06, // Uses: Query, Set + FileFsFullSizeInformation = 0x07, // Uses: Query + FileFsObjectIdInformation = 0x08, // Uses: Query, Set + FileFsDriverPathInformation = 0x09, + FileFsVolumeFlagsInformation = 0x0A, + FileFsSectorSizeInformation = 0x0B, // Uses: Query + } +} diff --git a/SMBLibrary/Enums/FileSystemInformation/SectorSizeInformationFlags.cs b/SMBLibrary/Enums/FileSystemInformation/SectorSizeInformationFlags.cs new file mode 100644 index 0000000..7720a44 --- /dev/null +++ b/SMBLibrary/Enums/FileSystemInformation/SectorSizeInformationFlags.cs @@ -0,0 +1,13 @@ +using System; + +namespace SMBLibrary +{ + [Flags] + public enum SectorSizeInformationFlags : uint + { + AlignedDevice = 0x00000001, // SSINFO_FLAGS_ALIGNED_DEVICE + PartitionAlignedOnDevice = 0x00000002, // SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE + NoSeekPenalty = 0x0000004, // SSINFO_FLAGS_NO_SEEK_PENALTY + TrimEnabled = 0x00000008, // SSINFO_FLAGS_TRIM_ENABLED + } +} diff --git a/SMBLibrary/SMBLibrary.csproj b/SMBLibrary/SMBLibrary.csproj index 48f2e3b..80fe48f 100644 --- a/SMBLibrary/SMBLibrary.csproj +++ b/SMBLibrary/SMBLibrary.csproj @@ -49,9 +49,14 @@ + + + + + @@ -399,7 +404,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SMBLibrary/Structures/FileInformation/FileInformation.cs b/SMBLibrary/Structures/FileInformation/FileInformation.cs new file mode 100644 index 0000000..a0488f4 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/FileInformation.cs @@ -0,0 +1,93 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + public abstract class FileInformation + { + public abstract void WriteBytes(byte[] buffer, int offset); + + public byte[] GetBytes() + { + byte[] buffer = new byte[this.Length]; + WriteBytes(buffer, 0); + return buffer; + } + + public abstract FileInformationClass FileInformationClass + { + get; + } + + public abstract int Length + { + get; + } + + public static FileInformation GetFileInformation(byte[] buffer, int offset, FileInformationClass informationClass) + { + switch (informationClass) + { + case FileInformationClass.FileBasicInformation: + return new FileBasicInformation(buffer, offset); + case FileInformationClass.FileStandardInformation: + return new FileStandardInformation(buffer, offset); + case FileInformationClass.FileInternalInformation: + return new FileInternalInformation(buffer, offset); + case FileInformationClass.FileEaInformation: + return new FileEaInformation(buffer, offset); + case FileInformationClass.FileRenameInformation: + return new FileRenameInformationType2(buffer, offset); + case FileInformationClass.FileLinkInformation: + return new FileLinkInformationType2(buffer, offset); + case FileInformationClass.FileNamesInformation: + throw new NotImplementedException(); + case FileInformationClass.FileDispositionInformation: + return new FileDispositionInformation(buffer, offset); + case FileInformationClass.FilePositionInformation: + throw new NotImplementedException(); + case FileInformationClass.FileFullEaInformation: + return new FileFullEAInformation(buffer, offset); + case FileInformationClass.FileModeInformation: + return new FileModeInformation(buffer, offset); + case FileInformationClass.FileAlignmentInformation: + throw new NotImplementedException(); + case FileInformationClass.FileAllInformation: + throw new NotImplementedException(); + case FileInformationClass.FileAllocationInformation: + return new FileAllocationInformation(buffer, offset); + case FileInformationClass.FileEndOfFileInformation: + return new FileEndOfFileInformation(buffer, offset); + case FileInformationClass.FileAlternateNameInformation: + throw new NotImplementedException(); + case FileInformationClass.FileStreamInformation: + throw new NotImplementedException(); + case FileInformationClass.FilePipeInformation: + throw new NotImplementedException(); + case FileInformationClass.FilePipeLocalInformation: + throw new NotImplementedException(); + case FileInformationClass.FilePipeRemoteInformation: + throw new NotImplementedException(); + case FileInformationClass.FileCompressionInformation: + throw new NotImplementedException(); + case FileInformationClass.FileNetworkOpenInformation: + return new FileNetworkOpenInformation(buffer, offset); + case FileInformationClass.FileAttributeTagInformation: + throw new NotImplementedException(); + case FileInformationClass.FileValidDataLengthInformation: + return new FileValidDataLengthInformation(buffer, offset); + case FileInformationClass.FileShortNameInformation: + throw new NotImplementedException(); + default: + throw new UnsupportedInformationLevelException(); + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileBasicInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileBasicInformation.cs new file mode 100644 index 0000000..f070448 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileBasicInformation.cs @@ -0,0 +1,67 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.7 - FileBasicInformation + /// + public class FileBasicInformation : FileInformation + { + public const int FixedLength = 40; + + public DateTime? CreationTime; + public DateTime? LastAccessTime; + public DateTime? LastWriteTime; + public DateTime? ChangeTime; + public FileAttributes FileAttributes; + public uint Reserved; + + public FileBasicInformation() + { + } + + public FileBasicInformation(byte[] buffer, int offset) + { + CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0); + LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 8); + LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 16); + ChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 24); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 32); + Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 36); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + FileTimeHelper.WriteFileTime(buffer, offset + 0, CreationTime); + FileTimeHelper.WriteFileTime(buffer, offset + 8, LastAccessTime); + FileTimeHelper.WriteFileTime(buffer, offset + 16, LastWriteTime); + FileTimeHelper.WriteFileTime(buffer, offset + 24, ChangeTime); + LittleEndianWriter.WriteUInt32(buffer, offset + 32, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 36, Reserved); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileBasicInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileEaInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileEaInformation.cs new file mode 100644 index 0000000..26cb860 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileEaInformation.cs @@ -0,0 +1,52 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.12 - FileEaInformation + /// + public class FileEaInformation : FileInformation + { + public const int FixedLength = 4; + + public uint EaSize; + + public FileEaInformation() + { + } + + public FileEaInformation(byte[] buffer, int offset) + { + EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 0); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, offset + 0, EaSize); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileEaInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileInternalInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileInternalInformation.cs new file mode 100644 index 0000000..212b0ee --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileInternalInformation.cs @@ -0,0 +1,52 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.20 - FileInternalInformation + /// + public class FileInternalInformation : FileInformation + { + public const int FixedLength = 8; + + public long IndexNumber; + + public FileInternalInformation() + { + } + + public FileInternalInformation(byte[] buffer, int offset) + { + IndexNumber = LittleEndianConverter.ToInt64(buffer, offset + 0); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteInt64(buffer, offset + 0, IndexNumber); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileInternalInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileModeInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileModeInformation.cs new file mode 100644 index 0000000..aa546df --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileModeInformation.cs @@ -0,0 +1,52 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.24 - FileModeInformation + /// + public class FileModeInformation : FileInformation + { + public const int FixedSize = 4; + + public CreateOptions FileMode; + + public FileModeInformation() + { + } + + public FileModeInformation(byte[] buffer, int offset) + { + FileMode = (CreateOptions)LittleEndianConverter.ToUInt32(buffer, offset + 0); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, offset, (uint)FileMode); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileModeInformation; + } + } + + public override int Length + { + get + { + return FixedSize; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileNetworkOpenInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileNetworkOpenInformation.cs new file mode 100644 index 0000000..555fbc8 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileNetworkOpenInformation.cs @@ -0,0 +1,73 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.12 - FileNetworkOpenInformation + /// + public class FileNetworkOpenInformation : FileInformation + { + public const int FixedLength = 56; + + public DateTime? CreationTime; + public DateTime? LastAccessTime; + public DateTime? LastWriteTime; + public DateTime? ChangeTime; + public ulong AllocationSize; + public ulong EndOfFile; + public FileAttributes FileAttributes; + public uint Reserved; + + public FileNetworkOpenInformation() + { + } + + public FileNetworkOpenInformation(byte[] buffer, int offset) + { + CreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0); + LastAccessTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 8); + LastWriteTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 16); + ChangeTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 24); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 32); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 48); + Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 52); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + FileTimeHelper.WriteFileTime(buffer, offset + 0, CreationTime); + FileTimeHelper.WriteFileTime(buffer, offset + 8, LastAccessTime); + FileTimeHelper.WriteFileTime(buffer, offset + 16, LastWriteTime); + FileTimeHelper.WriteFileTime(buffer, offset + 24, ChangeTime); + LittleEndianWriter.WriteUInt64(buffer, offset + 32, AllocationSize); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt32(buffer, offset + 48, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 52, Reserved); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileNetworkOpenInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileStandardInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileStandardInformation.cs new file mode 100644 index 0000000..9503330 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileStandardInformation.cs @@ -0,0 +1,67 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.38 - FileStandardInformation + /// + public class FileStandardInformation : FileInformation + { + public const int FixedLength = 24; + + public ulong AllocationSize; + public ulong EndOfFile; + public uint NumberOfLinks; + public bool DeletePending; + public bool Directory; + public ushort Reserved; + + public FileStandardInformation() + { + } + + public FileStandardInformation(byte[] buffer, int offset) + { + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 0); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 8); + NumberOfLinks = LittleEndianConverter.ToUInt32(buffer, offset + 16); + DeletePending = (ByteReader.ReadByte(buffer, offset + 20) > 0); + Directory = (ByteReader.ReadByte(buffer, offset + 21) > 0); + Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 22); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt64(buffer, offset + 0, AllocationSize); + LittleEndianWriter.WriteUInt64(buffer, offset + 8, EndOfFile); + LittleEndianWriter.WriteUInt32(buffer, offset + 16, NumberOfLinks); + ByteWriter.WriteByte(buffer, offset + 20, Convert.ToByte(DeletePending)); + ByteWriter.WriteByte(buffer, offset + 21, Convert.ToByte(Directory)); + LittleEndianWriter.WriteUInt16(buffer, offset + 22, Reserved); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileStandardInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Query/FileStreamInformation.cs b/SMBLibrary/Structures/FileInformation/Query/FileStreamInformation.cs new file mode 100644 index 0000000..b444c8b --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Query/FileStreamInformation.cs @@ -0,0 +1,66 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.40 - FileStreamInformation + /// + public class FileStreamInformation : FileInformation + { + public const int FixedLength = 24; + + public uint NextEntryOffset; + private uint StreamNameLength; + public ulong StreamSize; + public ulong StreamAllocationSize; + public string StreamName = String.Empty; + + public FileStreamInformation() + { + } + + public FileStreamInformation(byte[] buffer, int offset) + { + NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0); + StreamNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4); + StreamSize = LittleEndianConverter.ToUInt64(buffer, offset + 8); + StreamAllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 16); + ByteReader.ReadUTF16String(buffer, offset + 24, (int)StreamNameLength / 2); + + } + + public override void WriteBytes(byte[] buffer, int offset) + { + StreamNameLength = (uint)(StreamName.Length * 2); + LittleEndianWriter.WriteUInt32(buffer, offset + 0, NextEntryOffset); + LittleEndianWriter.WriteUInt32(buffer, offset + 4, StreamNameLength); + LittleEndianWriter.WriteUInt64(buffer, offset + 8, StreamSize); + LittleEndianWriter.WriteUInt64(buffer, offset + 16, StreamAllocationSize); + ByteWriter.WriteUTF16String(buffer, offset + 24, StreamName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileStreamInformation; + } + } + + public override int Length + { + get + { + return FixedLength + StreamName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileBothDirectoryInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileBothDirectoryInformation.cs new file mode 100644 index 0000000..8c90f3a --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileBothDirectoryInformation.cs @@ -0,0 +1,91 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.8 - FileBothDirectoryInformation + /// + public class FileBothDirectoryInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 94; + + public DateTime CreationTime; + public DateTime LastAccessTime; + public DateTime LastWriteTime; + public DateTime ChangeTime; + public ulong EndOfFile; + public ulong AllocationSize; + public FileAttributes FileAttributes; + private uint FileNameLength; + public uint EaSize; + private byte ShortNameLength; + public byte Reserved; + public string ShortName = String.Empty; // Short (8.3) file name in UTF16 (24 bytes) + public string FileName = String.Empty; + + public FileBothDirectoryInformation() + { + } + + public FileBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset) + { + CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8)); + LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16)); + LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24)); + ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32)); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60); + EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64); + ShortNameLength = ByteReader.ReadByte(buffer, offset + 68); + Reserved = ByteReader.ReadByte(buffer, offset + 69); + ShortName = ByteReader.ReadUTF16String(buffer, offset + 70, ShortNameLength / 2); + FileName = ByteReader.ReadUTF16String(buffer, offset + 94, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + ShortNameLength = (byte)(ShortName.Length * 2); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc()); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength); + LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize); + ByteWriter.WriteByte(buffer, offset + 68, ShortNameLength); + ByteWriter.WriteByte(buffer, offset + 69, Reserved); + ByteWriter.WriteUTF16String(buffer, offset + 70, ShortName); + ByteWriter.WriteUTF16String(buffer, offset + 94, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileBothDirectoryInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileDirectoryInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileDirectoryInformation.cs new file mode 100644 index 0000000..ce30f90 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileDirectoryInformation.cs @@ -0,0 +1,78 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.10 - FileDirectoryInformation + /// + public class FileDirectoryInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 64; + + public DateTime CreationTime; + public DateTime LastAccessTime; + public DateTime LastWriteTime; + public DateTime ChangeTime; + public ulong EndOfFile; + public ulong AllocationSize; + public FileAttributes FileAttributes; + private uint FileNameLength; + public string FileName = String.Empty; + + public FileDirectoryInformation() + { + } + + public FileDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset) + { + CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8)); + LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16)); + LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24)); + ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32)); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60); + FileName = ByteReader.ReadUTF16String(buffer, offset + 64, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc()); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength); + ByteWriter.WriteUTF16String(buffer, offset + 64, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileDirectoryInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileFullDirectoryInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileFullDirectoryInformation.cs new file mode 100644 index 0000000..c562346 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileFullDirectoryInformation.cs @@ -0,0 +1,81 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.14 - FileFullDirectoryInformation + /// + public class FileFullDirectoryInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 68; + + public DateTime CreationTime; + public DateTime LastAccessTime; + public DateTime LastWriteTime; + public DateTime ChangeTime; + public ulong EndOfFile; + public ulong AllocationSize; + public FileAttributes FileAttributes; + private uint FileNameLength; + public uint EaSize; + public string FileName = String.Empty; + + public FileFullDirectoryInformation() + { + } + + public FileFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset) + { + CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8)); + LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16)); + LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24)); + ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32)); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60); + EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64); + FileName = ByteReader.ReadUTF16String(buffer, offset + 68, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc()); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength); + LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize); + ByteWriter.WriteUTF16String(buffer, offset + 68, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileFullDirectoryInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdBothDirectoryInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdBothDirectoryInformation.cs new file mode 100644 index 0000000..aaa59c9 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdBothDirectoryInformation.cs @@ -0,0 +1,97 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.17 - FileIdBothDirectoryInformation + /// + public class FileIdBothDirectoryInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 104; + + public DateTime CreationTime; + public DateTime LastAccessTime; + public DateTime LastWriteTime; + public DateTime ChangeTime; + public ulong EndOfFile; + public ulong AllocationSize; + public FileAttributes FileAttributes; + private uint FileNameLength; + public uint EaSize; + private byte ShortNameLength; + public byte Reserved1; + public string ShortName = String.Empty; // Short (8.3) file name in UTF16 (24 bytes) + public ushort Reserved2; + public ulong FileId; + public string FileName = String.Empty; + + public FileIdBothDirectoryInformation() + { + } + + public FileIdBothDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset) + { + CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8)); + LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16)); + LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24)); + ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32)); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60); + EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64); + ShortNameLength = ByteReader.ReadByte(buffer, offset + 68); + Reserved1 = ByteReader.ReadByte(buffer, offset + 69); + ShortName = ByteReader.ReadUTF16String(buffer, offset + 70, ShortNameLength / 2); + Reserved2 = LittleEndianConverter.ToUInt16(buffer, offset + 94); + FileId = LittleEndianConverter.ToUInt64(buffer, offset + 96); + FileName = ByteReader.ReadUTF16String(buffer, offset + 104, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + ShortNameLength = (byte)(ShortName.Length * 2); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc()); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength); + LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize); + ByteWriter.WriteByte(buffer, offset + 68, ShortNameLength); + ByteWriter.WriteByte(buffer, offset + 69, Reserved1); + ByteWriter.WriteUTF16String(buffer, offset + 70, ShortName); + LittleEndianWriter.WriteUInt16(buffer, offset + 94, Reserved2); + LittleEndianWriter.WriteUInt64(buffer, offset + 96, FileId); + ByteWriter.WriteUTF16String(buffer, offset + 104, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileIdBothDirectoryInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdFullDirectoryInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdFullDirectoryInformation.cs new file mode 100644 index 0000000..0cccf0d --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileIdFullDirectoryInformation.cs @@ -0,0 +1,87 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.18 - FileIdFullDirectoryInformation + /// + public class FileIdFullDirectoryInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 80; + + public DateTime CreationTime; + public DateTime LastAccessTime; + public DateTime LastWriteTime; + public DateTime ChangeTime; + public ulong EndOfFile; + public ulong AllocationSize; + public FileAttributes FileAttributes; + private uint FileNameLength; + public uint EaSize; + public uint Reserved; + public ulong FileId; + public string FileName = String.Empty; + + public FileIdFullDirectoryInformation() + { + } + + public FileIdFullDirectoryInformation(byte[] buffer, int offset) : base(buffer, offset) + { + CreationTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 8)); + LastAccessTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 16)); + LastWriteTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 24)); + ChangeTime = DateTime.FromFileTimeUtc(LittleEndianConverter.ToInt64(buffer, offset + 32)); + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset + 40); + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset + 48); + FileAttributes = (FileAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 56); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 60); + EaSize = LittleEndianConverter.ToUInt32(buffer, offset + 64); + Reserved = LittleEndianConverter.ToUInt32(buffer, offset + 68); + FileId = LittleEndianConverter.ToUInt64(buffer, offset + 72); + FileName = ByteReader.ReadUTF16String(buffer, offset + 80, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CreationTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 16, LastAccessTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 24, LastWriteTime.ToFileTimeUtc()); + LittleEndianWriter.WriteInt64(buffer, offset + 32, ChangeTime.ToFileTimeUtc()); + LittleEndianWriter.WriteUInt64(buffer, offset + 40, EndOfFile); + LittleEndianWriter.WriteUInt64(buffer, offset + 48, AllocationSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 56, (uint)FileAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 60, FileNameLength); + LittleEndianWriter.WriteUInt32(buffer, offset + 64, EaSize); + LittleEndianWriter.WriteUInt32(buffer, offset + 68, Reserved); + LittleEndianWriter.WriteUInt64(buffer, offset + 72, FileId); + ByteWriter.WriteUTF16String(buffer, offset + 80, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileIdFullDirectoryInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/FileNamesInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileNamesInformation.cs new file mode 100644 index 0000000..445cc7c --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/FileNamesInformation.cs @@ -0,0 +1,57 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.4.26 - FileNamesInformation + /// + public class FileNamesInformation : QueryDirectoryFileInformation + { + public const int FixedLength = 12; + + private uint FileNameLength; + public string FileName = String.Empty; + + public FileNamesInformation() + { + } + + public FileNamesInformation(byte[] buffer, int offset) : base(buffer, offset) + { + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 8); + FileName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + base.WriteBytes(buffer, offset); + FileNameLength = (uint)(FileName.Length * 2); + LittleEndianWriter.WriteUInt32(buffer, offset + 8, FileNameLength); + ByteWriter.WriteUTF16String(buffer, offset + 12, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileNamesInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/QueryDirectory/QueryDirectoryFileInformation.cs b/SMBLibrary/Structures/FileInformation/QueryDirectory/QueryDirectoryFileInformation.cs new file mode 100644 index 0000000..94c47cd --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/QueryDirectory/QueryDirectoryFileInformation.cs @@ -0,0 +1,115 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + public abstract class QueryDirectoryFileInformation : FileInformation + { + public uint NextEntryOffset; + public uint FileIndex; + + public QueryDirectoryFileInformation() + { + } + + public QueryDirectoryFileInformation(byte[] buffer, int offset) + { + NextEntryOffset = LittleEndianConverter.ToUInt32(buffer, offset + 0); + FileIndex = LittleEndianConverter.ToUInt32(buffer, offset + 4); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, offset + 0, NextEntryOffset); + LittleEndianWriter.WriteUInt32(buffer, offset + 4, FileIndex); + } + + public static QueryDirectoryFileInformation ReadFileInformation(byte[] buffer, int offset, FileInformationClass fileInformationClass) + { + switch (fileInformationClass) + { + case FileInformationClass.FileDirectoryInformation: + return new FileDirectoryInformation(buffer, offset); + case FileInformationClass.FileFullDirectoryInformation: + return new FileFullDirectoryInformation(buffer, offset); + case FileInformationClass.FileBothDirectoryInformation: + return new FileBothDirectoryInformation(buffer, offset); + case FileInformationClass.FileNamesInformation: + return new FileNamesInformation(buffer, offset); + case FileInformationClass.FileIdBothDirectoryInformation: + return new FileIdBothDirectoryInformation(buffer, offset); + case FileInformationClass.FileIdFullDirectoryInformation: + return new FileIdFullDirectoryInformation(buffer, offset); + default: + throw new NotImplementedException(String.Format("File information class {0} is not supported.", (int)fileInformationClass)); + } + } + + public static List ReadFileInformationList(byte[] buffer, int offset, FileInformationClass fileInformationClass) + { + List result = new List(); + QueryDirectoryFileInformation entry; + do + { + entry = ReadFileInformation(buffer, offset, fileInformationClass); + result.Add(entry); + offset += (int)entry.NextEntryOffset; + } + while (entry.NextEntryOffset != 0); + return result; + } + + public static byte[] GetBytes(List fileInformationList) + { + int listLength = GetListLength(fileInformationList); + byte[] buffer = new byte[listLength]; + int offset = 0; + for (int index = 0; index < fileInformationList.Count; index++) + { + QueryDirectoryFileInformation entry = fileInformationList[index]; + int length = entry.Length; + int paddedLength = (int)Math.Ceiling((double)length / 8) * 8; + if (index < fileInformationList.Count - 1) + { + entry.NextEntryOffset = (uint)paddedLength; + } + else + { + entry.NextEntryOffset = 0; + } + entry.WriteBytes(buffer, offset); + offset += paddedLength; + } + return buffer; + } + + public static int GetListLength(List fileInformationList) + { + int result = 0; + for(int index = 0; index < fileInformationList.Count; index++) + { + QueryDirectoryFileInformation entry = fileInformationList[index]; + int length = entry.Length; + // [MS-FSCC] each [entry] MUST be aligned on an 8-byte boundary. + if (index < fileInformationList.Count - 1) + { + // No padding is required following the last data element. + int paddedLength = (int)Math.Ceiling((double)length / 8) * 8; + result += paddedLength; + } + else + { + result += length; + } + } + return result; + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileAllocationInformation.cs b/SMBLibrary/Structures/FileInformation/Set/FileAllocationInformation.cs new file mode 100644 index 0000000..1fd6113 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileAllocationInformation.cs @@ -0,0 +1,53 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.4 - FileAllocationInformation + /// + public class FileAllocationInformation : FileInformation + { + public const int FixedLength = 8; + + public ulong AllocationSize; + + public FileAllocationInformation() + { + } + + public FileAllocationInformation(byte[] buffer, int offset) + { + AllocationSize = LittleEndianConverter.ToUInt64(buffer, offset); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt64(buffer, offset, AllocationSize); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileAllocationInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileDispositionInformation.cs b/SMBLibrary/Structures/FileInformation/Set/FileDispositionInformation.cs new file mode 100644 index 0000000..6cf7ca6 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileDispositionInformation.cs @@ -0,0 +1,53 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.11 - FileDispositionInformation + /// + public class FileDispositionInformation : FileInformation + { + public const int FixedLength = 1; + + public bool DeletePending; + + public FileDispositionInformation() + { + } + + public FileDispositionInformation(byte[] buffer, int offset) + { + DeletePending = Convert.ToBoolean(ByteReader.ReadByte(buffer, offset + 0)); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(DeletePending)); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileDispositionInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileEndOfFileInformation.cs b/SMBLibrary/Structures/FileInformation/Set/FileEndOfFileInformation.cs new file mode 100644 index 0000000..890a87d --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileEndOfFileInformation.cs @@ -0,0 +1,53 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.13 - FileEndOfFileInformation + /// + public class FileEndOfFileInformation : FileInformation + { + public const int FixedLength = 8; + + public ulong EndOfFile; + + public FileEndOfFileInformation() + { + } + + public FileEndOfFileInformation(byte[] buffer, int offset) + { + EndOfFile = LittleEndianConverter.ToUInt64(buffer, offset); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt64(buffer, offset, EndOfFile); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileEndOfFileInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileFullEAInformation.cs b/SMBLibrary/Structures/FileInformation/Set/FileFullEAInformation.cs index 655f049..2bc4cf4 100644 --- a/SMBLibrary/Structures/FileInformation/Set/FileFullEAInformation.cs +++ b/SMBLibrary/Structures/FileInformation/Set/FileFullEAInformation.cs @@ -12,9 +12,9 @@ using Utilities; namespace SMBLibrary { /// - /// [MS-FSCC] 2.4.15 - FILE_FULL_EA_INFORMATION + /// [MS-FSCC] 2.4.15 - FileFullEaInformation /// - public class FileFullEAInformation + public class FileFullEAInformation : FileInformation { public const int FixedLength = 8; @@ -39,7 +39,7 @@ namespace SMBLibrary EaValue = ByteReader.ReadAnsiString(buffer, ref offset, EaValueLength); } - public void WriteBytes(byte[] buffer, int offset) + public override void WriteBytes(byte[] buffer, int offset) { EaNameLength = (byte)EaName.Length; EaValueLength = (ushort)EaValue.Length; @@ -51,7 +51,15 @@ namespace SMBLibrary ByteWriter.WriteAnsiString(buffer, ref offset, EaValue); } - public int Length + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileFullEaInformation; + } + } + + public override int Length { get { diff --git a/SMBLibrary/Structures/FileInformation/Set/FileLinkInformationType2.cs b/SMBLibrary/Structures/FileInformation/Set/FileLinkInformationType2.cs new file mode 100644 index 0000000..d1224db --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileLinkInformationType2.cs @@ -0,0 +1,64 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.21.2 - FileLinkInformation Type 2 + /// + public class FileLinkInformationType2 : FileInformation + { + public const int FixedLength = 20; + + public bool ReplaceIfExists; + // 7 reserved bytes + public ulong RootDirectory; + private uint FileNameLength; + public string FileName = String.Empty; + + public FileLinkInformationType2() + { + } + + public FileLinkInformationType2(byte[] buffer, int offset) + { + ReplaceIfExists = Conversion.ToBoolean(ByteReader.ReadByte(buffer, offset + 0)); + RootDirectory = LittleEndianConverter.ToUInt64(buffer, offset + 8); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 16); + FileName = ByteReader.ReadUTF16String(buffer, offset + 20, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + FileNameLength = (uint)(FileName.Length * 2); + ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(ReplaceIfExists)); + LittleEndianWriter.WriteUInt64(buffer, offset + 8, RootDirectory); + LittleEndianWriter.WriteUInt32(buffer, offset + 16, FileNameLength); + ByteWriter.WriteUTF16String(buffer, offset + 20, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileLinkInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileRenameInformationType2.cs b/SMBLibrary/Structures/FileInformation/Set/FileRenameInformationType2.cs new file mode 100644 index 0000000..88d270d --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileRenameInformationType2.cs @@ -0,0 +1,64 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.34.2 - FileRenameInformation Type 2 + /// + public class FileRenameInformationType2 : FileInformation + { + public const int FixedLength = 20; + + public bool ReplaceIfExists; + // 7 reserved bytes + public ulong RootDirectory; + private uint FileNameLength; + public string FileName = String.Empty; + + public FileRenameInformationType2() + { + } + + public FileRenameInformationType2(byte[] buffer, int offset) + { + ReplaceIfExists = Conversion.ToBoolean(ByteReader.ReadByte(buffer, offset + 0)); + RootDirectory = LittleEndianConverter.ToUInt64(buffer, offset + 8); + FileNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 16); + FileName = ByteReader.ReadUTF16String(buffer, offset + 20, (int)FileNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + FileNameLength = (uint)(FileName.Length * 2); + ByteWriter.WriteByte(buffer, offset + 0, Convert.ToByte(ReplaceIfExists)); + LittleEndianWriter.WriteUInt64(buffer, offset + 8, RootDirectory); + LittleEndianWriter.WriteUInt32(buffer, offset + 16, FileNameLength); + ByteWriter.WriteUTF16String(buffer, offset + 20, FileName); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileRenameInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileInformation/Set/FileValidDataLengthInformation.cs b/SMBLibrary/Structures/FileInformation/Set/FileValidDataLengthInformation.cs new file mode 100644 index 0000000..be52543 --- /dev/null +++ b/SMBLibrary/Structures/FileInformation/Set/FileValidDataLengthInformation.cs @@ -0,0 +1,53 @@ +/* Copyright (C) 2014-2017 Tal Aloni . 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 System.Text; +using Utilities; + +namespace SMBLibrary +{ + /// + /// [MS-FSCC] 2.4.41 - FileValidDataLengthInformation + /// + public class FileValidDataLengthInformation : FileInformation + { + public const int FixedLength = 8; + + public long ValidDataLength; + + public FileValidDataLengthInformation() + { + } + + public FileValidDataLengthInformation(byte[] buffer, int offset) + { + ValidDataLength = LittleEndianConverter.ToInt64(buffer, offset); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteInt64(buffer, offset, ValidDataLength); + } + + public override FileInformationClass FileInformationClass + { + get + { + return FileInformationClass.FileValidDataLengthInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsAttributeInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsAttributeInformation.cs new file mode 100644 index 0000000..a682b0c --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsAttributeInformation.cs @@ -0,0 +1,66 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.1 - FileFsAttributeInformation + /// + public class FileFsAttributeInformation : FileSystemInformation + { + public const int FixedLength = 12; + + public FileSystemAttributes FileSystemAttributes; + /// + /// Maximum file name component length, in bytes, supported by the specified file system. + /// The value of this field MUST be greater than zero and MUST be no more than 510. + /// + public uint MaximumComponentNameLength; + private uint FileSystemNameLength; + public string FileSystemName = String.Empty; + + public FileFsAttributeInformation() + { + } + + public FileFsAttributeInformation(byte[] buffer, int offset) + { + FileSystemAttributes = (FileSystemAttributes)LittleEndianConverter.ToUInt32(buffer, offset + 0); + MaximumComponentNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 4); + FileSystemNameLength = LittleEndianConverter.ToUInt32(buffer, offset + 8); + FileSystemName = ByteReader.ReadUTF16String(buffer, offset + 12, (int)FileSystemNameLength / 2); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + FileSystemNameLength = (uint)(FileSystemName.Length * 2); + LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)FileSystemAttributes); + LittleEndianWriter.WriteUInt32(buffer, offset + 4, MaximumComponentNameLength); + LittleEndianWriter.WriteUInt32(buffer, offset + 8, FileSystemNameLength); + ByteWriter.WriteUTF16String(buffer, offset + 12, FileSystemName); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsAttributeInformation; + } + } + + public override int Length + { + get + { + return FixedLength + FileSystemName.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsControlInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsControlInformation.cs new file mode 100644 index 0000000..42de780 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsControlInformation.cs @@ -0,0 +1,70 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.2 - FileFsControlInformation + /// + public class FileFsControlInformation : FileSystemInformation + { + public const int FixedLength = 48; + + public long FreeSpaceStartFiltering; + public long FreeSpaceThreshold; + public long FreeSpaceStopFiltering; + public ulong DefaultQuotaThreshold; + public ulong DefaultQuotaLimit; + public FileSystemControlFlags FileSystemControlFlags; + public uint Padding; + + public FileFsControlInformation() + { + } + + public FileFsControlInformation(byte[] buffer, int offset) + { + FreeSpaceStartFiltering = LittleEndianConverter.ToInt64(buffer, offset + 0); + FreeSpaceThreshold = LittleEndianConverter.ToInt64(buffer, offset + 8); + FreeSpaceStopFiltering = LittleEndianConverter.ToInt64(buffer, offset + 16); + DefaultQuotaThreshold = LittleEndianConverter.ToUInt64(buffer, offset + 24); + DefaultQuotaLimit = LittleEndianConverter.ToUInt64(buffer, offset + 32); + FileSystemControlFlags = (FileSystemControlFlags)LittleEndianConverter.ToUInt32(buffer, offset + 40); + Padding = LittleEndianConverter.ToUInt32(buffer, offset + 44); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteInt64(buffer, offset + 0, FreeSpaceStartFiltering); + LittleEndianWriter.WriteInt64(buffer, offset + 8, FreeSpaceThreshold); + LittleEndianWriter.WriteInt64(buffer, offset + 16, FreeSpaceStopFiltering); + LittleEndianWriter.WriteUInt64(buffer, offset + 24, DefaultQuotaThreshold); + LittleEndianWriter.WriteUInt64(buffer, offset + 32, DefaultQuotaLimit); + LittleEndianWriter.WriteUInt32(buffer, offset + 40, (uint)FileSystemControlFlags); + LittleEndianWriter.WriteUInt32(buffer, offset + 44, Padding); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsControlInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsDeviceInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsDeviceInformation.cs new file mode 100644 index 0000000..e67c038 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsDeviceInformation.cs @@ -0,0 +1,55 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.10 - FileFsDeviceInformation + /// + public class FileFsDeviceInformation : FileSystemInformation + { + public const int FixedLength = 8; + + public DeviceType DeviceType; + public DeviceCharacteristics Characteristics; + + public FileFsDeviceInformation() + { + } + + public FileFsDeviceInformation(byte[] buffer, int offset) + { + DeviceType = (DeviceType)LittleEndianConverter.ToUInt32(buffer, offset + 0); + Characteristics = (DeviceCharacteristics)LittleEndianConverter.ToUInt32(buffer, offset + 4); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, offset + 0, (uint)DeviceType); + LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)Characteristics); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsDeviceInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsFullSizeInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsFullSizeInformation.cs new file mode 100644 index 0000000..401c085 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsFullSizeInformation.cs @@ -0,0 +1,64 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.4 - FileFsFullSizeInformation + /// + public class FileFsFullSizeInformation : FileSystemInformation + { + public const int FixedLength = 32; + + public long TotalAllocationUnits; + public long CallerAvailableAllocationUnits; + public long ActualAvailableAllocationUnits; + public uint SectorsPerAllocationUnit; + public uint BytesPerSector; + + public FileFsFullSizeInformation() + { + } + + public FileFsFullSizeInformation(byte[] buffer, int offset) + { + TotalAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 0); + CallerAvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 8); + ActualAvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 16); + SectorsPerAllocationUnit = LittleEndianConverter.ToUInt32(buffer, offset + 24); + BytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 28); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteInt64(buffer, offset + 0, TotalAllocationUnits); + LittleEndianWriter.WriteInt64(buffer, offset + 8, CallerAvailableAllocationUnits); + LittleEndianWriter.WriteInt64(buffer, offset + 16, ActualAvailableAllocationUnits); + LittleEndianWriter.WriteUInt32(buffer, offset + 24, SectorsPerAllocationUnit); + LittleEndianWriter.WriteUInt32(buffer, offset + 28, BytesPerSector); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsFullSizeInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsObjectIdInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsObjectIdInformation.cs new file mode 100644 index 0000000..05085ec --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsObjectIdInformation.cs @@ -0,0 +1,56 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.6 - FileFsObjectIdInformation + /// + public class FileFsObjectIdInformation : FileSystemInformation + { + public const int FixedLength = 64; + + public Guid ObjectID; + public byte[] ExtendedInfo; //48 bytes + + public FileFsObjectIdInformation() + { + ExtendedInfo = new byte[48]; + } + + public FileFsObjectIdInformation(byte[] buffer, int offset) + { + LittleEndianConverter.ToGuid(buffer, offset + 0); + ExtendedInfo = ByteReader.ReadBytes(buffer, offset + 16, 48); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteGuidBytes(buffer, offset + 0, ObjectID); + ByteWriter.WriteBytes(buffer, offset + 16, ExtendedInfo); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsObjectIdInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsSectorSizeInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsSectorSizeInformation.cs new file mode 100644 index 0000000..de72860 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsSectorSizeInformation.cs @@ -0,0 +1,70 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.4 - FileFsSectorSizeInformation + /// + public class FileFsSectorSizeInformation : FileSystemInformation + { + public const int FixedLength = 28; + + public uint LogicalBytesPerSector; + public uint PhysicalBytesPerSectorForAtomicity; + public uint PhysicalBytesPerSectorForPerformance; + public uint FileSystemEffectivePhysicalBytesPerSectorForAtomicity; + public SectorSizeInformationFlags Flags; + public uint ByteOffsetForSectorAlignment; + public uint ByteOffsetForPartitionAlignment; + + public FileFsSectorSizeInformation() + { + } + + public FileFsSectorSizeInformation(byte[] buffer, int offset) + { + LogicalBytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 0); + PhysicalBytesPerSectorForAtomicity = LittleEndianConverter.ToUInt32(buffer, offset + 4); + PhysicalBytesPerSectorForPerformance = LittleEndianConverter.ToUInt32(buffer, offset + 8); + FileSystemEffectivePhysicalBytesPerSectorForAtomicity = LittleEndianConverter.ToUInt32(buffer, offset + 12); + Flags = (SectorSizeInformationFlags)LittleEndianConverter.ToUInt32(buffer, offset + 16); + ByteOffsetForSectorAlignment = LittleEndianConverter.ToUInt32(buffer, offset + 20); + ByteOffsetForPartitionAlignment = LittleEndianConverter.ToUInt32(buffer, offset + 24); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteUInt32(buffer, offset + 0, LogicalBytesPerSector); + LittleEndianWriter.WriteUInt32(buffer, offset + 4, PhysicalBytesPerSectorForAtomicity); + LittleEndianWriter.WriteUInt32(buffer, offset + 8, PhysicalBytesPerSectorForPerformance); + LittleEndianWriter.WriteUInt32(buffer, offset + 12, FileSystemEffectivePhysicalBytesPerSectorForAtomicity); + LittleEndianWriter.WriteUInt32(buffer, offset + 16, (uint)Flags); + LittleEndianWriter.WriteUInt32(buffer, offset + 20, ByteOffsetForSectorAlignment); + LittleEndianWriter.WriteUInt32(buffer, offset + 24, ByteOffsetForPartitionAlignment); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsSectorSizeInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsSizeInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsSizeInformation.cs new file mode 100644 index 0000000..f9fab2f --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsSizeInformation.cs @@ -0,0 +1,61 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.8 - FileFsSizeInformation + /// + public class FileFsSizeInformation : FileSystemInformation + { + public const int FixedLength = 24; + + public long TotalAllocationUnits; + public long AvailableAllocationUnits; + public uint SectorsPerAllocationUnit; + public uint BytesPerSector; + + public FileFsSizeInformation() + { + } + + public FileFsSizeInformation(byte[] buffer, int offset) + { + TotalAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 0); + AvailableAllocationUnits = LittleEndianConverter.ToInt64(buffer, offset + 8); + SectorsPerAllocationUnit = LittleEndianConverter.ToUInt32(buffer, offset + 16); + BytesPerSector = LittleEndianConverter.ToUInt32(buffer, offset + 20); + } + + public override void WriteBytes(byte[] buffer, int offset) + { + LittleEndianWriter.WriteInt64(buffer, offset + 0, TotalAllocationUnits); + LittleEndianWriter.WriteInt64(buffer, offset + 8, AvailableAllocationUnits); + LittleEndianWriter.WriteUInt32(buffer, offset + 16, SectorsPerAllocationUnit); + LittleEndianWriter.WriteUInt32(buffer, offset + 20, BytesPerSector); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsSizeInformation; + } + } + + public override int Length + { + get + { + return FixedLength; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileFsVolumeInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileFsVolumeInformation.cs new file mode 100644 index 0000000..eb01c50 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileFsVolumeInformation.cs @@ -0,0 +1,71 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + /// + /// [MS-FSCC] 2.5.9 - FileFsVolumeInformation + /// + public class FileFsVolumeInformation : FileSystemInformation + { + public const int FixedLength = 18; + + public DateTime? VolumeCreationTime; + public uint VolumeSerialNumber; + private uint VolumeLabelLength; + public bool SupportsObjects; + public byte Reserved; + public string VolumeLabel = String.Empty; + + public FileFsVolumeInformation() + { + } + + public FileFsVolumeInformation(byte[] buffer, int offset) + { + VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0); + VolumeSerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8); + VolumeLabelLength = LittleEndianConverter.ToUInt32(buffer, offset + 12); + SupportsObjects = Convert.ToBoolean(ByteReader.ReadByte(buffer, offset + 16)); + Reserved = ByteReader.ReadByte(buffer, offset + 17); + if (VolumeLabelLength > 0) + { + VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)VolumeLabelLength / 2); + } + } + + public override void WriteBytes(byte[] buffer, int offset) + { + VolumeLabelLength = (uint)(VolumeLabel.Length * 2); + FileTimeHelper.WriteFileTime(buffer, offset + 0, VolumeCreationTime); + LittleEndianWriter.WriteUInt32(buffer, offset + 8, VolumeSerialNumber); + LittleEndianWriter.WriteUInt32(buffer, offset + 12, VolumeLabelLength); + ByteWriter.WriteByte(buffer, offset + 16, Convert.ToByte(SupportsObjects)); + ByteWriter.WriteByte(buffer, offset + 17, Reserved); + ByteWriter.WriteUTF16String(buffer, offset + 18, VolumeLabel); + } + + public override FileSystemInformationClass FileSystemInformationClass + { + get + { + return FileSystemInformationClass.FileFsVolumeInformation; + } + } + + public override int Length + { + get + { + return FixedLength + VolumeLabel.Length * 2; + } + } + } +} diff --git a/SMBLibrary/Structures/FileSystemInformation/FileSystemInformation.cs b/SMBLibrary/Structures/FileSystemInformation/FileSystemInformation.cs new file mode 100644 index 0000000..09a69f6 --- /dev/null +++ b/SMBLibrary/Structures/FileSystemInformation/FileSystemInformation.cs @@ -0,0 +1,34 @@ +/* Copyright (C) 2017 Tal Aloni . 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 +{ + public abstract class FileSystemInformation + { + public abstract void WriteBytes(byte[] buffer, int offset); + + public byte[] GetBytes() + { + byte[] buffer = new byte[this.Length]; + WriteBytes(buffer, 0); + return buffer; + } + + public abstract FileSystemInformationClass FileSystemInformationClass + { + get; + } + + public abstract int Length + { + get; + } + } +}