diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileBothDirectoryInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileBothDirectoryInfo.cs index 9272f10..9cce17b 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileBothDirectoryInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileBothDirectoryInfo.cs @@ -98,5 +98,13 @@ namespace SMBLibrary.SMB1 } return length; } + + public override FindInformationLevel InformationLevel + { + get + { + return FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileDirectoryInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileDirectoryInfo.cs index b8232d3..6038092 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileDirectoryInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileDirectoryInfo.cs @@ -80,5 +80,13 @@ namespace SMBLibrary.SMB1 } return length; } + + public override FindInformationLevel InformationLevel + { + get + { + return FindInformationLevel.SMB_FIND_FILE_DIRECTORY_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileFullDirectoryInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileFullDirectoryInfo.cs index 625d931..6105925 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileFullDirectoryInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileFullDirectoryInfo.cs @@ -83,5 +83,13 @@ namespace SMBLibrary.SMB1 } return length; } + + public override FindInformationLevel InformationLevel + { + get + { + return FindInformationLevel.SMB_FIND_FILE_FULL_DIRECTORY_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileNamesInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileNamesInfo.cs index 8e1ec0d..37cba04 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileNamesInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindFileNamesInfo.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Tal Aloni . All rights reserved. +/* 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, @@ -59,5 +59,13 @@ namespace SMBLibrary.SMB1 } return length; } + + public override FindInformationLevel InformationLevel + { + get + { + return FindInformationLevel.SMB_FIND_FILE_NAMES_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindInformation.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindInformation.cs index 50ebcf1..82e0eee 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindInformation.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/FindInformation/FindInformation.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Tal Aloni . All rights reserved. +/* 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, @@ -31,6 +31,11 @@ namespace SMBLibrary.SMB1 } } + public abstract FindInformationLevel InformationLevel + { + get; + } + public static FindInformation ReadEntry(byte[] buffer, ref int offset, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) { switch (informationLevel) @@ -44,7 +49,7 @@ namespace SMBLibrary.SMB1 case FindInformationLevel.SMB_FIND_FILE_BOTH_DIRECTORY_INFO: return new FindFileBothDirectoryInfo(buffer, ref offset, isUnicode); default: - throw new InvalidRequestException();; + throw new UnsupportedInformationLevelException();; } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSAttibuteInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSAttibuteInfo.cs index ee68d39..147d9b3 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSAttibuteInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSAttibuteInfo.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Tal Aloni . All rights reserved. +/* 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, @@ -46,12 +46,20 @@ namespace SMBLibrary.SMB1 return buffer; } - public int Length + public override int Length { get { return FixedLength + FileSystemName.Length * 2; } } + + public override QueryFSInformationLevel InformationLevel + { + get + { + return QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSDeviceInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSDeviceInfo.cs index fb767d8..4cb4ce2 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSDeviceInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSDeviceInfo.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Tal Aloni . All rights reserved. +/* 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, @@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1 /// public class QueryFSDeviceInfo : QueryFSInformation { - public const int Length = 8; + public const int FixedLength = 8; public DeviceType DeviceType; public DeviceCharacteristics DeviceCharacteristics; @@ -38,5 +38,21 @@ namespace SMBLibrary.SMB1 LittleEndianWriter.WriteUInt32(buffer, 4, (uint)DeviceCharacteristics); return buffer; } + + public override int Length + { + get + { + return FixedLength; + } + } + + public override QueryFSInformationLevel InformationLevel + { + get + { + return QueryFSInformationLevel.SMB_QUERY_FS_DEVICE_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSInformation.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSInformation.cs index fab7d4c..47b6d6d 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSInformation.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSInformation.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Tal Aloni . All rights reserved. +/* 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, @@ -15,6 +15,16 @@ namespace SMBLibrary.SMB1 { public abstract byte[] GetBytes(bool isUnicode); + public abstract int Length + { + get; + } + + public abstract QueryFSInformationLevel InformationLevel + { + get; + } + public static QueryFSInformation GetQueryFSInformation(byte[] buffer, QueryFSInformationLevel informationLevel, bool isUnicode) { switch (informationLevel) @@ -28,7 +38,7 @@ namespace SMBLibrary.SMB1 case QueryFSInformationLevel.SMB_QUERY_FS_ATTRIBUTE_INFO: return new QueryFSAttibuteInfo(buffer, 0); default: - throw new InvalidRequestException(); + throw new UnsupportedInformationLevelException(); } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSSizeInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSSizeInfo.cs index 7f756bb..4a8a010 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSSizeInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSSizeInfo.cs @@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1 /// public class QueryFSSizeInfo : QueryFSInformation { - public const int Length = 24; + public const int FixedLength = 24; public long TotalAllocationUnits; public long TotalFreeAllocationUnits; @@ -44,5 +44,21 @@ namespace SMBLibrary.SMB1 LittleEndianWriter.WriteUInt32(buffer, 20, BytesPerSector); return buffer; } + + public override int Length + { + get + { + return FixedLength; + } + } + + public override QueryFSInformationLevel InformationLevel + { + get + { + return QueryFSInformationLevel.SMB_QUERY_FS_SIZE_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSVolumeInfo.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSVolumeInfo.cs index 3321aa1..c833da1 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSVolumeInfo.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryFSInformation/QueryFSVolumeInfo.cs @@ -20,7 +20,7 @@ namespace SMBLibrary.SMB1 public DateTime? VolumeCreationTime; public uint SerialNumber; - //uint VolumeLabelSize; + private uint VolumeLabelSize; public ushort Reserved; public string VolumeLabel; // Unicode @@ -33,22 +33,38 @@ namespace SMBLibrary.SMB1 { VolumeCreationTime = FileTimeHelper.ReadNullableFileTime(buffer, offset + 0); SerialNumber = LittleEndianConverter.ToUInt32(buffer, offset + 8); - uint volumeLabelSize = LittleEndianConverter.ToUInt32(buffer, offset + 12); + VolumeLabelSize = LittleEndianConverter.ToUInt32(buffer, offset + 12); Reserved = LittleEndianConverter.ToUInt16(buffer, offset + 16); - VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)volumeLabelSize); + VolumeLabel = ByteReader.ReadUTF16String(buffer, offset + 18, (int)VolumeLabelSize); } public override byte[] GetBytes(bool isUnicode) { - uint volumeLabelSize = (uint)(VolumeLabel.Length * 2); + VolumeLabelSize = (uint)(VolumeLabel.Length * 2); - byte[] buffer = new byte[FixedLength + volumeLabelSize]; + byte[] buffer = new byte[this.Length]; FileTimeHelper.WriteFileTime(buffer, 0, VolumeCreationTime); LittleEndianWriter.WriteUInt32(buffer, 8, SerialNumber); - LittleEndianWriter.WriteUInt32(buffer, 12, volumeLabelSize); + LittleEndianWriter.WriteUInt32(buffer, 12, VolumeLabelSize); LittleEndianWriter.WriteUInt16(buffer, 16, Reserved); ByteWriter.WriteUTF16String(buffer, 18, VolumeLabel); return buffer; } + + public override int Length + { + get + { + return FixedLength + VolumeLabel.Length * 2; + } + } + + public override QueryFSInformationLevel InformationLevel + { + get + { + return QueryFSInformationLevel.SMB_QUERY_FS_VOLUME_INFO; + } + } } } diff --git a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryInformation/QueryInformation.cs b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryInformation/QueryInformation.cs index 42de3ed..5e1ad20 100644 --- a/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryInformation/QueryInformation.cs +++ b/SMBLibrary/SMB1/Transaction2Subcommands/Structures/QueryInformation/QueryInformation.cs @@ -41,7 +41,7 @@ namespace SMBLibrary.SMB1 case QueryInformationLevel.SMB_QUERY_FILE_COMPRESSION_INFO: return new QueryFileCompressionInfo(buffer, 0); default: - throw new InvalidRequestException(); + throw new UnsupportedInformationLevelException(); } } }